'The perpendicular bisector of this segment.
If no point is specified or the point specified is not on the
bisector then the bisector is returned as a Line. Otherwise a
Segment is returned that joins the point specified and the
intersection of the bisector and the segment.
Parameters
p : Point
Returns
bisector : Line or Segment
See Also
LinearEntity.perpendicular_segment
Examples
>>> 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(3, 3), Point2D(5, 1))'

def perpendicular_bisector(self, p=None):

    l = self.perpendicular_line(self.midpoint)
    if (p is not None):
        p2 = Point(p, dim=self.ambient_dimension)
        if (p2 in l):
            return Segment(self.midpoint, p2)
    return l
