-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubdiv.c
executable file
·55 lines (45 loc) · 1.26 KB
/
subdiv.c
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
#include <math.h>
void subdiv(degree,coeff,weight,t,bleft,bright,wleft,wright)
/*
subdivides ratbez curve at parameter value t.
Output: left and right polygon with respective weights.
Ordering of right polygon is reversed.
*/
float coeff[],weight[],bleft[],
bright[],wleft[],wright[];
float t;
int degree;
{
int r,i;
float t1,ww1,ww2;
t1 = 1.0 - t;
/*
first, obtain right subpolygon from rat de Casteljau
*/
for (i=0;i <= degree; i++) wright[i] = weight[i];
for (i=0;i <= degree; i++) bright[i] = coeff[i];
for (r=1; r<= degree; r++)
for (i=0; i<= degree - r; i++)
{
ww1 = wright[i]; ww2= wright[i+1];
wright[i] = t1*wright[i] + t*wright[i+1];
bright[i]= ( t1*ww1 * bright[i]
+ t*ww2 * bright[i+1] ) / wright[i];
}
/*
use same as above in order to get left half. Idea:
reverse ordering; then the above yields left half.
*/
t = 1.0 - t; t1 = 1.0 - t;
for (i=0;i <= degree; i++) wleft[degree -i] = weight[i];
for (i=0;i <= degree; i++) bleft[degree-i] = coeff[i];
for (r=1; r<= degree; r++)
for (i=0; i<= degree - r; i++)
{
ww1 = wleft[i]; ww2= wleft[i+1];
wleft[i] = t1*wleft[i] + t*wleft[i+1];
bleft[i]= ( t1*ww1 * bleft[i]
+ t*ww2 * bleft[i+1] ) / wleft[i];
}
}