mirror of
https://github.com/3b1b/manim.git
synced 2025-11-14 08:27:45 +00:00
Add VMobject.subdivide_intersections
This commit is contained in:
parent
de4a56849e
commit
a2f3758a7a
1 changed files with 23 additions and 0 deletions
|
|
@ -34,6 +34,7 @@ from manimlib.utils.space_ops import cross2d
|
|||
from manimlib.utils.space_ops import earclip_triangulation
|
||||
from manimlib.utils.space_ops import get_norm
|
||||
from manimlib.utils.space_ops import get_unit_normal
|
||||
from manimlib.utils.space_ops import line_intersects_path
|
||||
from manimlib.utils.space_ops import midpoint
|
||||
from manimlib.utils.space_ops import normalize_along_axis
|
||||
from manimlib.utils.space_ops import z_to_vector
|
||||
|
|
@ -566,6 +567,28 @@ class VMobject(Mobject):
|
|||
vmob.set_points(np.vstack(new_points))
|
||||
return self
|
||||
|
||||
def subdivide_sharp_curves(
|
||||
self,
|
||||
angle_threshold: float = 30 * DEGREES,
|
||||
recurse: bool = True
|
||||
):
|
||||
def tuple_to_subdivisions(b0, b1, b2):
|
||||
angle = angle_between_vectors(b1 - b0, b2 - b1)
|
||||
return int(angle / angle_threshold)
|
||||
|
||||
self.subdivide_curves_by_condition(tuple_to_subdivisions, recurse)
|
||||
return self
|
||||
|
||||
def subdivide_intersections(self, recurse: bool = True):
|
||||
path = self.get_anchors()
|
||||
def tuple_to_subdivisions(b0, b1, b2):
|
||||
if line_intersects_path(b0, b1, path):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
self.subdivide_curves_by_condition(tuple_to_subdivisions, recurse)
|
||||
return self
|
||||
|
||||
def add_points_as_corners(self, points: Iterable[Vect3]):
|
||||
for point in points:
|
||||
self.add_line_to(point)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue