The class OrthogonalConnection
creates a polyline that goes from p1 to p2, composed only by horizontal and vertical segments. The shape of the line is controlled by the path parameter.
There are two ways to use this class:
-
p1
andp2
are the start and end points of the line, and path is a string with the characters "-" and "|" indicating the horizontal and vertical segments of the line.For example
"-|-"
will start with a horizontal segment, that will go until the x coordinate intermediate betweenp1
andp2
, then a vertical segment up to the y coordinate ofp2
, and finally a horizontal segment top2
.If several "-" or "|" are used, each one represent a fraction of the total distance to be covered. For example
"--|-"
will make the vertical segment to be a 2/3 in horizontal distance from p1 to p2, because "--|-" contains 3 "-" segments. -
p2
is omitted and path is a list of tuples[(p, s), ... ]
wherep
is a point ands
is a string with the characters "-" and "|" as in the previous case. In this case a line is created fromp1
top
, following the path ins
, and the procedure is repeated for the next tuple in the list, until the list is exhausted. The final point of the polyline is the lastp
in the list.
The class returns a Line object that contains several segments. You can add a tip to it (see example), and use it as any other manim object.
In addition, that line provides a method .midpoint()
which returns the point at proportion 0.5 of the whole path, and accepts an
optional integer parameter segment
. If segment
is provided, it identifies one of the segments of the polyline (there is one
segment for each "-" or "|" in the path), and returns the midpoint of that segment. This is useful to put labels (see example).
The image resulting from exmaple.py
is the following: