|
32 | 32 | from manim.mobject.mobject import *
|
33 | 33 | from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
|
34 | 34 | from manim.mobject.opengl.opengl_mobject import OpenGLMobject
|
35 |
| -from manim.mobject.types.vectorized_mobject import VGroup, VMobject |
| 35 | +from manim.mobject.types.vectorized_mobject import VectorizedPoint, VGroup, VMobject |
36 | 36 | from manim.utils.color import (
|
37 | 37 | ManimColor,
|
38 | 38 | ParsableManimColor,
|
@@ -616,17 +616,18 @@ def __init__(
|
616 | 616 | **kwargs,
|
617 | 617 | )
|
618 | 618 | # used for rotations
|
| 619 | + self.new_height = height |
619 | 620 | self._current_theta = 0
|
620 | 621 | self._current_phi = 0
|
621 |
| - |
| 622 | + self.base_circle = Circle( |
| 623 | + radius=base_radius, |
| 624 | + color=self.fill_color, |
| 625 | + fill_opacity=self.fill_opacity, |
| 626 | + stroke_width=0, |
| 627 | + ) |
| 628 | + self.base_circle.shift(height * IN) |
| 629 | + self._set_start_and_end_attributes(direction) |
622 | 630 | if show_base:
|
623 |
| - self.base_circle = Circle( |
624 |
| - radius=base_radius, |
625 |
| - color=self.fill_color, |
626 |
| - fill_opacity=self.fill_opacity, |
627 |
| - stroke_width=0, |
628 |
| - ) |
629 |
| - self.base_circle.shift(height * IN) |
630 | 631 | self.add(self.base_circle)
|
631 | 632 |
|
632 | 633 | self._rotate_to_direction()
|
@@ -656,6 +657,12 @@ def func(self, u: float, v: float) -> np.ndarray:
|
656 | 657 | ],
|
657 | 658 | )
|
658 | 659 |
|
| 660 | + def get_start(self) -> np.ndarray: |
| 661 | + return self.start_point.get_center() |
| 662 | + |
| 663 | + def get_end(self) -> np.ndarray: |
| 664 | + return self.end_point.get_center() |
| 665 | + |
659 | 666 | def _rotate_to_direction(self) -> None:
|
660 | 667 | x, y, z = self.direction
|
661 | 668 |
|
@@ -710,6 +717,15 @@ def get_direction(self) -> np.ndarray:
|
710 | 717 | """
|
711 | 718 | return self.direction
|
712 | 719 |
|
| 720 | + def _set_start_and_end_attributes(self, direction): |
| 721 | + normalized_direction = direction * np.linalg.norm(direction) |
| 722 | + |
| 723 | + start = self.base_circle.get_center() |
| 724 | + end = start + normalized_direction * self.new_height |
| 725 | + self.start_point = VectorizedPoint(start) |
| 726 | + self.end_point = VectorizedPoint(end) |
| 727 | + self.add(self.start_point, self.end_point) |
| 728 | + |
713 | 729 |
|
714 | 730 | class Cylinder(Surface):
|
715 | 731 | """A cylinder, defined by its height, radius and direction,
|
@@ -1150,14 +1166,20 @@ def __init__(
|
1150 | 1166 | self.end - height * self.direction,
|
1151 | 1167 | **kwargs,
|
1152 | 1168 | )
|
1153 |
| - |
1154 | 1169 | self.cone = Cone(
|
1155 |
| - direction=self.direction, base_radius=base_radius, height=height, **kwargs |
| 1170 | + direction=self.direction, |
| 1171 | + base_radius=base_radius, |
| 1172 | + height=height, |
| 1173 | + **kwargs, |
1156 | 1174 | )
|
1157 | 1175 | self.cone.shift(end)
|
1158 |
| - self.add(self.cone) |
| 1176 | + self.end_point = VectorizedPoint(end) |
| 1177 | + self.add(self.end_point, self.cone) |
1159 | 1178 | self.set_color(color)
|
1160 | 1179 |
|
| 1180 | + def get_end(self) -> np.ndarray: |
| 1181 | + return self.end_point.get_center() |
| 1182 | + |
1161 | 1183 |
|
1162 | 1184 | class Torus(Surface):
|
1163 | 1185 | """A torus.
|
|
0 commit comments