Measurement Tools

Point Coordinates

import math

import geompy

 

# create a point

point = geompy.MakeVertex(15., 23., 80.)

 

# get the coordinates of the point and check its values

coords = geompy.PointCoordinates(point)

 

# check the obtained coordinate values

tolerance = 1.e-07

def IsEqual(val1, val2): return (math.fabs(val1 - val2) < tolerance)

 

if IsEqual(coords[0], 15.) and IsEqual(coords[1], 23.) and IsEqual(coords[2], 80.):

    print "All values are OK."

else :

    print "Coordinates of point must be (15, 23, 80), but returned (",

    print coords[0], ", ", coords[1], ", ", coords[2], ")"

    pass

Basic Properties

import geompy

import math

 

# create a box

box = geompy.MakeBoxDXDYDZ(100,30,100)

props = geompy.BasicProperties(box)

print "\nBox 100x30x100 Basic Properties:"

print " Wires length: ", props[0]

print " Surface area: ", props[1]

print " Volume      : ", props[2]

length = math.sqrt((props[0] - 1840)*(props[0] - 1840))

area = math.sqrt((props[1] - 32000)*(props[1] - 32000))

volume = math.sqrt((props[2] - 300000)*(props[2] - 300000))

if length > 1e-7 or area > 1e-7 or volume > 1e-7:

    print "While must be:"

    print " Wires length: ", 1840

    print " Surface area: ", 32000

    print " Volume      : ", 300000.

Center of masses

import geompy

import math

 

# create a box

box = geompy.MakeBoxDXDYDZ(100,30,100)

cm = geompy.MakeCDG(box)

if cm is None:

    raise RuntimeError, "MakeCDG(box) failed"

else:

    print "\nCentre of gravity of box has been successfully obtained:"

    coords = geompy.PointCoordinates(cm)

    print "(", coords[0], ", ", coords[1], ", ", coords[2], ")"

    dx = math.sqrt((coords[0] - 50)*(coords[0] - 50))

    dy = math.sqrt((coords[1] - 15)*(coords[1] - 15))

    dz = math.sqrt((coords[2] - 50)*(coords[2] - 50))

    if dx > 1e-7 or dy > 1e-7 or dz > 1e-7:

        print "But must be (50, 15, 50)"

Inertia

import geompy

import math

 

# create a box

box = geompy.MakeBoxDXDYDZ(100,30,100)

In = geompy.Inertia(box)

print "\nInertia matrix of box 100x30x100:"

print " (", In[0], ", ", In[1], ", ", In[2], ")"

print " (", In[3], ", ", In[4], ", ", In[5], ")"

print " (", In[6], ", ", In[7], ", ", In[8], ")"

print "Main moments of inertia of box 100x30x100:"

print " Ix = ", In[9], ", Iy = ", In[10], ", Iz = ", In[11]

 

Check Free Boundaries

import os

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

# create boxes

box1 = geompy.MakeBox(0,0,0,100,50,100)

box2 = geompy.MakeBox(100,0,0,250,50,100)

 

# make a compound

compound = geompy.MakeCompound([box1, box2])

 

# import from *.brep

ImportBREP = geompy.ImportBREP("os.getenv("DATA_DIR")+"/Shapes/Brep/flight_solid.brep")

 

# get a face

faces = geompy.SubShapeAllSorted(ImportBREP, geompy.ShapeType["FACE"])

 

# get the free boundary for face 32

Res = geompy.GetFreeBoundary(faces[32])

isSuccess   = Res[0]

ClosedWires = Res[1]

OpenWires   = Res[2]

  

if isSuccess == 1 :

    print "Checking free boudaries is OK."

else :

    print "Checking free boudaries is KO!"

print "len(ClosedWires) = ", len(ClosedWires)

i = 0

for wire in ClosedWires :

    wire_name = "Face 32 -> Close wires : WIRE %d"%(i+1)

    geompy.addToStudy(ClosedWires[i], wire_name)

    if i < len(ClosedWires) :

        i = i+ 1

print "len(OpenWires) = ", len(OpenWires)

i = 0

for wire in OpenWires :

    wire_name = "Face 32 -> Open wires : WIRE %d"%(i+1)

    geompy.addToStudy(OpenWires[i], wire_name)

    if i < len(OpenWires) :

        i = i+ 1

 

# get the free boundary for face 41

Res = geompy.GetFreeBoundary(faces[41])

isSuccess   = Res[0]

ClosedWires = Res[1]

OpenWires   = Res[2]

  

if isSuccess == 1 :

    print "Checking free boudaries is OK."

else :

    print "Checking free boudaries is KO!"

print "len(ClosedWires) = ", len(ClosedWires)

i = 0

for wire in ClosedWires :

    wire_name = "Face 41 -> Close wires : WIRE %d"%(i+1)

    geompy.addToStudy(ClosedWires[i], wire_name)

    if i < len(ClosedWires) :

        i = i+ 1

print "len(OpenWires) = ", len(OpenWires)

i = 0

for wire in OpenWires :

    wire_name = "Face 41 -> Open wires : WIRE %d"%(i+1)

    geompy.addToStudy(OpenWires[i], wire_name)

    if i < len(OpenWires) :

        i = i+ 1

        

# add the imported object to the study

id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")

salome.sg.updateObjBrowser(1)

 

Check Free Faces

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

# create a vertex and a vector

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

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

v = geompy.MakeVector(p1, p2)

 

# create a cylinder

cylinder = geompy.MakeCone(p1, v, 30, 20, 20)

 

# create a cone

cone = geompy.MakeCone(p1, v, 70, 40, 60)

 

# make cut

cut = geompy.MakeCut(cone, cylinder)

 

# get faces as sub-shapes

faces = []

faces = geompy.SubShapeAllSorted(cut, geompy.ShapeType["FACE"])

f_2 = geompy.GetSubShapeID(cut, faces[0])

 

# remove one face from the shape

cut_without_f_2 = geompy.SuppressFaces(cut, [f_2])

 

# suppress the specified wire

result = geompy.GetFreeFacesIDs(cut_without_f_2)

print "A number of free faces is ", len(result)

 

# add objects in the study

all_faces = geompy.SubShapeAllSorted(cut_without_f_2, geompy.ShapeType["FACE"])

for face in all_faces :

    sub_shape_id = geompy.GetSubShapeID(cut_without_f_2, face)

    if result.count(sub_shape_id) > 0 :

        face_name = "Free face %d"%(sub_shape_id)

        geompy.addToStudy(face, face_name)

 

# in this example all faces from cut_without_f_2 are free

id_cut_without_f_2 = geompy.addToStudy(cut_without_f_2, "Cut without f_2")

 

# display the results

gg.createAndDisplayGO(id_cut_without_f_2)

gg.setDisplayMode(id_cut_without_f_2,1)

Bounding Box

import geompy

 

# create a box

box = geompy.MakeBoxDXDYDZ(100,30,100)

bb = geompy.BoundingBox(box)

print "\nBounding Box of box 100x30x100:"

print " Xmin = ", bb[0], ", Xmax = ", bb[1]

print " Ymin = ", bb[2], ", Ymax = ", bb[3]

print " Zmin = ", bb[4], ", Zmax = ", bb[5]

 

Minimal Distance

import geompy

 

# create boxes

box1 = geompy.MakeBoxDXDYDZ(100,30,100)

box2 = geompy.MakeBox(105,0,0,200,30,100)

min_dist = geompy.MinDistance(box1,box2)

print "\nMinimal distance between box1 and box2 = ", min_dist

Angle

import salome

salome.salome_init()

 

import math

import geompy

geompy.init_geom(salome.myStudy)

 

OX  = geompy.MakeVectorDXDYDZ(10, 0,0)

OXY = geompy.MakeVectorDXDYDZ(10,10,0)

 

# in one plane

Angle = geompy.GetAngle(OX, OXY)

 

print "\nAngle between OX and OXY = ", Angle

if math.fabs(Angle - 45.0) > 1e-05:

    print "  Error: returned angle is", Angle, "while must be 45.0"

    pass

 

# not in one plane

OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)

Angle = geompy.GetAngle(OX, OXY_shift)

 

print "Angle between OX and OXY_shift = ", Angle

if math.fabs(Angle - 45.0) > 1e-05:

    print "  Error: returned angle is", Angle, "while must be 45.0"

    pass

 

# not linear

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

pnt2 = geompy.MakeVertex(10, 0, 0)

pnt3 = geompy.MakeVertex(20, 10, 0)

arc  = geompy.MakeArc(pnt1, pnt2, pnt3)

Angle = geompy.GetAngle(OX, arc)

 

if (math.fabs(Angle + 1.0) > 1e-6 or geompy.MeasuOp.IsDone()):

    print "Error. Angle must not be computed on curvilinear edges"

    pass

Tolerance

import geompy

 

# create a box

box = geompy.MakeBoxDXDYDZ(100,30,100)

Toler = geompy.Tolerance(box)

print "\nBox 100x30x100 tolerance:"

print " Face min. tolerance: ", Toler[0]

print " Face max. tolerance: ", Toler[1]

print " Edge min. tolerance: ", Toler[2]

print " Edge max. tolerance: ", Toler[3]

print " Vertex min. tolerance: ", Toler[4]

print " Vertex max. tolerance: ", Toler[5]

 

What Is

import geompy

 

# create a box

box = geompy.MakeBoxDXDYDZ(100,30,100)

Descr = geompy.WhatIs(box)

print "\nBox 100x30x100 description:"

print Descr

 

Check Shape

import geompy

 

# create a box

box = geompy.MakeBoxDXDYDZ(100,30,100)

IsValid = geompy.CheckShape(box)

if IsValid == 0:

    raise RuntimeError, "Invalid box created"

else:

    print "\nBox is valid"

 

 

Check Compound of Blocks

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

# create boxes

box1 = geompy.MakeBox(0,0,0,100,50,100)

box2 = geompy.MakeBox(100,0,0,250,50,100)

 

# make a compound

compound = geompy.MakeCompound([box1, box2])

 

# glue the faces of the compound

tolerance = 1e-5

glue = geompy.MakeGlueFaces(compound, tolerance)

IsValid = geompy.CheckCompoundOfBlocks(glue)

if IsValid == 0:

    raise RuntimeError, "Invalid compound created"

else:

    print "\nCompound is valid"