2 # /usr/lib/python2.7/dist-packages/matplotlib/bezier.py
3 # in Debian's python-matplotlib 2.0.0+dfsg1-2 (amd64)
4 # and trimmed to have only BezierSegment
6 # 1. This LICENSE AGREEMENT is between the Matplotlib Development Team
7 # ("MDT"), and the Individual or Organization ("Licensee") accessing and
8 # otherwise using matplotlib software in source or binary form and its
9 # associated documentation.
11 # 2. Subject to the terms and conditions of this License Agreement, MDT
12 # hereby grants Licensee a nonexclusive, royalty-free, world-wide license
13 # to reproduce, analyze, test, perform and/or display publicly, prepare
14 # derivative works, distribute, and otherwise use matplotlib
15 # alone or in any derivative version, provided, however, that MDT's
16 # License Agreement and MDT's notice of copyright, i.e., "Copyright (c)
17 # 2012- Matplotlib Development Team; All Rights Reserved" are retained in
18 # matplotlib alone or in any derivative version prepared by
21 # 3. In the event Licensee prepares a derivative work that is based on or
22 # incorporates matplotlib or any part thereof, and wants to
23 # make the derivative work available to others as provided herein, then
24 # Licensee hereby agrees to include in any such work a brief summary of
25 # the changes made to matplotlib .
27 # 4. MDT is making matplotlib available to Licensee on an "AS
28 # IS" basis. MDT MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
29 # IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, MDT MAKES NO AND
30 # DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
31 # FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB
32 # WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
34 # 5. MDT SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB
35 # FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
36 # LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING
37 # MATPLOTLIB , OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
38 # THE POSSIBILITY THEREOF.
40 # 6. This License Agreement will automatically terminate upon a material
41 # breach of its terms and conditions.
43 # 7. Nothing in this License Agreement shall be deemed to create any
44 # relationship of agency, partnership, or joint venture between MDT and
45 # Licensee. This License Agreement does not grant permission to use MDT
46 # trademarks or trade name in a trademark sense to endorse or promote
47 # products or services of Licensee, or any third party.
49 # 8. By copying, installing or otherwise using matplotlib ,
50 # Licensee agrees to be bound by the terms and conditions of this License
57 class BezierSegment(object):
59 A simple class of a 2-dimensional bezier segment
62 # Higher order bezier lines can be supported by simplying adding
63 # corresponding values.
64 _binom_coeff = {1: np.array([1., 1.]),
65 2: np.array([1., 2., 1.]),
66 3: np.array([1., 3., 3., 1.])}
68 def __init__(self, control_points):
70 *control_points* : location of contol points. It needs have a
71 shpae of n * 2, where n is the order of the bezier line. 1<=
74 _o = len(control_points)
75 self._orders = np.arange(_o)
76 _coeff = BezierSegment._binom_coeff[_o - 1]
78 _control_points = np.asarray(control_points)
79 xx = _control_points[:, 0]
80 yy = _control_points[:, 1]
82 self._px = xx * _coeff
83 self._py = yy * _coeff
85 def point_at_t(self, t):
86 "evaluate a point at t"
87 one_minus_t_powers = np.power(1. - t, self._orders)[::-1]
88 t_powers = np.power(t, self._orders)
90 tt = one_minus_t_powers * t_powers
91 _x = sum(tt * self._px)
92 _y = sum(tt * self._py)