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.

106 lines
5.0 KiB

6 months ago
  1. from sympy.core.numbers import pi
  2. from sympy.core.singleton import S
  3. from sympy.functions.elementary.miscellaneous import sqrt
  4. from sympy.functions.elementary.trigonometric import (cos, sin)
  5. from sympy.testing.pytest import raises
  6. from sympy.vector.coordsysrect import CoordSys3D
  7. from sympy.vector.integrals import ParametricIntegral, vector_integrate
  8. from sympy.vector.parametricregion import ParametricRegion
  9. from sympy.vector.implicitregion import ImplicitRegion
  10. from sympy.abc import x, y, z, u, v, r, t, theta, phi
  11. from sympy.geometry import Point, Segment, Curve, Circle, Polygon, Plane
  12. C = CoordSys3D('C')
  13. def test_parametric_lineintegrals():
  14. halfcircle = ParametricRegion((4*cos(theta), 4*sin(theta)), (theta, -pi/2, pi/2))
  15. assert ParametricIntegral(C.x*C.y**4, halfcircle) == S(8192)/5
  16. curve = ParametricRegion((t, t**2, t**3), (t, 0, 1))
  17. field1 = 8*C.x**2*C.y*C.z*C.i + 5*C.z*C.j - 4*C.x*C.y*C.k
  18. assert ParametricIntegral(field1, curve) == 1
  19. line = ParametricRegion((4*t - 1, 2 - 2*t, t), (t, 0, 1))
  20. assert ParametricIntegral(C.x*C.z*C.i - C.y*C.z*C.k, line) == 3
  21. assert ParametricIntegral(4*C.x**3, ParametricRegion((1, t), (t, 0, 2))) == 8
  22. helix = ParametricRegion((cos(t), sin(t), 3*t), (t, 0, 4*pi))
  23. assert ParametricIntegral(C.x*C.y*C.z, helix) == -3*sqrt(10)*pi
  24. field2 = C.y*C.i + C.z*C.j + C.z*C.k
  25. assert ParametricIntegral(field2, ParametricRegion((cos(t), sin(t), t**2), (t, 0, pi))) == -5*pi/2 + pi**4/2
  26. def test_parametric_surfaceintegrals():
  27. semisphere = ParametricRegion((2*sin(phi)*cos(theta), 2*sin(phi)*sin(theta), 2*cos(phi)),\
  28. (theta, 0, 2*pi), (phi, 0, pi/2))
  29. assert ParametricIntegral(C.z, semisphere) == 8*pi
  30. cylinder = ParametricRegion((sqrt(3)*cos(theta), sqrt(3)*sin(theta), z), (z, 0, 6), (theta, 0, 2*pi))
  31. assert ParametricIntegral(C.y, cylinder) == 0
  32. cone = ParametricRegion((v*cos(u), v*sin(u), v), (u, 0, 2*pi), (v, 0, 1))
  33. assert ParametricIntegral(C.x*C.i + C.y*C.j + C.z**4*C.k, cone) == pi/3
  34. triangle1 = ParametricRegion((x, y), (x, 0, 2), (y, 0, 10 - 5*x))
  35. triangle2 = ParametricRegion((x, y), (y, 0, 10 - 5*x), (x, 0, 2))
  36. assert ParametricIntegral(-15.6*C.y*C.k, triangle1) == ParametricIntegral(-15.6*C.y*C.k, triangle2)
  37. assert ParametricIntegral(C.z, triangle1) == 10*C.z
  38. def test_parametric_volumeintegrals():
  39. cube = ParametricRegion((x, y, z), (x, 0, 1), (y, 0, 1), (z, 0, 1))
  40. assert ParametricIntegral(1, cube) == 1
  41. solidsphere1 = ParametricRegion((r*sin(phi)*cos(theta), r*sin(phi)*sin(theta), r*cos(phi)),\
  42. (r, 0, 2), (theta, 0, 2*pi), (phi, 0, pi))
  43. solidsphere2 = ParametricRegion((r*sin(phi)*cos(theta), r*sin(phi)*sin(theta), r*cos(phi)),\
  44. (r, 0, 2), (phi, 0, pi), (theta, 0, 2*pi))
  45. assert ParametricIntegral(C.x**2 + C.y**2, solidsphere1) == -256*pi/15
  46. assert ParametricIntegral(C.x**2 + C.y**2, solidsphere2) == 256*pi/15
  47. region_under_plane1 = ParametricRegion((x, y, z), (x, 0, 3), (y, 0, -2*x/3 + 2),\
  48. (z, 0, 6 - 2*x - 3*y))
  49. region_under_plane2 = ParametricRegion((x, y, z), (x, 0, 3), (z, 0, 6 - 2*x - 3*y),\
  50. (y, 0, -2*x/3 + 2))
  51. assert ParametricIntegral(C.x*C.i + C.j - 100*C.k, region_under_plane1) == \
  52. ParametricIntegral(C.x*C.i + C.j - 100*C.k, region_under_plane2)
  53. assert ParametricIntegral(2*C.x, region_under_plane2) == -9
  54. def test_vector_integrate():
  55. halfdisc = ParametricRegion((r*cos(theta), r* sin(theta)), (r, -2, 2), (theta, 0, pi))
  56. assert vector_integrate(C.x**2, halfdisc) == 4*pi
  57. assert vector_integrate(C.x, ParametricRegion((t, t**2), (t, 2, 3))) == -17*sqrt(17)/12 + 37*sqrt(37)/12
  58. assert vector_integrate(C.y**3*C.z, (C.x, 0, 3), (C.y, -1, 4)) == 765*C.z/4
  59. s1 = Segment(Point(0, 0), Point(0, 1))
  60. assert vector_integrate(-15*C.y, s1) == S(-15)/2
  61. s2 = Segment(Point(4, 3, 9), Point(1, 1, 7))
  62. assert vector_integrate(C.y*C.i, s2) == -6
  63. curve = Curve((sin(t), cos(t)), (t, 0, 2))
  64. assert vector_integrate(5*C.z, curve) == 10*C.z
  65. c1 = Circle(Point(2, 3), 6)
  66. assert vector_integrate(C.x*C.y, c1) == 72*pi
  67. c2 = Circle(Point(0, 0), Point(1, 1), Point(1, 0))
  68. assert vector_integrate(1, c2) == c2.circumference
  69. triangle = Polygon((0, 0), (1, 0), (1, 1))
  70. assert vector_integrate(C.x*C.i - 14*C.y*C.j, triangle) == 0
  71. p1, p2, p3, p4 = [(0, 0), (1, 0), (5, 1), (0, 1)]
  72. poly = Polygon(p1, p2, p3, p4)
  73. assert vector_integrate(-23*C.z, poly) == -161*C.z - 23*sqrt(17)*C.z
  74. point = Point(2, 3)
  75. assert vector_integrate(C.i*C.y - C.z, point) == ParametricIntegral(C.y*C.i, ParametricRegion((2, 3)))
  76. c3 = ImplicitRegion((x, y), x**2 + y**2 - 4)
  77. assert vector_integrate(45, c3) == 180*pi
  78. c4 = ImplicitRegion((x, y), (x - 3)**2 + (y - 4)**2 - 9)
  79. assert vector_integrate(1, c4) == 6*pi
  80. pl = Plane(Point(1, 1, 1), Point(2, 3, 4), Point(2, 2, 2))
  81. raises(ValueError, lambda: vector_integrate(C.x*C.z*C.i + C.k, pl))