线#

class sympy.geometry.line.LinearEntity(p1, p2=None, **kwargs)[源代码]#

n维欧几里德空间中所有线性实体(直线、射线和线段)的基类。

笔记

这是一个抽象类,不打算被实例化。

属性

ambient_dimension

方向

长度

第一页

第2页

property ambient_dimension#

返回LinearEntity对象的维度的属性方法。

参数:

p1 :线性度

返回:

:整数

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> l1 = Line(p1, p2)
>>> l1.ambient_dimension
2
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0, 0), Point(1, 1, 1)
>>> l1 = Line(p1, p2)
>>> l1.ambient_dimension
3
angle_between(l2)[源代码]#

返回从原点发出的光线形成的非反射角,其方向与线性实体的方向向量相同。

参数:

l1 :线性度

l2 :线性度

返回:

:以弧度表示的角度

笔记

根据向量v1和v2的点积可知:

dot(v1, v2) = |v1|*|v2|*cos(A)

其中A是两个矢量之间形成的角度。利用上述公式,我们可以得到两条直线的方向向量,并很容易地求出两条直线之间的夹角。

实例

>>> from sympy import Line
>>> e = Line((0, 0), (1, 0))
>>> ne = Line((0, 0), (1, 1))
>>> sw = Line((1, 1), (0, 0))
>>> ne.angle_between(e)
pi/4
>>> sw.angle_between(e)
3*pi/4

若要获得直线相交处的非钝角,请使用 smallest_angle_between 方法:

>>> sw.smallest_angle_between(e)
pi/4
>>> from sympy import Point3D, Line3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(-1, 2, 0)
>>> l1, l2 = Line3D(p1, p2), Line3D(p2, p3)
>>> l1.angle_between(l2)
acos(-sqrt(2)/3)
>>> l1.smallest_angle_between(l2)
acos(sqrt(2)/3)
arbitrary_point(parameter='t')[源代码]#

线上的参数化点。

参数:

参数 :str,可选

将用于参数化点的参数的名称。默认值为“t”。当该参数为0时,返回定义直线的第一个点,当该参数为1时,返回第二个点。

返回:

:点

加薪:

ValueError

什么时候? parameter 已经出现在行的定义中。

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.arbitrary_point()
Point2D(4*t + 1, 3*t)
>>> from sympy import Point3D, Line3D
>>> p1, p2 = Point3D(1, 0, 0), Point3D(5, 3, 1)
>>> l1 = Line3D(p1, p2)
>>> l1.arbitrary_point()
Point3D(4*t + 1, 3*t, t)
static are_concurrent(*lines)[源代码]#

一系列的线性实体是并行的吗?

如果两个并行实体在一个点上相交,则为一个或多个并行实体。

参数:

lines

A sequence of linear entities.

返回:

True :如果一组线性实体相交于一个点

:否则。

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(3, 5)
>>> p3, p4 = Point(-2, -2), Point(0, 2)
>>> l1, l2, l3 = Line(p1, p2), Line(p1, p3), Line(p1, p4)
>>> Line.are_concurrent(l1, l2, l3)
True
>>> l4 = Line(p2, p3)
>>> Line.are_concurrent(l2, l3, l4)
False
>>> from sympy import Point3D, Line3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(3, 5, 2)
>>> p3, p4 = Point3D(-2, -2, -2), Point3D(0, 2, 1)
>>> l1, l2, l3 = Line3D(p1, p2), Line3D(p1, p3), Line3D(p1, p4)
>>> Line3D.are_concurrent(l1, l2, l3)
True
>>> l4 = Line3D(p2, p3)
>>> Line3D.are_concurrent(l2, l3, l4)
False
bisectors(other)[源代码]#

返回穿过在同一平面上的自身与他人交点的垂直线。

参数:

line :Line3D

返回:

列表:两个线实例

实例

>>> from sympy import Point3D, Line3D
>>> r1 = Line3D(Point3D(0, 0, 0), Point3D(1, 0, 0))
>>> r2 = Line3D(Point3D(0, 0, 0), Point3D(0, 1, 0))
>>> r1.bisectors(r2)
[Line3D(Point3D(0, 0, 0), Point3D(1, 1, 0)), Line3D(Point3D(0, 0, 0), Point3D(1, -1, 0))]
contains(other)[源代码]#

子类应该实现这个方法,如果其他类在self的边界上,则应该返回True;如果不在self边界上,则返回False;如果无法确定,则返回None。

property direction#

线性度的方向向量。

返回:

p :一个点;从原点到该点的光线是

方向 \(self\)

实例

>>> from sympy import Line
>>> a, b = (1, 1), (1, 3)
>>> Line(a, b).direction
Point2D(0, 2)
>>> Line(b, a).direction
Point2D(0, -2)

这可以报告为距原点的距离为1:

>>> Line(b, a).direction.unit
Point2D(0, -1)
intersection(other)[源代码]#

与另一个几何实体的交集。

参数:

o :点或线性

返回:

交叉 :几何实体列表

实例

>>> from sympy import Point, Line, Segment
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(7, 7)
>>> l1 = Line(p1, p2)
>>> l1.intersection(p3)
[Point2D(7, 7)]
>>> p4, p5 = Point(5, 0), Point(0, 3)
>>> l2 = Line(p4, p5)
>>> l1.intersection(l2)
[Point2D(15/8, 15/8)]
>>> p6, p7 = Point(0, 5), Point(2, 6)
>>> s1 = Segment(p6, p7)
>>> l1.intersection(s1)
[]
>>> from sympy import Point3D, Line3D, Segment3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(7, 7, 7)
>>> l1 = Line3D(p1, p2)
>>> l1.intersection(p3)
[Point3D(7, 7, 7)]
>>> l1 = Line3D(Point3D(4,19,12), Point3D(5,25,17))
>>> l2 = Line3D(Point3D(-3, -15, -19), direction_ratio=[2,8,8])
>>> l1.intersection(l2)
[Point3D(1, 1, -3)]
>>> p6, p7 = Point3D(0, 5, 2), Point3D(2, 6, 3)
>>> s1 = Segment3D(p6, p7)
>>> l1.intersection(s1)
[]
is_parallel(l2)[源代码]#

两个线性实体是平行的吗?

参数:

l1 :线性度

l2 :线性度

返回:

True :如果l1和l2平行,

:否则。

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> p3, p4 = Point(3, 4), Point(6, 7)
>>> l1, l2 = Line(p1, p2), Line(p3, p4)
>>> Line.is_parallel(l1, l2)
True
>>> p5 = Point(6, 6)
>>> l3 = Line(p3, p5)
>>> Line.is_parallel(l1, l3)
False
>>> from sympy import Point3D, Line3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(3, 4, 5)
>>> p3, p4 = Point3D(2, 1, 1), Point3D(8, 9, 11)
>>> l1, l2 = Line3D(p1, p2), Line3D(p3, p4)
>>> Line3D.is_parallel(l1, l2)
True
>>> p5 = Point3D(6, 6, 6)
>>> l3 = Line3D(p3, p5)
>>> Line3D.is_parallel(l1, l3)
False

参见

coefficients

is_perpendicular(l2)[源代码]#

两个线性实体是否垂直?

参数:

l1 :线性度

l2 :线性度

返回:

True :如果l1和l2垂直,

:否则。

实例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(-1, 1)
>>> l1, l2 = Line(p1, p2), Line(p1, p3)
>>> l1.is_perpendicular(l2)
True
>>> p4 = Point(5, 3)
>>> l3 = Line(p1, p4)
>>> l1.is_perpendicular(l3)
False
>>> from sympy import Point3D, Line3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(-1, 2, 0)
>>> l1, l2 = Line3D(p1, p2), Line3D(p2, p3)
>>> l1.is_perpendicular(l2)
False
>>> p4 = Point3D(5, 3, 7)
>>> l3 = Line3D(p1, p4)
>>> l1.is_perpendicular(l3)
False

参见

coefficients

is_similar(other)[源代码]#

如果self和other包含在同一行中,则返回True。

实例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 1), Point(3, 4), Point(2, 3)
>>> l1 = Line(p1, p2)
>>> l2 = Line(p1, p3)
>>> l1.is_similar(l2)
True
property length#

线的长度。

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(3, 5)
>>> l1 = Line(p1, p2)
>>> l1.length
oo
property p1#

线性实体的第一个定义点。

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l = Line(p1, p2)
>>> l.p1
Point2D(0, 0)
property p2#

线性实体的第二个定义点。

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l = Line(p1, p2)
>>> l.p2
Point2D(5, 3)
parallel_line(p)[源代码]#

创建一条与穿过该点的线性实体平行的新线 \(p\) .

参数:

p :点

返回:

line :行

实例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(2, 3), Point(-2, 2)
>>> l1 = Line(p1, p2)
>>> l2 = l1.parallel_line(p3)
>>> p3 in l2
True
>>> l1.is_parallel(l2)
True
>>> from sympy import Point3D, Line3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(2, 3, 4), Point3D(-2, 2, 0)
>>> l1 = Line3D(p1, p2)
>>> l2 = l1.parallel_line(p3)
>>> p3 in l2
True
>>> l1.is_parallel(l2)
True

参见

is_parallel

perpendicular_line(p)[源代码]#

创建一条垂直于穿过该点的线性实体的新直线 \(p\) .

参数:

p :点

返回:

line :行

实例

>>> from sympy import Point3D, Line3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(2, 3, 4), Point3D(-2, 2, 0)
>>> L = Line3D(p1, p2)
>>> P = L.perpendicular_line(p3); P
Line3D(Point3D(-2, 2, 0), Point3D(4/29, 6/29, 8/29))
>>> L.is_perpendicular(P)
True

In 3D the, the first point used to define the line is the point through which the perpendicular was required to pass; the second point is (arbitrarily) contained in the given line:

>>> P.p2 in L
True
perpendicular_segment(p)[源代码]#

创建垂直线段 \(p\) 到这条线。

The endpoints of the segment are p and the closest point in the line containing self. (If self is not a line, the point might not be in self.)

参数:

p :点

返回:

分段 :段

笔记

返回 \(p\) 本身如果 \(p\) 在这个线性实体上。

实例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, 2)
>>> l1 = Line(p1, p2)
>>> s1 = l1.perpendicular_segment(p3)
>>> l1.is_perpendicular(s1)
True
>>> p3 in s1
True
>>> l1.perpendicular_segment(Point(4, 0))
Segment2D(Point2D(4, 0), Point2D(2, 2))
>>> from sympy import Point3D, Line3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(0, 2, 0)
>>> l1 = Line3D(p1, p2)
>>> s1 = l1.perpendicular_segment(p3)
>>> l1.is_perpendicular(s1)
True
>>> p3 in s1
True
>>> l1.perpendicular_segment(Point3D(4, 0, 0))
Segment3D(Point3D(4, 0, 0), Point3D(4/3, 4/3, 4/3))
property points#

用来定义这个线性实体的两点。

返回:

:点元组

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 11)
>>> l1 = Line(p1, p2)
>>> l1.points
(Point2D(0, 0), Point2D(5, 11))
projection(other)[源代码]#

将点、直线、光线或线段投影到此线性实体上。

参数:

其他 :点或线性(直线、射线、线段)

返回:

投影 :点或线性(直线、射线、线段)

返回类型与参数的类型匹配 other .

加薪:

GeometryError

当方法无法执行投影时。

笔记

投影包括将定义线性实体的两个点投影到一条直线上,然后使用这些投影重构线性实体。通过找到L上最接近P的点,将点P投影到直线L上。该点是L与穿过P的垂直于L的直线的交点。

实例

>>> from sympy import Point, Line, Segment, Rational
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(Rational(1, 2), 0)
>>> l1 = Line(p1, p2)
>>> l1.projection(p3)
Point2D(1/4, 1/4)
>>> p4, p5 = Point(10, 0), Point(12, 1)
>>> s1 = Segment(p4, p5)
>>> l1.projection(s1)
Segment2D(Point2D(5, 5), Point2D(13/2, 13/2))
>>> p1, p2, p3 = Point(0, 0, 1), Point(1, 1, 2), Point(2, 0, 1)
>>> l1 = Line(p1, p2)
>>> l1.projection(p3)
Point3D(2/3, 2/3, 5/3)
>>> p4, p5 = Point(10, 0, 1), Point(12, 1, 3)
>>> s1 = Segment(p4, p5)
>>> l1.projection(s1)
Segment3D(Point3D(10/3, 10/3, 13/3), Point3D(5, 5, 6))
random_point(seed=None)[源代码]#

直线性上的随机点。

返回:

:点

实例

>>> from sympy import Point, Line, Ray, Segment
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> line = Line(p1, p2)
>>> r = line.random_point(seed=42)  # seed value is optional
>>> r.n(3)
Point2D(-0.72, -0.432)
>>> r in line
True
>>> Ray(p1, p2).random_point(seed=42).n(3)
Point2D(0.72, 0.432)
>>> Segment(p1, p2).random_point(seed=42).n(3)
Point2D(3.2, 1.92)
smallest_angle_between(l2)[源代码]#

返回包含线性实体的直线相交处形成的最小角度。

参数:

l1 :线性度

l2 :线性度

返回:

:以弧度表示的角度

实例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(0, 4), Point(2, -2)
>>> l1, l2 = Line(p1, p2), Line(p1, p3)
>>> l1.smallest_angle_between(l2)
pi/4
class sympy.geometry.line.Line(*args, **kwargs)[源代码]#

空间中的无限线。

二维直线由两个不同的点、点和坡度或方程声明。三维线可以用点和方向比来定义。

参数:

p1 :点

p2 :点

slope : SymPy expression

direction_ratio :列表

方程式 :直线方程

笔记

\(Line\) 将自动子类化为 \(Line2D\)\(Line3D\) 基于 \(p1\) . 这个 \(slope\) 论点只与 \(Line2D\) 以及 \(direction_ratio\) 论点只与 \(Line3D\) .

The order of the points will define the direction of the line which is used when calculating the angle between lines.

实例

>>> from sympy import Line, Segment, Point, Eq
>>> from sympy.abc import x, y, a, b
>>> L = Line(Point(2,3), Point(3,5))
>>> L
Line2D(Point2D(2, 3), Point2D(3, 5))
>>> L.points
(Point2D(2, 3), Point2D(3, 5))
>>> L.equation()
-2*x + y + 1
>>> L.coefficients
(-2, 1, 1)

用关键字实例化 slope

>>> Line(Point(0, 0), slope=0)
Line2D(Point2D(0, 0), Point2D(1, 0))

用另一个线性对象实例化

>>> s = Segment((0, 0), (0, 1))
>>> Line(s).equation()
x

与for中的等式相对应的线 \(ax + by + c = 0\) ,可以输入:

>>> Line(3*x + y + 18)
Line2D(Point2D(0, -18), Point2D(1, -21))

如果 \(x\)\(y\) 具有不同的名称,则也可以将它们指定为字符串(以匹配名称)或符号:

>>> Line(Eq(3*a + b, -18), x='a', y=b)
Line2D(Point2D(0, -18), Point2D(1, -21))
contains(other)[源代码]#

如果返回真 \(other\) 在这条线上,否则为False。

实例

>>> from sympy import Line,Point
>>> p1, p2 = Point(0, 1), Point(3, 4)
>>> l = Line(p1, p2)
>>> l.contains(p1)
True
>>> l.contains((0, 1))
True
>>> l.contains((0, 0))
False
>>> a = (0, 0, 0)
>>> b = (1, 1, 1)
>>> c = (2, 2, 2)
>>> l1 = Line(a, b)
>>> l2 = Line(b, a)
>>> l1 == l2
False
>>> l1 in l2
True
distance(other)[源代码]#

查找直线和点之间的最短距离。

加薪:

NotImplementedError is raised if `other` is not a Point

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> s = Line(p1, p2)
>>> s.distance(Point(-1, 1))
sqrt(2)
>>> s.distance((-1, 2))
3*sqrt(2)/2
>>> p1, p2 = Point(0, 0, 0), Point(1, 1, 1)
>>> s = Line(p1, p2)
>>> s.distance(Point(-1, 1, 1))
2*sqrt(6)/3
>>> s.distance((-1, 1, 1))
2*sqrt(6)/3
equals(other)[源代码]#

如果self和other是相同的数学实体,则返回True

plot_interval(parameter='t')[源代码]#

线的默认几何绘图的绘图间隔。给出将生成+/-5个单位长的直线的值(其中单位是定义直线的两点之间的距离)。

参数:

参数 :str,可选

默认值为“t”。

返回:

plot_interval :list(绘图间隔)

[parameter, lower_bound, upper_bound]

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.plot_interval()
[t, -5, 5]
class sympy.geometry.line.Ray(p1, p2=None, **kwargs)[源代码]#

射线是空间中具有源点和方向的半直线。

参数:

p1 :点

射线的源头

p2 :点或弧度值

该点决定光线传播的方向。如果以角度表示,则以弧度表示,正方向为逆时针。

笔记

\(Ray\) 将自动子类化为 \(Ray2D\)\(Ray3D\) 基于 \(p1\) .

实例

>>> from sympy import Ray, Point, pi
>>> r = Ray(Point(2, 3), Point(3, 5))
>>> r
Ray2D(Point2D(2, 3), Point2D(3, 5))
>>> r.points
(Point2D(2, 3), Point2D(3, 5))
>>> r.source
Point2D(2, 3)
>>> r.xdirection
oo
>>> r.ydirection
oo
>>> r.slope
2
>>> Ray(Point(0, 0), angle=pi/4).slope
1

属性

来源

contains(other)[源代码]#

射线中是否包含其他几何量?

实例

>>> from sympy import Ray,Point,Segment
>>> p1, p2 = Point(0, 0), Point(4, 4)
>>> r = Ray(p1, p2)
>>> r.contains(p1)
True
>>> r.contains((1, 1))
True
>>> r.contains((1, 3))
False
>>> s = Segment((1, 1), (2, 2))
>>> r.contains(s)
True
>>> s = Segment((1, 2), (2, 5))
>>> r.contains(s)
False
>>> r1 = Ray((2, 2), (3, 3))
>>> r.contains(r1)
True
>>> r1 = Ray((2, 2), (3, 5))
>>> r.contains(r1)
False
distance(other)[源代码]#

查找光线与点之间的最短距离。

加薪:

NotImplementedError is raised if `other` is not a Point

实例

>>> from sympy import Point, Ray
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> s = Ray(p1, p2)
>>> s.distance(Point(-1, -1))
sqrt(2)
>>> s.distance((-1, 2))
3*sqrt(2)/2
>>> p1, p2 = Point(0, 0, 0), Point(1, 1, 2)
>>> s = Ray(p1, p2)
>>> s
Ray3D(Point3D(0, 0, 0), Point3D(1, 1, 2))
>>> s.distance(Point(-1, -1, 2))
4*sqrt(3)/3
>>> s.distance((-1, -1, 2))
4*sqrt(3)/3
equals(other)[源代码]#

如果self和other是相同的数学实体,则返回True

plot_interval(parameter='t')[源代码]#

射线的默认几何绘图的绘图间隔。给出将生成10个单位长的光线的值(其中,单位是定义光线的两点之间的距离)。

参数:

参数 :str,可选

默认值为“t”。

返回:

plot_interval :列表

[parameter, lower_bound, upper_bound]

实例

>>> from sympy import Ray, pi
>>> r = Ray((0, 0), angle=pi/4)
>>> r.plot_interval()
[t, 0, 10]
property source#

光线发出的点。

实例

>>> from sympy import Point, Ray
>>> p1, p2 = Point(0, 0), Point(4, 1)
>>> r1 = Ray(p1, p2)
>>> r1.source
Point2D(0, 0)
>>> p1, p2 = Point(0, 0, 0), Point(4, 1, 5)
>>> r1 = Ray(p2, p1)
>>> r1.source
Point3D(4, 1, 5)
class sympy.geometry.line.Segment(p1, p2, **kwargs)[源代码]#

空间中的线段。

参数:

p1 :点

p2 :点

笔记

如果使用二维或三维点定义 \(Segment\) ,它将自动子类化为 \(Segment2D\)\(Segment3D\) .

实例

>>> from sympy import Point, Segment
>>> Segment((1, 0), (1, 1)) # tuples are interpreted as pts
Segment2D(Point2D(1, 0), Point2D(1, 1))
>>> s = Segment(Point(4, 3), Point(1, 1))
>>> s.points
(Point2D(4, 3), Point2D(1, 1))
>>> s.slope
2/3
>>> s.length
sqrt(13)
>>> s.midpoint
Point2D(5/2, 2)
>>> Segment((1, 0, 0), (1, 1, 1)) # tuples are interpreted as pts
Segment3D(Point3D(1, 0, 0), Point3D(1, 1, 1))
>>> s = Segment(Point(4, 3, 9), Point(1, 1, 7)); s
Segment3D(Point3D(4, 3, 9), Point3D(1, 1, 7))
>>> s.points
(Point3D(4, 3, 9), Point3D(1, 1, 7))
>>> s.length
sqrt(17)
>>> s.midpoint
Point3D(5/2, 2, 8)

属性

长度

(number or SymPy expression)

中点

(点)

contains(other)[源代码]#

此段中是否包含其他几何体?

实例

>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 1), Point(3, 4)
>>> s = Segment(p1, p2)
>>> s2 = Segment(p2, p1)
>>> s.contains(s2)
True
>>> from sympy import Point3D, Segment3D
>>> p1, p2 = Point3D(0, 1, 1), Point3D(3, 4, 5)
>>> s = Segment3D(p1, p2)
>>> s2 = Segment3D(p2, p1)
>>> s.contains(s2)
True
>>> s.contains((p1 + p2)/2)
True
distance(other)[源代码]#

查找线段和点之间的最短距离。

加薪:

NotImplementedError is raised if `other` is not a Point

实例

>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 1), Point(3, 4)
>>> s = Segment(p1, p2)
>>> s.distance(Point(10, 15))
sqrt(170)
>>> s.distance((0, 12))
sqrt(73)
>>> from sympy import Point3D, Segment3D
>>> p1, p2 = Point3D(0, 0, 3), Point3D(1, 1, 4)
>>> s = Segment3D(p1, p2)
>>> s.distance(Point3D(10, 15, 12))
sqrt(341)
>>> s.distance((10, 15, 12))
sqrt(341)
equals(other)[源代码]#

如果self和other是相同的数学实体,则返回True

property length#

线段的长度。

实例

>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 0), Point(4, 3)
>>> s1 = Segment(p1, p2)
>>> s1.length
5
>>> from sympy import Point3D, Segment3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(4, 3, 3)
>>> s1 = Segment3D(p1, p2)
>>> s1.length
sqrt(34)
property midpoint#

线段的中点。

实例

>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 0), Point(4, 3)
>>> s1 = Segment(p1, p2)
>>> s1.midpoint
Point2D(2, 3/2)
>>> from sympy import Point3D, Segment3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(4, 3, 3)
>>> s1 = Segment3D(p1, p2)
>>> s1.midpoint
Point3D(2, 3/2, 3/2)
perpendicular_bisector(p=None)[源代码]#

此线段的垂直平分线。

如果没有指定点或指定的点不在平分线上,则平分线将作为直线返回。否则,将返回一个线段,该线段连接指定的点以及平分线与线段的交点。

参数:

p :点

返回:

平分线 :直线或线段

实例

>>> from sympy import Point, Segment
>>> p1, p2, p3 = Point(0, 0), Point(6, 6), Point(5, 1)
>>> s1 = Segment(p1, p2)
>>> s1.perpendicular_bisector()
Line2D(Point2D(3, 3), Point2D(-3, 9))
>>> s1.perpendicular_bisector(p3)
Segment2D(Point2D(5, 1), Point2D(3, 3))
plot_interval(parameter='t')[源代码]#

段的默认几何绘图的绘图间隔给出了将在绘图中生成完整线段的值。

参数:

参数 :str,可选

默认值为“t”。

返回:

plot_interval :列表

[parameter, lower_bound, upper_bound]

实例

>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> s1 = Segment(p1, p2)
>>> s1.plot_interval()
[t, 0, 1]
class sympy.geometry.line.LinearEntity2D(p1, p2=None, **kwargs)[源代码]#

二维欧几里德空间中所有线性实体(直线、射线和线段)的基类。

笔记

这是一个抽象类,不打算被实例化。

属性

第一页

第2页

系数

斜坡

property bounds#

xmax,在矩形中表示xmax,表示图形中的xmax。

perpendicular_line(p)[源代码]#

创建一条垂直于穿过该点的线性实体的新直线 \(p\) .

参数:

p :点

返回:

line :行

实例

>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(2, 3), Point(-2, 2)
>>> L = Line(p1, p2)
>>> P = L.perpendicular_line(p3); P
Line2D(Point2D(-2, 2), Point2D(-5, 4))
>>> L.is_perpendicular(P)
True

In 2D, the first point of the perpendicular line is the point through which was required to pass; the second point is arbitrarily chosen. To get a line that explicitly uses a point in the line, create a line from the perpendicular segment from the line to the point:

>>> Line(L.perpendicular_segment(p3))
Line2D(Point2D(-2, 2), Point2D(4/13, 6/13))
property slope#

此线性实体的坡度,如果垂直,则为无穷大。

返回:

slope : number or SymPy expression

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(3, 5)
>>> l1 = Line(p1, p2)
>>> l1.slope
5/3
>>> p3 = Point(0, 4)
>>> l2 = Line(p1, p3)
>>> l2.slope
oo

参见

coefficients

class sympy.geometry.line.Line2D(p1, pt=None, slope=None, **kwargs)[源代码]#

二维空间中的无限线。

使用两个不同的点或使用关键字定义的点和坡度来声明直线 \(slope\) .

参数:

p1 :点

pt :点

slope : SymPy expression

实例

>>> from sympy import Line, Segment, Point
>>> L = Line(Point(2,3), Point(3,5))
>>> L
Line2D(Point2D(2, 3), Point2D(3, 5))
>>> L.points
(Point2D(2, 3), Point2D(3, 5))
>>> L.equation()
-2*x + y + 1
>>> L.coefficients
(-2, 1, 1)

用关键字实例化 slope

>>> Line(Point(0, 0), slope=0)
Line2D(Point2D(0, 0), Point2D(1, 0))

用另一个线性对象实例化

>>> s = Segment((0, 0), (0, 1))
>>> Line(s).equation()
x
property coefficients#

