Skip to content

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions lib/matplotlib/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link
Contributor

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"?

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)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is an array, then isn't this just _contrrol_points.T?


self._px = xx * _coeff
self._py = yy * _coeff
self._pxyz = [xx * _coeff for xx in xyz]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this is xyz * _coeff.


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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this is np.sum(tt * px, axis=1).


return tuple(_xyz)

def split_bezier_intersecting_with_closedpath(bezier,
inside_closedpath,
Expand Down