-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Make BezierSegment support N-dimensional beziers #9686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,7 +151,7 @@ def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t, | |
|
||
class BezierSegment(object): | ||
""" | ||
A simple class of a 2-dimensional bezier segment | ||
A simple class of an N-dimensional bezier segment | ||
""" | ||
|
||
# Higher order bezier lines can be supported by simplying adding | ||
|
@@ -163,31 +163,29 @@ class BezierSegment(object): | |
def __init__(self, control_points): | ||
""" | ||
*control_points* : location of contol points. It needs have a | ||
shpae of n * 2, where n is the order of the bezier line. 1<= | ||
n <= 3 is supported. | ||
shpae of n * D, where n is the order of the bezier line | ||
and D is the dimension (the length of each control point | ||
tuple). 1 <= n <= 3 is supported. | ||
""" | ||
_o = len(control_points) | ||
dim = len(control_points[0]) | ||
self._orders = np.arange(_o) | ||
_coeff = BezierSegment._binom_coeff[_o - 1] | ||
|
||
_control_points = np.asarray(control_points) | ||
xx = _control_points[:, 0] | ||
yy = _control_points[:, 1] | ||
xyz = [_control_points[:, i] for i in range(0, dim)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is an array, then isn't this just |
||
|
||
self._px = xx * _coeff | ||
self._py = yy * _coeff | ||
self._pxyz = [xx * _coeff for xx in xyz] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this is |
||
|
||
def point_at_t(self, t): | ||
"evaluate a point at t" | ||
one_minus_t_powers = np.power(1. - t, self._orders)[::-1] | ||
t_powers = np.power(t, self._orders) | ||
|
||
tt = one_minus_t_powers * t_powers | ||
_x = sum(tt * self._px) | ||
_y = sum(tt * self._py) | ||
|
||
return _x, _y | ||
_xyz = [sum(tt * px) for px in self._pxyz] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this is |
||
|
||
return tuple(_xyz) | ||
|
||
def split_bezier_intersecting_with_closedpath(bezier, | ||
inside_closedpath, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"It needs to have a shape"?