|
![](/i/fill.gif) |
Invisible wrote:
> using de Casteljau's algorithm:
>
> Plot(T, P[])
> If P[] contains just one point, return it. Otherwise...
> Construct Q[] by linearly interpolating between each adjacent pair
> of points in P[], at parameter=T.
> Recursively call Plot(T, Q[]).
In Haskell:
spline t ps =
case ps of
[] -> error "zero control points"
p:[] -> p
_ -> spline t $ zipWith (\a b -> (a *| (1-t)) + (b *| t)) ps
(tail ps)
It's delightfully simple stuff like this that makes me love Haskell.
> except that each control point has a "weight". What the algorithm
> appears to do is draw the spline in 3D and then perspective-project it
> back into 2D.
This is presumably trivial in almost any language... but in Haskell:
rational_bezier t ps =
let Vector3 x y z = bezier_spline $ map (\(Vector2 x y, k) ->
Vector3 (k*x) (k*y) k) ps
in Vector2 (x/z) (y/z)
Again, beautifully simple (if rather wide to fit on one line...)
> has a "knot vector" which controls how much of the curve is influenced
> by a specific control point. A B-spline can be "uniform" (all knots
> equally spaced) or "non-uniform" (knot spacing is unequal).
>
> This much I understand. What I don't yet understand is the fine detail
> of how B-splines actually work.
>
> A NURBS is simply a B-spline which is (potentially) non-uniform (i.e.,
> the knots are adjustable) and rational (i.e., it uses this strange 3D
> projection trick). So if I could just understand B-splines, I would be
> able to comprehend NURBS.
Uh... yeah. o_O
Post a reply to this message
|
![](/i/fill.gif) |