本文整理汇总了Python中sympy.geometry.Ellipse.atoms方法的典型用法代码示例。如果您正苦于以下问题:Python Ellipse.atoms方法的具体用法?Python Ellipse.atoms怎么用?Python Ellipse.atoms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.geometry.Ellipse
的用法示例。
在下文中一共展示了Ellipse.atoms方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ellipse
# 需要导入模块: from sympy.geometry import Ellipse [as 别名]
# 或者: from sympy.geometry.Ellipse import atoms [as 别名]
def test_ellipse():
p1 = Point(0, 0)
p2 = Point(1, 1)
p3 = Point(x1, x2)
p4 = Point(0, 1)
p5 = Point(-1, 0)
e1 = Ellipse(p1, 1, 1)
e2 = Ellipse(p2, half, 1)
e3 = Ellipse(p1, y1, y1)
c1 = Circle(p1, 1)
c2 = Circle(p2,1)
c3 = Circle(Point(sqrt(2),sqrt(2)),1)
# Test creation with three points
cen, rad = Point(3*half, 2), 5*half
assert Circle(Point(0,0), Point(3,0), Point(0,4)) == Circle(cen, rad)
raises(GeometryError, "Circle(Point(0,0), Point(1,1), Point(2,2))")
# Basic Stuff
assert e1 == c1
assert e1 != e2
assert p4 in e1
assert p2 not in e2
assert e1.area == pi
assert e2.area == pi/2
assert e3.area == pi*(y1**2)
assert c1.area == e1.area
assert c1.circumference == e1.circumference
assert e3.circumference == 2*pi*y1
# with generic symbols, the hradius is assumed to contain the major radius
M = Symbol('M')
m = Symbol('m')
c = Ellipse(p1, M, m).circumference
_x = c.atoms(Dummy).pop()
assert c == \
4*M*C.Integral(sqrt((1 - _x**2*(M**2 - m**2)/M**2)/(1 - _x**2)), (_x, 0, 1))
assert e2.arbitrary_point() in e2
# Foci
f1, f2 = Point(sqrt(12), 0), Point(-sqrt(12), 0)
ef = Ellipse(Point(0, 0), 4, 2)
assert ef.foci in [(f1, f2), (f2, f1)]
# Tangents
v = sqrt(2) / 2
p1_1 = Point(v, v)
p1_2 = p2 + Point(half, 0)
p1_3 = p2 + Point(0, 1)
assert e1.tangent_lines(p4) == c1.tangent_lines(p4)
assert e2.tangent_lines(p1_2) == [Line(p1_2, p2 + Point(half, 1))]
assert e2.tangent_lines(p1_3) == [Line(p1_3, p2 + Point(half, 1))]
assert c1.tangent_lines(p1_1) == [Line(p1_1, Point(0, sqrt(2)))]
assert e2.is_tangent(Line(p1_2, p2 + Point(half, 1)))
assert e2.is_tangent(Line(p1_3, p2 + Point(half, 1)))
assert c1.is_tangent(Line(p1_1, Point(0, sqrt(2))))
assert e1.is_tangent(Line(Point(0, 0), Point(1, 1))) == False
assert Ellipse(Point(5, 5), 2, 1).tangent_lines(Point(0, 0)) == \
[Line(Point(0, 0), Point(S(77)/25, S(132)/25)),
Line(Point(0, 0), Point(S(33)/5, S(22)/5))]
assert Ellipse(Point(5, 5), 2, 1).tangent_lines(Point(3, 4)) == \
[Line(Point(3, 4), Point(3, 5)), Line(Point(3, 4), Point(5, 4))]
assert Circle(Point(5, 5), 2).tangent_lines(Point(3, 3)) == \
[Line(Point(3, 3), Point(3, 5)), Line(Point(3, 3), Point(5, 3))]
assert Circle(Point(5, 5), 2).tangent_lines(Point(5 - 2*sqrt(2), 5)) == \
[Line(Point(5 - 2*sqrt(2), 5), Point(5 - sqrt(2), 5 - sqrt(2))),
Line(Point(5 - 2*sqrt(2), 5), Point(5 - sqrt(2), 5 + sqrt(2))),]
# Properties
major = 3
minor = 1
e4 = Ellipse(p2, minor, major)
assert e4.focus_distance == sqrt(major**2 - minor**2)
ecc = e4.focus_distance / major
assert e4.eccentricity == ecc
assert e4.periapsis == major*(1 - ecc)
assert e4.apoapsis == major*(1 + ecc)
# independent of orientation
e4 = Ellipse(p2, major, minor)
assert e4.focus_distance == sqrt(major**2 - minor**2)
ecc = e4.focus_distance / major
assert e4.eccentricity == ecc
assert e4.periapsis == major*(1 - ecc)
assert e4.apoapsis == major*(1 + ecc)
# Intersection
l1 = Line(Point(1, -5), Point(1, 5))
l2 = Line(Point(-5, -1), Point(5, -1))
l3 = Line(Point(-1, -1), Point(1, 1))
l4 = Line(Point(-10, 0), Point(0, 10))
pts_c1_l3 = [Point(sqrt(2)/2, sqrt(2)/2), Point(-sqrt(2)/2, -sqrt(2)/2)]
assert intersection(e2, l4) == []
assert intersection(c1, Point(1, 0)) == [Point(1, 0)]
assert intersection(c1, l1) == [Point(1, 0)]
assert intersection(c1, l2) == [Point(0, -1)]
assert intersection(c1, l3) in [pts_c1_l3, [pts_c1_l3[1], pts_c1_l3[0]]]
#.........这里部分代码省略.........
示例2: test_ellipse
# 需要导入模块: from sympy.geometry import Ellipse [as 别名]
# 或者: from sympy.geometry.Ellipse import atoms [as 别名]
def test_ellipse():
p1 = Point(0, 0)
p2 = Point(1, 1)
p4 = Point(0, 1)
e1 = Ellipse(p1, 1, 1)
e2 = Ellipse(p2, half, 1)
e3 = Ellipse(p1, y1, y1)
c1 = Circle(p1, 1)
c2 = Circle(p2, 1)
c3 = Circle(Point(sqrt(2), sqrt(2)), 1)
# Test creation with three points
cen, rad = Point(3 * half, 2), 5 * half
assert Circle(Point(0, 0), Point(3, 0), Point(0, 4)) == Circle(cen, rad)
raises(GeometryError, lambda: Circle(Point(0, 0), Point(1, 1), Point(2, 2)))
raises(ValueError, lambda: Ellipse(None, None, None, 1))
raises(GeometryError, lambda: Circle(Point(0, 0)))
# Basic Stuff
assert Ellipse(None, 1, 1).center == Point(0, 0)
assert e1 == c1
assert e1 != e2
assert p4 in e1
assert p2 not in e2
assert e1.area == pi
assert e2.area == pi / 2
assert e3.area == pi * (y1 ** 2)
assert c1.area == e1.area
assert c1.circumference == e1.circumference
assert e3.circumference == 2 * pi * y1
assert e1.plot_interval() == e2.plot_interval() == [t, -pi, pi]
assert e1.plot_interval(x) == e2.plot_interval(x) == [x, -pi, pi]
assert Ellipse(None, 1, None, 1).circumference == 2 * pi
assert c1.minor == 1
assert c1.major == 1
assert c1.hradius == 1
assert c1.vradius == 1
# Private Functions
assert hash(c1) == hash(Circle(Point(1, 0), Point(0, 1), Point(0, -1)))
assert c1 in e1
assert (Line(p1, p2) in e1) == False
assert e1.__cmp__(e1) == 0
assert e1.__cmp__(Point(0, 0)) > 0
# Encloses
assert e1.encloses(Segment(Point(-0.5, -0.5), Point(0.5, 0.5))) == True
assert e1.encloses(Line(p1, p2)) == False
assert e1.encloses(Ray(p1, p2)) == False
assert e1.encloses(e1) == False
assert e1.encloses(Polygon(Point(-0.5, -0.5), Point(-0.5, 0.5), Point(0.5, 0.5))) == True
assert e1.encloses(RegularPolygon(p1, 0.5, 3)) == True
assert e1.encloses(RegularPolygon(p1, 5, 3)) == False
assert e1.encloses(RegularPolygon(p2, 5, 3)) == False
# with generic symbols, the hradius is assumed to contain the major radius
M = Symbol("M")
m = Symbol("m")
c = Ellipse(p1, M, m).circumference
_x = c.atoms(Dummy).pop()
assert c == 4 * M * C.Integral(sqrt((1 - _x ** 2 * (M ** 2 - m ** 2) / M ** 2) / (1 - _x ** 2)), (_x, 0, 1))
assert e2.arbitrary_point() in e2
# Foci
f1, f2 = Point(sqrt(12), 0), Point(-sqrt(12), 0)
ef = Ellipse(Point(0, 0), 4, 2)
assert ef.foci in [(f1, f2), (f2, f1)]
# Tangents
v = sqrt(2) / 2
p1_1 = Point(v, v)
p1_2 = p2 + Point(half, 0)
p1_3 = p2 + Point(0, 1)
assert e1.tangent_lines(p4) == c1.tangent_lines(p4)
assert e2.tangent_lines(p1_2) == [Line(p1_2, p2 + Point(half, 1))]
assert e2.tangent_lines(p1_3) == [Line(p1_3, p2 + Point(half, 1))]
assert c1.tangent_lines(p1_1) == [Line(p1_1, Point(0, sqrt(2)))]
assert c1.tangent_lines(p1) == []
assert e2.is_tangent(Line(p1_2, p2 + Point(half, 1)))
assert e2.is_tangent(Line(p1_3, p2 + Point(half, 1)))
assert c1.is_tangent(Line(p1_1, Point(0, sqrt(2))))
assert e1.is_tangent(Line(Point(0, 0), Point(1, 1))) == False
assert c1.is_tangent(e1) == False
assert c1.is_tangent(Ellipse(Point(2, 0), 1, 1)) == True
assert c1.is_tangent(Polygon(Point(1, 1), Point(1, -1), Point(2, 0))) == True
assert c1.is_tangent(Polygon(Point(1, 1), Point(1, 0), Point(2, 0))) == False
assert Ellipse(Point(5, 5), 2, 1).tangent_lines(Point(0, 0)) == [
Line(Point(0, 0), Point(S(77) / 25, S(132) / 25)),
Line(Point(0, 0), Point(S(33) / 5, S(22) / 5)),
]
assert Ellipse(Point(5, 5), 2, 1).tangent_lines(Point(3, 4)) == [
Line(Point(3, 4), Point(4, 4)),
Line(Point(3, 4), Point(3, 5)),
]
assert Circle(Point(5, 5), 2).tangent_lines(Point(3, 3)) == [
Line(Point(3, 3), Point(4, 3)),
#.........这里部分代码省略.........
示例3: test_ellipse_geom
# 需要导入模块: from sympy.geometry import Ellipse [as 别名]
# 或者: from sympy.geometry.Ellipse import atoms [as 别名]
def test_ellipse_geom():
x = Symbol('x', real=True)
y = Symbol('y', real=True)
t = Symbol('t', real=True)
y1 = Symbol('y1', real=True)
half = Rational(1, 2)
p1 = Point(0, 0)
p2 = Point(1, 1)
p4 = Point(0, 1)
e1 = Ellipse(p1, 1, 1)
e2 = Ellipse(p2, half, 1)
e3 = Ellipse(p1, y1, y1)
c1 = Circle(p1, 1)
c2 = Circle(p2, 1)
c3 = Circle(Point(sqrt(2), sqrt(2)), 1)
# Test creation with three points
cen, rad = Point(3*half, 2), 5*half
assert Circle(Point(0, 0), Point(3, 0), Point(0, 4)) == Circle(cen, rad)
raises(
GeometryError, lambda: Circle(Point(0, 0), Point(1, 1), Point(2, 2)))
raises(ValueError, lambda: Ellipse(None, None, None, 1))
raises(GeometryError, lambda: Circle(Point(0, 0)))
# Basic Stuff
assert Ellipse(None, 1, 1).center == Point(0, 0)
assert e1 == c1
assert e1 != e2
assert p4 in e1
assert p2 not in e2
assert e1.area == pi
assert e2.area == pi/2
assert e3.area == pi*y1*abs(y1)
assert c1.area == e1.area
assert c1.circumference == e1.circumference
assert e3.circumference == 2*pi*y1
assert e1.plot_interval() == e2.plot_interval() == [t, -pi, pi]
assert e1.plot_interval(x) == e2.plot_interval(x) == [x, -pi, pi]
assert Ellipse(None, 1, None, 1).circumference == 2*pi
assert c1.minor == 1
assert c1.major == 1
assert c1.hradius == 1
assert c1.vradius == 1
# Private Functions
assert hash(c1) == hash(Circle(Point(1, 0), Point(0, 1), Point(0, -1)))
assert c1 in e1
assert (Line(p1, p2) in e1) is False
assert e1.__cmp__(e1) == 0
assert e1.__cmp__(Point(0, 0)) > 0
# Encloses
assert e1.encloses(Segment(Point(-0.5, -0.5), Point(0.5, 0.5))) is True
assert e1.encloses(Line(p1, p2)) is False
assert e1.encloses(Ray(p1, p2)) is False
assert e1.encloses(e1) is False
assert e1.encloses(
Polygon(Point(-0.5, -0.5), Point(-0.5, 0.5), Point(0.5, 0.5))) is True
assert e1.encloses(RegularPolygon(p1, 0.5, 3)) is True
assert e1.encloses(RegularPolygon(p1, 5, 3)) is False
assert e1.encloses(RegularPolygon(p2, 5, 3)) is False
# with generic symbols, the hradius is assumed to contain the major radius
M = Symbol('M')
m = Symbol('m')
c = Ellipse(p1, M, m).circumference
_x = c.atoms(Dummy).pop()
assert c == 4*M*Integral(
sqrt((1 - _x**2*(M**2 - m**2)/M**2)/(1 - _x**2)), (_x, 0, 1))
assert e2.arbitrary_point() in e2
# Foci
f1, f2 = Point(sqrt(12), 0), Point(-sqrt(12), 0)
ef = Ellipse(Point(0, 0), 4, 2)
assert ef.foci in [(f1, f2), (f2, f1)]
# Tangents
v = sqrt(2) / 2
p1_1 = Point(v, v)
p1_2 = p2 + Point(half, 0)
p1_3 = p2 + Point(0, 1)
assert e1.tangent_lines(p4) == c1.tangent_lines(p4)
assert e2.tangent_lines(p1_2) == [Line(Point(3/2, 1), Point(3/2, 1/2))]
assert e2.tangent_lines(p1_3) == [Line(Point(1, 2), Point(5/4, 2))]
assert c1.tangent_lines(p1_1) != [Line(p1_1, Point(0, sqrt(2)))]
assert c1.tangent_lines(p1) == []
assert e2.is_tangent(Line(p1_2, p2 + Point(half, 1)))
assert e2.is_tangent(Line(p1_3, p2 + Point(half, 1)))
assert c1.is_tangent(Line(p1_1, Point(0, sqrt(2))))
assert e1.is_tangent(Line(Point(0, 0), Point(1, 1))) is False
assert c1.is_tangent(e1) is False
assert c1.is_tangent(Ellipse(Point(2, 0), 1, 1)) is True
assert c1.is_tangent(
Polygon(Point(1, 1), Point(1, -1), Point(2, 0))) is True
assert c1.is_tangent(
Polygon(Point(1, 1), Point(1, 0), Point(2, 0))) is False
assert Circle(Point(5, 5), 3).is_tangent(Circle(Point(0, 5), 1)) is False
#.........这里部分代码省略.........