Transformation Operations

Translation

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

# create vertex and vector

p1 = geompy.MakeVertex(10, 40, 0)

p2 = geompy.MakeVertex( 0,  0, 50)

p3 = geompy.MakeVertex(50, 80, 0)

v = geompy.MakeVector(p1, p2)

vt = geompy.MakeVector(p1, p3)

 

# create cylinder

height = 35

radius1 = 20

cylinder = geompy.MakeCylinder(p1, v, radius1, height)

 

# translate the given object along the vector, specified by its end points

# (all three functions produce the same result)

translation1 = geompy.MakeTranslationTwoPoints(cylinder, p1, p3)

translation2 = geompy.MakeTranslation(cylinder, 40, 40, 0)

translation3 = geompy.MakeTranslationVector(cylinder, vt)

 

# add objects in study

id_cylinder = geompy.addToStudy(cylinder, "Cylinder")

id_translation1 = geompy.addToStudy(translation1, "Translation1")

id_translation2 = geompy.addToStudy(translation2, "Translation2")

id_translation3 = geompy.addToStudy(translation3, "Translation3")

 

# display results

gg.createAndDisplayGO(id_cylinder)

gg.setDisplayMode(id_cylinder,1)

gg.createAndDisplayGO(id_translation1)

gg.setDisplayMode(id_translation1,1)

gg.createAndDisplayGO(id_translation2)

gg.setDisplayMode(id_translation2,1)

gg.createAndDisplayGO(id_translation3)

gg.setDisplayMode(id_translation3,1)

Rotation

import geompy

import salome

import math

gg = salome.ImportComponentGUI("GEOM")

 

# create vertex and vector

p1 = geompy.MakeVertex(10, 40, 0)

p2 = geompy.MakeVertex( 0,  0, 50)

p3 = geompy.MakeVertex(10, 50,-20)

p4 = geompy.MakeVertex(10, 50, 60)

v = geompy.MakeVector(p1, p2)

vr = geompy.MakeVector(p3, p4)

 

# create cylinder

height = 35

radius1 = 20

cylinder = geompy.MakeCylinder(p1, v, radius1, height)

 

# rotate the given object around the given axis on the given angle

rotation = geompy.MakeRotation(cylinder, vr, math.pi)

 

# add objects in study

id_vr = geompy.addToStudy(vr, "Rotation axis")

id_cylinder = geompy.addToStudy(cylinder, "Cylinder")

id_rotation = geompy.addToStudy(rotation, "Rotation")

 

# display results

gg.createAndDisplayGO(id_vr)

gg.createAndDisplayGO(id_cylinder)

gg.setDisplayMode(id_cylinder,1)

gg.createAndDisplayGO(id_rotation)

gg.setDisplayMode(id_rotation,1)

 

Modify Location

import geompy

import salome

import math

gg = salome.ImportComponentGUI("GEOM")

 

# create vertex and vector

p1 = geompy.MakeVertex(10, 40, 0)

p2 = geompy.MakeVertex( 0,  0, 50)

v = geompy.MakeVector(p1, p2)

 

# create cylinder

height = 35

radius1 = 20

cylinder = geompy.MakeCylinder(p1, v, radius1, height)

 

# create local coordinate systems

cs1 = geompy.MakeMarker( 0, 0, 0, 1,0,0, 0,1,0)

cs2 = geompy.MakeMarker(30,40,40, 1,0,0, 0,1,0)

 

# modify the location of the given object

position = geompy.MakePosition(cylinder, cs1, cs2)

 

# add objects in study

id_cs1 = geompy.addToStudy(cs1, "Coordinate system 1")

id_cs2 = geompy.addToStudy(cs2, "Coordinate system 2")

id_cylinder = geompy.addToStudy(cylinder, "Cylinder")

id_position = geompy.addToStudy(position, "Position")

 

# display results

gg.createAndDisplayGO(id_cylinder)

gg.setDisplayMode(id_cylinder,1)

gg.createAndDisplayGO(id_position)

gg.setDisplayMode(id_position,1)

 

Mirror Image

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

# create box

box = geompy.MakeBoxDXDYDZ(200, 200, 200)

 

# create an object, symmetrical to the given one relatively the given plane

p1 = geompy.MakeVertex( 0, 25,  0)

p2 = geompy.MakeVertex( 5, 25,  0)

p3 = geompy.MakeVertex( 0,-30, 40)

plane = geompy.MakePlaneThreePnt(p1, p2, p3, 1000.)

mirror1 = geompy.MakeMirrorByPlane(box, plane)

 

# create an object, symmetrical to the given one relatively the given axis

p4 = geompy.MakeVertex( 210, 210, -20)

p5 = geompy.MakeVertex( 210, 210, 220)

axis = geompy.MakeVector(p4, p5)

mirror2 = geompy.MakeMirrorByAxis(box, axis)

 

# create an object, symmetrical to the given one relatively the given point

mirror3 = geompy.MakeMirrorByPoint(box, p4)

 

# add objects in study

id_box = geompy.addToStudy(box, "Box")

id_plane = geompy.addToStudy(plane, "Plane")

id_mirror1 = geompy.addToStudy(mirror1, "Mirror plane")

id_axis = geompy.addToStudy(axis, "Axis")

id_mirror2 = geompy.addToStudy(mirror2, "Mirror axis")

id_p4 = geompy.addToStudy(p4, "Point")

id_mirror3 = geompy.addToStudy(mirror3, "Mirror point")

 

# display results

gg.createAndDisplayGO(id_box)

gg.setDisplayMode(id_box,1)

gg.createAndDisplayGO(id_plane)

gg.createAndDisplayGO(id_mirror1)

gg.setDisplayMode(id_mirror1,1)

gg.createAndDisplayGO(id_axis)

gg.createAndDisplayGO(id_mirror2)

gg.setDisplayMode(id_mirror2,1)

gg.createAndDisplayGO(id_p4)

gg.createAndDisplayGO(id_mirror3)

gg.setDisplayMode(id_mirror3,1)

 

Scale Transform

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

# create box and sphere

box = geompy.MakeBoxDXDYDZ(200, 200, 200)

 

# scale the given object by the factor

p0 = geompy.MakeVertex(100, 100, 100)

factor = 0.5

scale = geompy.MakeScaleTransform(box, p0, factor)

 

# add objects in study

id_box = geompy.addToStudy(box, "Box")

id_scale = geompy.addToStudy(scale, "Scale")

 

# display results

gg.createAndDisplayGO(id_box)

gg.setDisplayMode(id_box,1)

gg.createAndDisplayGO(id_scale)

gg.setDisplayMode(id_scale,1)

 

Offset Surface

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

# create box and sphere

box = geompy.MakeBox(20, 20, 20, 200, 200, 200)

 

# create new object as offset of the given one

offset = geompy.MakeOffset(box, 70.)

 

# add objects in study

id_box = geompy.addToStudy(box, "Box")

id_offset = geompy.addToStudy(offset, "Offset")

 

# display results

gg.createAndDisplayGO(id_box)

gg.setDisplayMode(id_box,1)

gg.createAndDisplayGO(id_offset)

 

Multi Translation

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

# create vertices and vectors

p0  = geompy.MakeVertex( 0.,  0.,  0.)

px  = geompy.MakeVertex(20.,  0.,  0.)

py  = geompy.MakeVertex( 0., 20.,  0.)

pz  = geompy.MakeVertex( 0.,  0., 20.)

pxy = geompy.MakeVertex( 50., 0., 0.)

pxyz = geompy.MakeVertex( 50., 50., 50.)

vz  = geompy.MakeVector(p0, pz)

vxy = geompy.MakeVector(px, py)

vtr1d = geompy.MakeVector(p0, pxyz)

vtr2d = geompy.MakeVector(p0, pxy)

  

# create arc

arc = geompy.MakeArc(py, pz, px)

 

# create wire

wire = geompy.MakeWire([vxy, arc])

 

# create planar face

face = geompy.MakeFace(wire, 1)

 

# create prism

prism = geompy.MakePrismVecH(face, vz, 20.0)

 

# translate the given object along the given vector a given number times

tr1d = geompy.MakeMultiTranslation1D(prism, vtr1d, 20, 4)

 

# consequently apply two specified translations to the object specified number of times

tr2d = geompy.MakeMultiTranslation2D(prism, vtr1d, 20, 4, vtr2d, 80, 3)

 

# add objects in study

id_prism = geompy.addToStudy(prism,"Prism")

id_tr1d = geompy.addToStudy(tr1d,"Translation 1D")

id_tr2d = geompy.addToStudy(tr2d,"Translation 2D")

 

# display prism and results of fillet operation

gg.createAndDisplayGO(id_prism)

gg.setDisplayMode(id_prism,1)

gg.createAndDisplayGO(id_tr1d)

gg.setDisplayMode(id_tr1d,1)

gg.createAndDisplayGO(id_tr2d)

gg.setDisplayMode(id_tr2d,1)

 

Multi Rotation

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

# create vertices and vectors

p0  = geompy.MakeVertex( 0.,  0.,  0.)

px  = geompy.MakeVertex(20.,  0.,  0.)

py  = geompy.MakeVertex( 0., 20.,  0.)

pz  = geompy.MakeVertex( 0.,  0., 20.)

pxyz = geompy.MakeVertex( 50., 50., 10.)

vz  = geompy.MakeVector(p0, pz)

vxy = geompy.MakeVector(px, py)

vrot1d = geompy.MakeVector(p0, pxyz)

  

# create arc

arc = geompy.MakeArc(py, pz, px)

 

# create wire

wire = geompy.MakeWire([vxy, arc])

 

# create planar face

face = geompy.MakeFace(wire, 1)

 

# create prism

prism = geompy.MakePrismVecH(face, vz, 20.0)

 

# rotate the given object around the given axis on the given angle a given number times

rot1d = geompy.MultiRotate1D(prism, vrot1d, 4)

 

# rotate the given object around the given axis on the given angle a given number times

# and multi-translate each rotation result

rot2d = geompy.MultiRotate2D(prism, vrot1d, 60, 4, 50, 5)

 

# add objects in study

id_prism = geompy.addToStudy(prism,"Prism")

id_rot1d = geompy.addToStudy(rot1d,"Rotation 1D")

id_rot2d = geompy.addToStudy(rot2d,"Rotation 2D")

 

# display prism and results of fillet operation

gg.createAndDisplayGO(id_prism)

gg.setDisplayMode(id_prism,1)

gg.createAndDisplayGO(id_rot1d)

gg.setDisplayMode(id_rot1d,1)

gg.createAndDisplayGO(id_rot2d)

gg.setDisplayMode(id_rot2d,1)

 

Fillet

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

radius  = 10.

ShapeTypeEdge = geompy.ShapeType["EDGE"]

 

# create vertices and vectors

p0  = geompy.MakeVertex(  0.,   0.,   0.)

px  = geompy.MakeVertex(100.,   0.,   0.)

py  = geompy.MakeVertex(  0., 100.,   0.)

pz  = geompy.MakeVertex(  0.,   0., 100.)

vz  = geompy.MakeVector(p0, pz)

vxy = geompy.MakeVector(px, py)

  

# create arc

arc = geompy.MakeArc(py, pz, px)

 

# create wire

wire = geompy.MakeWire([vxy, arc])

 

# create planar face

face = geompy.MakeFace(wire, 1)

 

# create prism

prism = geompy.MakePrismVecH(face, vz, 100.0)

 

# get IDList for fillet

prism_edges = geompy.SubShapeAllSorted(prism, ShapeTypeEdge)

IDlist_e = []

IDlist_e.append(geompy.GetSubShapeID(prism, prism_edges[0]))

IDlist_e.append(geompy.GetSubShapeID(prism, prism_edges[1]))

IDlist_e.append(geompy.GetSubShapeID(prism, prism_edges[2]))

 

# make fillet on the specified edges of the given shape

fillet = geompy.MakeFillet(prism, radius, ShapeTypeEdge, IDlist_e)

 

# make fillet on all edges of the given shape

filletall = geompy.MakeFilletAll(prism, radius)

 

# add objects in study

id_prism = geompy.addToStudy(prism,"Prism")

id_fillet = geompy.addToStudy(fillet,"Fillet")

id_filletall = geompy.addToStudy(filletall,"Fillet all")

 

# display prism and results of fillet operation

gg.createAndDisplayGO(id_prism)

gg.setDisplayMode(id_prism,1)

gg.createAndDisplayGO(id_fillet)

gg.setDisplayMode(id_fillet,1)

gg.createAndDisplayGO(id_filletall)

gg.setDisplayMode(id_filletall,1)

 

Chamfer

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

d1 = 10.

d2 = 10.

ShapeTypeFace = geompy.ShapeType["FACE"]

 

# create vertices and vectors

p0  = geompy.MakeVertex(  0.,   0.,   0.)

px  = geompy.MakeVertex(100.,   0.,   0.)

py  = geompy.MakeVertex(  0., 100.,   0.)

pz  = geompy.MakeVertex(  0.,   0., 100.)

vz  = geompy.MakeVector(p0, pz)

vxy = geompy.MakeVector(px, py)

  

# create arc

arc = geompy.MakeArc(py, pz, px)

 

# create wire

wire = geompy.MakeWire([vxy, arc])

 

# create planar face

face = geompy.MakeFace(wire, 1)

 

# create prism

prism = geompy.MakePrismVecH(face, vz, 100.0)

 

# get IDList for chamfer

prism_faces = geompy.SubShapeAllSorted(prism, ShapeTypeFace)

f_ind_1 = geompy.GetSubShapeID(prism, prism_faces[0])

f_ind_2 = geompy.GetSubShapeID(prism, prism_faces[1])

IDlist_f = [f_ind_1, f_ind_2]

 

# perform a chamfer on edges, common to the specified faces

chamfer_e = geompy.MakeChamferEdge(prism, d1, d2, f_ind_1, f_ind_2)

 

# perform a chamfer on all edges of the specified faces

chamfer_f = geompy.MakeChamferFaces(prism, d1, d2, IDlist_f)

chamfer_f1 = geompy.MakeChamfer(prism, d1, d2, ShapeTypeFace, IDlist_f)

 

# perform a symmetric chamfer on all edges of the given shape

chamfer_all = geompy.MakeChamferAll(prism, d1)

 

# add objects in study

id_prism = geompy.addToStudy(prism,"Prism")

id_chamfer_e = geompy.addToStudy(chamfer_e,"Chamfer edge")

id_chamfer_f = geompy.addToStudy(chamfer_f,"Chamfer faces")

id_chamfer_f1 = geompy.addToStudy(chamfer_f1,"Chamfer faces 1")

id_chamfer_all = geompy.addToStudy(chamfer_all,"Chamfer all")

 

# display prism and results of chamfer operation

gg.createAndDisplayGO(id_prism)

gg.setDisplayMode(id_prism,1)

gg.createAndDisplayGO(id_chamfer_e)

gg.setDisplayMode(id_chamfer_e,1)

gg.createAndDisplayGO(id_chamfer_f)

gg.setDisplayMode(id_chamfer_f,1)

gg.createAndDisplayGO(id_chamfer_f1)

gg.setDisplayMode(id_chamfer_f1,1)

gg.createAndDisplayGO(id_chamfer_all)

gg.setDisplayMode(id_chamfer_all,1)