MCPcopy
hub / github.com/CadQuery/cadquery / testRotatedEllipse

Method testRotatedEllipse

tests/test_cadquery.py:870–977  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

868 )
869
870 def testRotatedEllipse(self):
871 def rotatePoint(x, y, alpha):
872 # rotation matrix
873 a = alpha * DEG2RAD
874 r = ((math.cos(a), math.sin(a)), (-math.sin(a), math.cos(a)))
875 return ((x * r[0][0] + y * r[1][0]), (x * r[0][1] + y * r[1][1]))
876
877 def ellipsePoints(r1, r2, a):
878 return (r1 * math.cos(a * DEG2RAD), r2 * math.sin(a * DEG2RAD))
879
880 DEG2RAD = math.pi / 180.0
881 p0 = (10, 20)
882 a1, a2 = 30, -60
883 r1, r2 = 20, 10
884 ra = 25
885
886 sx_rot, sy_rot = rotatePoint(*ellipsePoints(r1, r2, a1), ra)
887 ex_rot, ey_rot = rotatePoint(*ellipsePoints(r1, r2, a2), ra)
888
889 # startAtCurrent=False, sense = 1
890 ellipseArc1 = (
891 Workplane("XY")
892 .moveTo(*p0)
893 .ellipseArc(
894 r1, r2, startAtCurrent=False, angle1=a1, angle2=a2, rotation_angle=ra
895 )
896 )
897 start = ellipseArc1.val().startPoint()
898 end = ellipseArc1.val().endPoint()
899
900 self.assertTupleAlmostEquals(
901 (start.x, start.y), (p0[0] + sx_rot, p0[1] + sy_rot), 3
902 )
903 self.assertTupleAlmostEquals(
904 (end.x, end.y), (p0[0] + ex_rot, p0[1] + ey_rot), 3
905 )
906
907 # startAtCurrent=True, sense = 1
908 ellipseArc2 = (
909 Workplane("XY")
910 .moveTo(*p0)
911 .ellipseArc(
912 r1, r2, startAtCurrent=True, angle1=a1, angle2=a2, rotation_angle=ra
913 )
914 )
915 start = ellipseArc2.val().startPoint()
916 end = ellipseArc2.val().endPoint()
917
918 self.assertTupleAlmostEquals(
919 (start.x, start.y), (p0[0] + sx_rot - sx_rot, p0[1] + sy_rot - sy_rot), 3
920 )
921 self.assertTupleAlmostEquals(
922 (end.x, end.y), (p0[0] + ex_rot - sx_rot, p0[1] + ey_rot - sy_rot), 3
923 )
924
925 # startAtCurrent=False, sense = -1
926 ellipseArc3 = (
927 Workplane("XY")

Callers

nothing calls this directly

Calls 7

WorkplaneClass · 0.85
ellipseArcMethod · 0.80
moveToMethod · 0.80
startPointMethod · 0.80
endPointMethod · 0.80
valMethod · 0.45

Tested by

no test coverage detected