vpoints¶
- class janim.components.vpoints.Cmpt_VPoints(*args, **kwargs)¶
Bases:
Cmpt_Points,GenericCurve point coordinate data
Every three points represent a quadratic Bézier curve segment, and consecutive curves share common points.
For example, for a point coordinate list
[a, b, c, d, e, f, g], it represents these curves:[a, b, c][c, d, e][e, f, g]Treat
NAN_POINTas an indicator of subpath end.For example, for a point coordinate list
[a, b, c, d, e, NAN_POINT, f, g, h], it represents two subpaths:[a, b, c, d, e]and[f, g, h]If the end point and start point of a subpath are the same, that subpath is considered a closed path.
- set(points: VectArray) Self¶
Set point coordinate data, each coordinate point has three components
Use the form like
.set([[1.5, 3, 2], [2, 1.5, 0]])
- apply_points_fn(func: PointsFn, *, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
Applies the given function
functo all points as a single parameter, and see the result as new pointsConsiders
about_pointas the origin. If it’sNone, then the edge in theabout_edgedirection is considered asabout_point
- scale(scale_factor: float | Iterable, scale_stroke_radius: bool = False, *, root_only: bool = False, **kwargs) Self¶
Scale the item by a specified factor
If the scale factor provided is an iterable object, each element will be used as the scaling factor for the corresponding coordinate component. For example, if
scale_factoris(2, 0.5, 1), the item will be scaled by a factor of 2 along thexaxis, compressed by half along theyaxis, and remain unchanged along thezaxis
- classmethod align_for_interpolate(cmpt1: Cmpt_VPoints, cmpt2: Cmpt_VPoints) AlignedData[Self]¶
- static align_path(path1: ndarray, path2: ndarray) tuple[ndarray, ndarray]¶
- static insert_n_curves_to_point_list(n: int, points: VectArray) ndarray¶
- insert_n_curves(n: int, root_only=False) Self¶
- get_anchors() ndarray¶
Get the anchor points of the curve
- get_handles() ndarray¶
Get the control points of the curve
- property start_direction: ndarray¶
- property end_direction: ndarray¶
- static start_direction_from_points(points: ndarray) ndarray¶
- static end_direction_from_points(points: ndarray) ndarray¶
- close_path() Self¶
- static get_bezier_tuples_from_points(points: VectArray) Iterable[ndarray]¶
Get a list of Bézier curve control point groups from
pointsFor example, for
pointswith 7 points, the return value is(points[[0, 1, 2]], points[[2, 3, 4]], points[[4, 5, 6]])
- get_bezier_tuples() Iterable[ndarray]¶
Get a list of Bézier curve control point groups. See
get_bezier_tuples_from_points()for details
- curves_count() int¶
Get the number of curves
- get_nth_curve_points(n: int) VectArray¶
Get the control points of the
n-th Bézier curve group (0-indexed)
- get_nth_curve_function(n: int) Callable[[float], ndarray]¶
Returns a point function for the
n-th Bézier curve group. Pass a value between [0, 1] to get the corresponding point on the curve
- get_nth_curve_length_pieces(n: int, sample_points: int | None = None) ndarray¶
- quick_point_from_proportion(alpha: float) ndarray¶
Faster than
point_from_proportion()However, this assumes all curves have the same length, so it is not accurate
- curve_and_prop_of_partial_point(alpha: float) tuple[int, float]¶
If you want to get the point at proportion alpha along the entire curve, this function returns the index of the curve segment corresponding to this proportion, and the proportion to travel on that curve segment
- point_from_proportion(alpha: float) ndarray¶
Returns the point at proportion
alphaalong the entire path.
- pointwise_become_partial(other: Cmpt_VPoints | Item, a: float, b: float) Self¶
Extract the
[a, b]interval (maximum range[0, 1]represents the entire curve) from the passed object’s curve, set it to this object, and keep the number of points unchanged (points outside the interval are placed at the start/end point)
- static partial_points(points: ndarray, a: float, b: float) ndarray¶
Get the
[a, b]portion of the curve represented bypoints(maximum range[0, 1]represents the entire curve), keeping the number of points unchanged (points outside the interval are placed at the start/end point)Note: When
a <= 0andb >= 1, directly returnpointswithout copying
- pointwise_become_partial_reduced(other: Cmpt_VPoints | Item, a: float, b: float) Self¶
Extract the
[a, b]interval (maximum range[0, 1]represents the entire curve) from the passed object’s curve, set it to this object, and discard points outside the interval
- static partial_points_reduced(points: ndarray, a: float, b: float) ndarray¶
Get the
[a, b]portion of the curve represented bypoints(maximum range[0, 1]represents the entire curve), discarding points outside the intervalNote: When
a <= 0andb >= 1, directly returnpointswithout copying
- add_as_corners(points: VectArray) Self¶
Add
pointsas a polyline
- set_as_corners(points: VectArray) Self¶
Set the point data to a polyline formed by
points
- is_smooth(angle_tol: float = 0.017453292519943295) bool¶
- get_joint_products() ndarray¶
Get the dot product of direction vectors before and after each anchor point
- change_anchor_mode(mode: AnchorMode) Self¶
- make_smooth(approx=False, root_only=False) Self¶
Edits the path so as to pass smoothly through all the current anchor points.
If approx is False, this may increase the total number of points.
- make_approximately_smooth(root_only=False) Self¶
- make_jagged(root_only=False) Self¶
- static get_area_vector_from_points(points: ndarray) ndarray¶
- property area_vector: ndarray¶
A vector whose length is the area enclosed by the polygon formed by anchor points, pointing in the direction perpendicular to the polygon according to the right-hand rule
- property unit_normal: ndarray¶
Unit normal vector
- walk_subpath_end_indices() Generator[int, None, None]¶
Iterate over the end indices of each subpath
- get_subpath_end_indices() list[int]¶
- get_closepath_flags() ndarray¶
Get flags indicating whether subpaths are closed. The result length is the same as the number of points
For closed paths, the corresponding parts in the result will be set to
True
- static get_parts_by_end_indices(array: ndarray, end_indices: ndarray) list[ndarray]¶
Segment
arrayaccording to the list of subpath end indices
- get_subpaths() list[ndarray]¶
Get the list of subpaths
- add_subpath(points: VectArray) Self¶
- property identity: tuple[tuple[int, ...], ndarray]¶
- width_along_direction(direction: Vect) float¶
- same_shape(other: Cmpt_VPoints | Item) bool¶
Determine whether two groups of points have exactly the same shape
For two groups of points with the same shape, you can also use
same_direction()to measure direction alignment
- same_direction(other: Cmpt_VPoints | Item) bool¶
For two groups of points where
same_shape()returnsTrue, you can use this method to measure direction alignmentReturns a value between
-1and1Where
1means completely same direction,-1means completely opposite direction, and0means perpendicular
Note: For two groups of points where
same_shape()returnsFalse, the result of this method has no practical meaning