系数 (\(a\)\(b\)\(c\)\(ax + by + c = 0\) .

实例

>>> from sympy import Point, Line
>>> from sympy.abc import x, y
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l = Line(p1, p2)
>>> l.coefficients
(-3, 5, 0)
>>> p3 = Point(x, y)
>>> l2 = Line(p1, p3)
>>> l2.coefficients
(-y, x, 0)
equation(x='x', y='y')[源代码]#

直线方程:ax+by+c。

参数:

x :str,可选

用于x轴的名称,默认值为“x”。

y :str,可选

用于y轴的名称,默认值为“y”。

返回:

方程式 :SymPy表达式

实例

>>> from sympy import Point, Line
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.equation()
-3*x + 4*y + 3
class sympy.geometry.line.Ray2D(p1, pt=None, angle=None, **kwargs)[源代码]#

射线是空间中具有源点和方向的半直线。

参数:

p1 :点

射线的源头

p2 :点或弧度值

该点决定光线传播的方向。如果以角度表示,则以弧度表示,正方向为逆时针。

实例

>>> from sympy import Point, pi, Ray
>>> r = Ray(Point(2, 3), Point(3, 5))
>>> r
Ray2D(Point2D(2, 3), Point2D(3, 5))
>>> r.points
(Point2D(2, 3), Point2D(3, 5))
>>> r.source
Point2D(2, 3)
>>> r.xdirection
oo
>>> r.ydirection
oo
>>> r.slope
2
>>> Ray(Point(0, 0), angle=pi/4).slope
1

属性

来源

X方向

Y方向

closing_angle(r2)[源代码]#

返回r2必须旋转的角度,使其朝向与r1相同的方向。

参数:

r1 :Ray2D

r2 :Ray2D

返回:

:以弧度表示的角度(逆时针角度为正)

实例

>>> from sympy import Ray, pi
>>> r1 = Ray((0, 0), (1, 0))
>>> r2 = r1.rotate(-pi/2)
>>> angle = r1.closing_angle(r2); angle
pi/2
>>> r2.rotate(angle).direction.unit == r1.direction.unit
True
>>> r2.closing_angle(r1)
-pi/2
property xdirection#

射线的x方向。

如果光线指向正x方向,则为正无穷大;如果光线指向负x方向,则为负无穷大;如果光线垂直,则为0。

实例

>>> from sympy import Point, Ray
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, -1)
>>> r1, r2 = Ray(p1, p2), Ray(p1, p3)
>>> r1.xdirection
oo
>>> r2.xdirection
0

参见

ydirection

property ydirection#

光线的y方向。

如果光线指向正y方向,则为正无穷大;如果光线指向负y方向,则为负无穷大;如果光线水平,则为0。

实例

>>> from sympy import Point, Ray
>>> p1, p2, p3 = Point(0, 0), Point(-1, -1), Point(-1, 0)
>>> r1, r2 = Ray(p1, p2), Ray(p1, p3)
>>> r1.ydirection
-oo
>>> r2.ydirection
0

参见

xdirection

class sympy.geometry.line.Segment2D(p1, p2, **kwargs)[源代码]#

二维空间中的线段。

参数:

p1 :点

p2 :点

实例

>>> from sympy import Point, Segment
>>> Segment((1, 0), (1, 1)) # tuples are interpreted as pts
Segment2D(Point2D(1, 0), Point2D(1, 1))
>>> s = Segment(Point(4, 3), Point(1, 1)); s
Segment2D(Point2D(4, 3), Point2D(1, 1))
>>> s.points
(Point2D(4, 3), Point2D(1, 1))
>>> s.slope
2/3
>>> s.length
sqrt(13)
>>> s.midpoint
Point2D(5/2, 2)

属性

长度

(number or SymPy expression)

中点

(点)

class sympy.geometry.line.LinearEntity3D(p1, p2, **kwargs)[源代码]#

三维欧几里德空间中所有线性实体(直线、射线和线段)的基类。

笔记

这是一个基类,不打算被实例化。

属性

第一页

第2页

direction_ratio

direction_cosine

property direction_cosine#

三维中给定直线的标准化方向比。

实例

>>> from sympy import Point3D, Line3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(5, 3, 1)
>>> l = Line3D(p1, p2)
>>> l.direction_cosine
[sqrt(35)/7, 3*sqrt(35)/35, sqrt(35)/35]
>>> sum(i**2 for i in _)
1
property direction_ratio#

三维中给定直线的方向比。

实例

>>> from sympy import Point3D, Line3D
>>> p1, p2 = Point3D(0, 0, 0), Point3D(5, 3, 1)
>>> l = Line3D(p1, p2)
>>> l.direction_ratio
[5, 3, 1]
class sympy.geometry.line.Line3D(p1, pt=None, direction_ratio=(), **kwargs)[源代码]#

空间中的无限三维线。

用两个不同的点或使用关键字定义的点和方向比率声明一条直线 \(direction_ratio\) .

参数:

p1 :点3D

pt :点3D

direction_ratio :列表

实例

>>> from sympy import Line3D, Point3D
>>> L = Line3D(Point3D(2, 3, 4), Point3D(3, 5, 1))
>>> L
Line3D(Point3D(2, 3, 4), Point3D(3, 5, 1))
>>> L.points
(Point3D(2, 3, 4), Point3D(3, 5, 1))
distance(other)[源代码]#

Finds the shortest distance between a line and another object.

参数:

Point3D, Line3D, Plane, tuple, list

返回:

距离

笔记

This method accepts only 3D entities as it's parameter

Tuples and lists are converted to Point3D and therefore must be of length 3, 2 or 1.

NotImplementedError is raised if \(other\) is not an instance of one of the specified classes: Point3D, Line3D, or Plane.

实例

>>> from sympy.geometry import Line3D
>>> l1 = Line3D((0, 0, 0), (0, 0, 1))
>>> l2 = Line3D((0, 1, 0), (1, 1, 1))
>>> l1.distance(l2)
1

计算的距离也可以是符号:

>>> from sympy.abc import x, y
>>> l1 = Line3D((0, 0, 0), (0, 0, 1))
>>> l2 = Line3D((0, x, 0), (y, x, 1))
>>> l1.distance(l2)
Abs(x*y)/Abs(sqrt(y**2))
equation(x='x', y='y', z='z')[源代码]#

返回在三维中定义直线的表达式。

参数:

x :str,可选

用于x轴的名称,默认值为“x”。

y :str,可选

用于y轴的名称,默认值为“y”。

z :str,可选

用于z轴的名称,默认值为“z”。

返回:

方程式 :联立方程组

实例

>>> from sympy import Point3D, Line3D, solve
>>> from sympy.abc import x, y, z
>>> p1, p2 = Point3D(1, 0, 0), Point3D(5, 3, 0)
>>> l1 = Line3D(p1, p2)
>>> eq = l1.equation(x, y, z); eq
(-3*x + 4*y + 3, z)
>>> solve(eq.subs(z, 0), (x, y, z))
{x: 4*y/3 + 1}
class sympy.geometry.line.Ray3D(p1, pt=None, direction_ratio=(), **kwargs)[源代码]#

射线是空间中具有源点和方向的半直线。

参数:

p1 :点3D

射线的源头

p2 :点或方向向量

direction_ratio: Determines the direction in which the Ray propagates.

实例

>>> from sympy import Point3D, Ray3D
>>> r = Ray3D(Point3D(2, 3, 4), Point3D(3, 5, 0))
>>> r
Ray3D(Point3D(2, 3, 4), Point3D(3, 5, 0))
>>> r.points
(Point3D(2, 3, 4), Point3D(3, 5, 0))
>>> r.source
Point3D(2, 3, 4)
>>> r.xdirection
oo
>>> r.ydirection
oo
>>> r.direction_ratio
[1, 2, -4]

属性

来源

X方向

Y方向

Z方向

property xdirection#

射线的x方向。

如果光线指向正x方向,则为正无穷大;如果光线指向负x方向,则为负无穷大;如果光线垂直,则为0。

实例

>>> from sympy import Point3D, Ray3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(0, -1, 0)
>>> r1, r2 = Ray3D(p1, p2), Ray3D(p1, p3)
>>> r1.xdirection
oo
>>> r2.xdirection
0

参见

ydirection

property ydirection#

光线的y方向。

如果光线指向正y方向,则为正无穷大;如果光线指向负y方向,则为负无穷大;如果光线水平,则为0。

实例

>>> from sympy import Point3D, Ray3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(-1, -1, -1), Point3D(-1, 0, 0)
>>> r1, r2 = Ray3D(p1, p2), Ray3D(p1, p3)
>>> r1.ydirection
-oo
>>> r2.ydirection
0

参见

xdirection

property zdirection#

光线的z方向。

如果光线指向正z方向,则为正无穷大;如果光线指向负z方向,则为负无穷大;如果光线水平,则为0。

实例

>>> from sympy import Point3D, Ray3D
>>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(-1, -1, -1), Point3D(-1, 0, 0)
>>> r1, r2 = Ray3D(p1, p2), Ray3D(p1, p3)
>>> r1.ydirection
-oo
>>> r2.ydirection
0
>>> r2.zdirection
0

参见

xdirection

class sympy.geometry.line.Segment3D(p1, p2, **kwargs)[源代码]#

三维空间中的线段。

参数:

p1 :点3D

p2 :点3D

实例

>>> from sympy import Point3D, Segment3D
>>> Segment3D((1, 0, 0), (1, 1, 1)) # tuples are interpreted as pts
Segment3D(Point3D(1, 0, 0), Point3D(1, 1, 1))
>>> s = Segment3D(Point3D(4, 3, 9), Point3D(1, 1, 7)); s
Segment3D(Point3D(4, 3, 9), Point3D(1, 1, 7))
>>> s.points
(Point3D(4, 3, 9), Point3D(1, 1, 7))
>>> s.length
sqrt(17)
>>> s.midpoint
Point3D(5/2, 2, 8)

属性

长度

(number or SymPy expression)

中点

(点3d)