(self, p)
return Segment(p, p2)
Create a perpendicular line segment from `p` to this line.

        The enpoints 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.)

        Parameters
        ==========

        p : Point

        Returns
        =======

        segment : Segment

        Notes
        =====

        Returns `p` itself if `p` is on this linear entity.

        See Also
        ========

        perpendicular_line

        Examples
        ========

        >>> 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))
        Segment(Point(2, 2), Point(4, 0))
Create a perpendicular line segment from `p` to this line.
Create a perpendicular line segment from p to this line .
def perpendicular_segment(self, p):
        """Create a perpendicular line segment from `p` to this line.

        The enpoints 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.)

        Parameters
        ==========

        p : Point

        Returns
        =======

        segment : Segment

        Notes
        =====

        Returns `p` itself if `p` is on this linear entity.

        See Also
        ========

        perpendicular_line

        Examples
        ========

        >>> 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))
        Segment(Point(2, 2), Point(4, 0))

        """
        if p in self:
            return p
        a, b, c = self.coefficients
        if a == 0:  # horizontal
            p2 = Point(p.x, self.p1.y)
        elif b == 0:  # vertical
            p2 = Point(self.p1.x, p.y)
        else:
            # ax + by + c = 0
            y = (-c - a*p.x)/b
            m = self.slope
            d2 = 1 + m**2
            H = p.y - y
            dx = m*H/d2
            dy = m*dx
            p2 = (p.x + dx, y + dy)
        return Segment(p, p2)
def perpendicular_segment ( self , p ) : if p in self : return p a , b , c = self . coefficients if a == 0 : # horizontal p2 = Point ( p . x , self . p1 . y ) elif b == 0 : # vertical p2 = Point ( self . p1 . x , p . y ) else : # ax + by + c = 0 y = ( - c - a * p . x ) / b m = self . slope d2 = 1 + m ** 2 H = p . y - y dx = m * H / d2 dy = m * dx p2 = ( p . x + dx , y + dy ) return Segment ( p , p2 )