Python| Sympy Line.perpendicular_segment() 方法
在 Sympy 中,函数vertical_segment
包含 self 的行中的最近点。
perpendicular_segment()
用于创建从给定点到给定线的垂直线段。线段的端点是 p 和包含 self 的行中的最近点。
Syntax: Line.perpendicular_segment(p)
Parameters:
p: Point
Returns:
segment: Segment
示例 #1:
# import sympy and Point, Line
from sympy import Point, Line
p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, 2)
l1 = Line(p1, p2)
# using perpendicular_segment() method
perpendicularSegment = l1.perpendicular_segment(p3)
print(perpendicularSegment)
输出:
Segment2D(Point2D(0, 2), Point2D(1, 1))
示例 #2:
# import sympy and Point3D, Line3D
from sympy import Point3D, Line3D
p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(0, 2, 0)
ll1 = Line3D(p1, p2)
# using perpendicular_segment() method
s1 = l1.perpendicular_segment(p3)
perpendicularSegment = l1.perpendicular_segment(p3)
print(perpendicularSegment)
输出:
Segment3D(Point3D(0, 2, 0), Point3D(2/3, 2/3, 2/3))