Created
December 30, 2024 08:20
-
-
Save uwezi/9d56dc72ff68a3e84e57c763c4c8ec81 to your computer and use it in GitHub Desktop.
[Brace3D II] A flexible brace object for 3D. #manim #3D #brace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from manim import * | |
class Brace3D(Brace): | |
def __init__(self, line, rotation=0, **kwargs): | |
flatline = Line(ORIGIN, line.get_length()*RIGHT) | |
super().__init__(flatline, direction=np.array([0., -1., 0.]), **kwargs) | |
dline = line.get_end()-line.get_start() | |
self.rotate(angle=rotation, about_point=flatline.get_start(),axis=RIGHT) | |
self.rotate(-np.asin(dline[2]/np.linalg.norm(dline)), about_point=flatline.get_start(), axis=UP) | |
self.rotate(np.atan2(dline[1],dline[0]), about_point=flatline.get_start(), axis=OUT) | |
self.shift(line.get_start()-flatline.get_start()) | |
class brace3dtest(ThreeDScene): | |
def construct(self): | |
ax = ThreeDAxes( | |
x_range=[0,20,5], | |
y_range=[0,20,5], | |
z_range=[0,20,5], | |
x_length=5, | |
y_length=5, | |
z_length=5, | |
).add_coordinates() | |
ax.shift(-ax.c2p(5,5,5)) | |
self.set_camera_orientation(focal_distance=1000) | |
self.set_camera_orientation(phi=70 * DEGREES, theta=-70 * DEGREES) | |
self.add(ax) | |
dot = Dot3D(ax.c2p(15,10,10)) | |
self.add(dot) | |
newline = Line(ax.c2p(0,0,0), dot.get_center()) | |
self.add(newline) | |
ang = ValueTracker(0) | |
brace = always_redraw(lambda: | |
Brace3D(newline,rotation=ang.get_value(),buff=0.2) | |
) | |
self.add(brace) | |
self.wait() | |
self.play(ang.animate.set_value(2*PI),rate_func=rate_functions.linear,run_time=3) | |
self.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment