-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Description of bug / unexpected behavior
I wanted to use a tikz-equivalent of rounded corners
in manim to simply write the equivalent of the tikz code:
\draw[rounded corners,-Stealth] (0,0) -| (1,-1);
to obtain something like

but it turned out that the equivalent manim code is a huge mess:
import manim.mobject.geometry.tips as tips
class ellbowarrow(Scene):
def construct(self):
def add_tip(
line,
shorten=True,
tip_shape: type[tips.ArrowTip] | None = None,
tip_length: float | None = None,
tip_width: float | None = None,
):
tip = line.get_unpositioned_tip(
tip_length=tip_length,
tip_shape = tip_shape,
tip_width = tip_width,
)
tipangle = Line(tip.base, tip.tip_point).get_angle()
angle = Line(line.point_from_proportion(0.999),line.point_from_proportion(1.0)).get_angle()
tip.rotate(angle-tipangle,about_point=tip.base)
tip.shift(line.get_end()-tip.tip_point)
if shorten==True:
points = line.get_all_points()
points[-1]=tip.base
line.set_points(points)
line.add(tip)
return line
Line.add_tip = add_tip
grid = NumberPlane().add_coordinates()
self.add(grid)
p1 = Dot([-4,2,0],color=RED)
p2 = Dot([4,-1,0],color=BLUE)
c1 = Dot(p1.get_center()*UP+p2.get_center()*RIGHT-0.5*RIGHT, color=YELLOW)
c2 = Dot(p2.get_center()*RIGHT+p1.get_center()*UP-0.5*UP, color=TEAL)
self.add(p1,p2,c1,c2)
line1 = Line().set_points_as_corners(
[p1.get_center(), p1.get_center()*UP+p2.get_center()*RIGHT-0.5*RIGHT]
)
line1.add_cubic_bezier_curve(
p1.get_center()*UP+p2.get_center()*RIGHT-0.5*RIGHT,
p2.get_center()*RIGHT+p1.get_center()*UP,
p2.get_center()*RIGHT+p1.get_center()*UP,
p2.get_center()*RIGHT+p1.get_center()*UP-.5*UP
)
line1.add_line_to(p2.get_center())
line1.add_tip(shorten=False, tip_length=0.5)
self.play(Create(line1))
self.wait()
(thanks uwezi for the help)
Would you consider adding a way to round corners of arbitrary lines to make this kind of code significantly simpler?
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
🆕 New