Python | Sympy Line.perpendicular_segment() method
In Sympy, the function
closest point in the line containing self.
perpendicular_segment() is used to create a perpendicular line segment from a given point to the given line.The endpoints of the segment are p and theclosest point in the line containing self.
Syntax: Line.perpendicular_segment(p) Parameters: p: Point Returns: segment: Segment
Example #1:
# import sympy and Point, Linefrom sympy import Point, Line p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, 2)l1 = Line(p1, p2) # using perpendicular_segment() methodperpendicularSegment = l1.perpendicular_segment(p3) print(perpendicularSegment) |
Output:
Segment2D(Point2D(0, 2), Point2D(1, 1))
Example #2:
# import sympy and Point3D, Line3Dfrom 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() methods1 = l1.perpendicular_segment(p3) perpendicularSegment = l1.perpendicular_segment(p3) print(perpendicularSegment) |
Output:
Segment3D(Point3D(0, 2, 0), Point3D(2/3, 2/3, 2/3))
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course


