5552
|
1 function dnurbs = nrbderiv(nurbs) |
|
2 % |
|
3 % NRBDERIV: Construct the first derivative representation of a |
|
4 % NURBS curve or surface. |
|
5 % |
|
6 % Calling Sequence: |
|
7 % |
|
8 % ders = nrbderiv(nrb); |
|
9 % |
|
10 % Parameters: |
|
11 % |
|
12 % nrb : NURBS data structure, see nrbmak. |
|
13 % |
|
14 % ders : A data structure that represents the first |
|
15 % derivatives of a NURBS curve or surface. |
|
16 % |
|
17 % Description: |
|
18 % |
|
19 % The derivatives of a B-Spline are themselves a B-Spline of lower degree, |
|
20 % giving an efficient means of evaluating multiple derivatives. However, |
|
21 % although the same approach can be applied to NURBS, the situation for |
|
22 % NURBS is a more complex. I have at present restricted the derivatives |
|
23 % to just the first. I don't claim that this implentation is |
|
24 % the best approach, but it will have to do for now. The function returns |
|
25 % a data struture that for a NURBS curve contains the first derivatives of |
|
26 % the B-Spline representation. Remember that a NURBS curve is represent by |
|
27 % a univariate B-Spline using the homogeneous coordinates. |
|
28 % The derivative data structure can be evaluated later with the function |
|
29 % nrbdeval. |
|
30 % |
|
31 % Examples: |
|
32 % |
|
33 % See the function nrbdeval for an example. |
|
34 % |
|
35 % See: |
|
36 % |
|
37 % nrbdeval |
|
38 |
|
39 % D.M. Spink |
|
40 % Copyright (c) 2000. |
|
41 |
|
42 if ~isstruct(nurbs) |
|
43 error('NURBS representation is not structure!'); |
|
44 end |
|
45 |
|
46 if ~strcmp(nurbs.form,'B-NURBS') |
|
47 error('Not a recognised NURBS representation'); |
|
48 end |
|
49 |
|
50 degree = nurbs.order - 1; |
|
51 |
|
52 if iscell(nurbs.knots) |
|
53 % NURBS structure represents a surface |
|
54 |
|
55 num1 = nurbs.number(1); |
|
56 num2 = nurbs.number(2); |
|
57 |
|
58 % taking derivatives along the u direction |
|
59 dknots = nurbs.knots; |
|
60 dcoefs = permute(nurbs.coefs,[1 3 2]); |
|
61 dcoefs = reshape(dcoefs,4*num2,num1); |
|
62 [dcoefs,dknots{1}] = bspderiv(degree(1),dcoefs,nurbs.knots{1}); |
|
63 dcoefs = permute(reshape(dcoefs,[4 num2 size(dcoefs,2)]),[1 3 2]); |
|
64 dnurbs{1} = nrbmak(dcoefs, dknots); |
|
65 |
|
66 % taking derivatives along the v direction |
|
67 dknots = nurbs.knots; |
|
68 dcoefs = reshape(nurbs.coefs,4*num1,num2); |
|
69 [dcoefs,dknots{2}] = bspderiv(degree(2),dcoefs,nurbs.knots{2}); |
|
70 dcoefs = reshape(dcoefs,[4 num1 size(dcoefs,2)]); |
|
71 dnurbs{2} = nrbmak(dcoefs, dknots); |
|
72 |
|
73 else |
|
74 % NURBS structure represents a curve |
|
75 |
|
76 [dcoefs,dknots] = bspderiv(degree,nurbs.coefs,nurbs.knots); |
|
77 dnurbs = nrbmak(dcoefs, dknots); |
|
78 |
|
79 end |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |