geom/doc/salome/examples/angle.py

64 lines
1.8 KiB
Python
Raw Normal View History

2013-02-12 17:35:16 +06:00
# Angle
import salome
salome.salome_init()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New(salome.myStudy)
2013-02-12 17:35:16 +06:00
import math
OX = geompy.MakeVectorDXDYDZ(10, 0,0)
OXY = geompy.MakeVectorDXDYDZ(10,10,0)
# in one plane
Angle = geompy.GetAngle(OX, OXY)
2017-02-10 21:07:24 +05:00
print("\nAngle between OX and OXY = ", Angle)
2013-02-12 17:35:16 +06:00
if math.fabs(Angle - 45.0) > 1e-05:
2017-02-10 21:07:24 +05:00
print(" Error: returned angle is", Angle, "while must be 45.0")
2013-02-12 17:35:16 +06:00
pass
Angle = geompy.GetAngleRadians(OX, OXY)
2017-02-10 21:07:24 +05:00
print("\nAngle between OX and OXY in radians = ", Angle)
2013-02-12 17:35:16 +06:00
if math.fabs(Angle - math.pi/4) > 1e-05:
2017-02-10 21:07:24 +05:00
print(" Error: returned angle is", Angle, "while must be pi/4")
2013-02-12 17:35:16 +06:00
pass
Angle = geompy.GetAngleVectors(OX, OXY, True)
2017-02-10 21:07:24 +05:00
print("\nAngle between vectors OX and OXY = ", Angle)
2013-02-12 17:35:16 +06:00
if math.fabs(Angle - 45.0) > 1e-05:
2017-02-10 21:07:24 +05:00
print(" Error: returned angle is", Angle, "while must be 45.0")
2013-02-12 17:35:16 +06:00
pass
Angle = geompy.GetAngleRadiansVectors(OX, OXY, False)
2017-02-10 21:07:24 +05:00
print("\nBig angle between vectors OX and OXY in radians = ", Angle)
2013-02-12 17:35:16 +06:00
if math.fabs(Angle - math.pi*7./4.) > 1e-05:
2017-02-10 21:07:24 +05:00
print(" Error: returned angle is", Angle, "while must be 7*pi/4")
2013-02-12 17:35:16 +06:00
pass
# not in one plane
OXY_shift = geompy.MakeTranslation(OXY,10,-10,20)
Angle = geompy.GetAngle(OX, OXY_shift)
2017-02-10 21:07:24 +05:00
print("\nAngle between OX and OXY_shift = ", Angle)
2013-02-12 17:35:16 +06:00
if math.fabs(Angle - 45.0) > 1e-05:
2017-02-10 21:07:24 +05:00
print(" Error: returned angle is", Angle, "while must be 45.0")
2013-02-12 17:35:16 +06:00
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)
2013-02-28 20:00:05 +06:00
try:
Angle = geompy.GetAngle(OX, arc)
pass
except:
# It is a correct case, because GetAngle() must not be computed on curvilinear edges.
2013-02-12 17:35:16 +06:00
pass
2013-02-28 20:00:05 +06:00
assert (not geompy.MeasuOp.IsDone() ), 'Angle must not be computed on curvilinear edges.'