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