m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.9 KiB

6 months ago
  1. from sympy.core.numbers import pi
  2. from sympy.functions.elementary.trigonometric import (cos, sin)
  3. from sympy.vector.coordsysrect import CoordSys3D
  4. from sympy.vector.parametricregion import ParametricRegion, parametric_region_list
  5. from sympy.geometry import Point, Segment, Curve, Ellipse, Line, Parabola, Polygon
  6. from sympy.testing.pytest import raises
  7. from sympy.abc import a, b, r, t, x, y, z, theta, phi
  8. C = CoordSys3D('C')
  9. def test_ParametricRegion():
  10. point = ParametricRegion((3, 4))
  11. assert point.definition == (3, 4)
  12. assert point.parameters == ()
  13. assert point.limits == {}
  14. assert point.dimensions == 0
  15. # line x = y
  16. line_xy = ParametricRegion((y, y), (y, 1, 5))
  17. assert line_xy .definition == (y, y)
  18. assert line_xy.parameters == (y,)
  19. assert line_xy.dimensions == 1
  20. # line y = z
  21. line_yz = ParametricRegion((x,t,t), x, (t, 1, 2))
  22. assert line_yz.definition == (x,t,t)
  23. assert line_yz.parameters == (x, t)
  24. assert line_yz.limits == {t: (1, 2)}
  25. assert line_yz.dimensions == 1
  26. p1 = ParametricRegion((9*a, -16*b), (a, 0, 2), (b, -1, 5))
  27. assert p1.definition == (9*a, -16*b)
  28. assert p1.parameters == (a, b)
  29. assert p1.limits == {a: (0, 2), b: (-1, 5)}
  30. assert p1.dimensions == 2
  31. p2 = ParametricRegion((t, t**3), t)
  32. assert p2.parameters == (t,)
  33. assert p2.limits == {}
  34. assert p2.dimensions == 0
  35. circle = ParametricRegion((r*cos(theta), r*sin(theta)), r, (theta, 0, 2*pi))
  36. assert circle.definition == (r*cos(theta), r*sin(theta))
  37. assert circle.dimensions == 1
  38. halfdisc = ParametricRegion((r*cos(theta), r*sin(theta)), (r, -2, 2), (theta, 0, pi))
  39. assert halfdisc.definition == (r*cos(theta), r*sin(theta))
  40. assert halfdisc.parameters == (r, theta)
  41. assert halfdisc.limits == {r: (-2, 2), theta: (0, pi)}
  42. assert halfdisc.dimensions == 2
  43. ellipse = ParametricRegion((a*cos(t), b*sin(t)), (t, 0, 8))
  44. assert ellipse.parameters == (t,)
  45. assert ellipse.limits == {t: (0, 8)}
  46. assert ellipse.dimensions == 1
  47. cylinder = ParametricRegion((r*cos(theta), r*sin(theta), z), (r, 0, 1), (theta, 0, 2*pi), (z, 0, 4))
  48. assert cylinder.parameters == (r, theta, z)
  49. assert cylinder.dimensions == 3
  50. sphere = ParametricRegion((r*sin(phi)*cos(theta),r*sin(phi)*sin(theta), r*cos(phi)),
  51. r, (theta, 0, 2*pi), (phi, 0, pi))
  52. assert sphere.definition == (r*sin(phi)*cos(theta),r*sin(phi)*sin(theta), r*cos(phi))
  53. assert sphere.parameters == (r, theta, phi)
  54. assert sphere.dimensions == 2
  55. raises(ValueError, lambda: ParametricRegion((a*t**2, 2*a*t), (a, -2)))
  56. raises(ValueError, lambda: ParametricRegion((a, b), (a**2, sin(b)), (a, 2, 4, 6)))
  57. def test_parametric_region_list():
  58. point = Point(-5, 12)
  59. assert parametric_region_list(point) == [ParametricRegion((-5, 12))]
  60. e = Ellipse(Point(2, 8), 2, 6)
  61. assert parametric_region_list(e, t) == [ParametricRegion((2*cos(t) + 2, 6*sin(t) + 8), (t, 0, 2*pi))]
  62. c = Curve((t, t**3), (t, 5, 3))
  63. assert parametric_region_list(c) == [ParametricRegion((t, t**3), (t, 5, 3))]
  64. s = Segment(Point(2, 11, -6), Point(0, 2, 5))
  65. assert parametric_region_list(s, t) == [ParametricRegion((2 - 2*t, 11 - 9*t, 11*t - 6), (t, 0, 1))]
  66. s1 = Segment(Point(0, 0), (1, 0))
  67. assert parametric_region_list(s1, t) == [ParametricRegion((t, 0), (t, 0, 1))]
  68. s2 = Segment(Point(1, 2, 3), Point(1, 2, 5))
  69. assert parametric_region_list(s2, t) == [ParametricRegion((1, 2, 2*t + 3), (t, 0, 1))]
  70. s3 = Segment(Point(12, 56), Point(12, 56))
  71. assert parametric_region_list(s3) == [ParametricRegion((12, 56))]
  72. poly = Polygon((1,3), (-3, 8), (2, 4))
  73. assert parametric_region_list(poly, t) == [ParametricRegion((1 - 4*t, 5*t + 3), (t, 0, 1)), ParametricRegion((5*t - 3, 8 - 4*t), (t, 0, 1)), ParametricRegion((2 - t, 4 - t), (t, 0, 1))]
  74. p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7,8)))
  75. raises(ValueError, lambda: parametric_region_list(p1))