Python| Sympy Ellipse() 方法
在 sympy 中,函数
Ellipse()
用于从一个中心和两个半径创建椭圆,第一个是水平半径(沿 x 轴),第二个是垂直半径(沿 y 轴)。Syntax: Ellipse()
Parameters:
center: Point
hradius: number or SymPy expression, optional
vradius: number or SymPy expression, optional
eccentricity: number or SymPy expression, optional
Error: Raises Geometry Error when hradius, vradius and eccentricity are incorrectly supplied as parameters and Type Error when center is not a Point.
示例 #1:使用中心和半径
# import sympy and geometry module
from sympy.geometry import Point, Ellipse
# using Ellipse()
e1 = Ellipse(Point(0, 0), 5, 1)
print(e1.hradius,e1.vradius)
输出:
(5,1)
示例 #2:使用中心、半径和偏心率
# import sympy and geometry module
from sympy.geometry import Point, Ellipse, Rational
# using Ellipse()
e2 = Ellipse(Point(3, 1), hradius=3, eccentricity=Rational(4, 5))
print(e2)
输出:
Ellipse(Point2D(3, 1), 3, 9/5)
示例#3:使用中心、vradius 和 eccentricity
# import sympy and geometry module
from sympy.geometry import Point, Ellipse, Rational
# using Ellipse()
e2 = Ellipse(Point(3, 1), vradius=3, eccentricity=Rational(4, 5))
print(e2)
输出:
Ellipse(Point2D(3, 1), 5, 3)