|
from manim import * |
|
import manim.mobject.geometry.tips as tips |
|
|
|
# https://discord.com/channels/581738731934056449/1370706466541011055/1370728872416514141 |
|
|
|
class reasonablyTipped(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 |
|
|
|
npl = NumberPlane().add_coordinates() |
|
self.add(npl) |
|
|
|
line1 = Line([5,3,0],[2,2,0]).add_tip(tip_length=0.2) |
|
line2 = Line([5,3,0],[5,0,0]).add_tip(tip_length=0.5) |
|
line3 = Line().add_points_as_corners( |
|
[[6,-1,0],[5,-2,0],[4,-1,0],[3,-2,0],[2,-1,0]] |
|
).add_tip_nodist(tip_length=0.5) |
|
self.add(line1,line2,line3) |
|
|
|
line1a = Line([-5,3,0],[-2,2,0]).add_tip(shorten=False, tip_length=0.2) |
|
line2a = Line([-5,3,0],[-5,0,0]).add_tip(shorten=False, tip_length=0.5) |
|
line3a = Line().add_points_as_corners( |
|
[[-6,-1,0],[-5,-2,0],[-4,-1,0],[-3,-2,0],[-2,-1,0]] |
|
).add_tip_nodist(shorten=False, tip_length=0.5) |
|
self.add(line1a,line2a,line3a) |