BRL-CAD
nurb_basis.c
Go to the documentation of this file.
1 /* N U R B _ B A S I S . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1990-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup nurb */
21 /** @{ */
22 /** @file primitives/bspline/nurb_basis.c
23  *
24  * Evaluate the B-Spline Basis Functions.
25  *
26  */
27 
28 #include "common.h"
29 
30 #include "bio.h"
31 
32 #include "vmath.h"
33 #include "raytrace.h"
34 #include "nurb.h"
35 
36 /**
37  * This uses the traditional De Boor-Cox algorithm,
38  *
39  * D[k, i] (u) =
40  *
41  * U[i+n-k] - mu mu - U[i-1]
42  * ________________ D[k-1, i-1] (mu)+_________________ D[k-1, i] (mu)
43  * U[i+n-k] - U[i-1] U[i+n-k] - U[i-1]
44  *
45  * For U[i-1]] <= mu < U[i] where U is the knot vector, k is the
46  * order, and i is the interval. If the denominator is zero than the
47  * term is zero.
48  *
49  * Arguments -
50  * knts - knot vector of type (struct knot_vector *)
51  * interval - where the parameter mu is defined above.
52  * order - Order of the b-spline.
53  * mu - value which the basis functions are to be evaluated.
54  *
55  * Returns -
56  * fastf_t - a floating point value of the basis evaluation.
57  *
58  * Reference -
59  * Farin G., "Curves and Surfaces for Computer Aided Geometric Design",
60  * Academic Press, New York 1988.
61  */
62 fastf_t
63 rt_nurb_basis_eval(register struct knot_vector *knts, int interval, int order, fastf_t mu)
64 {
65 
66  register fastf_t den;
67  register fastf_t k1;
68  register fastf_t k2;
69  register fastf_t k3;
70  register fastf_t *kk = knts->knots + interval;
71  fastf_t b1, b2;
72 
73  k1 = *(kk);
74  k2 = *(kk + 1);
75 
76  if (order <= 1) {
77  if ((k1 <= mu) && (mu < k2))
78  return 1.0;
79  else
80  return 0.0;
81  }
82 
83  k3 = *(kk + order);
84 
85  den = (*(kk + order - 1) - k1);
86 
87  if (ZERO(den))
88  b1 = 0.0;
89  else
90  b1 = ((mu - k1) *
91  rt_nurb_basis_eval(knts, interval, order - 1, mu)) / den;
92 
93  den = (k3 - k2);
94 
95  if (ZERO(den))
96  b2 = 0.0;
97  else
98  b2 = ((k3 - mu) *
99  rt_nurb_basis_eval(knts, interval + 1, order - 1, mu)) / den;
100 
101  return b1 + b2;
102 }
103 /** @} */
104 
105 /*
106  * Local Variables:
107  * mode: C
108  * tab-width: 8
109  * indent-tabs-mode: t
110  * c-file-style: "stroustrup"
111  * End:
112  * ex: shiftwidth=4 tabstop=8
113  */
Header file for the BRL-CAD common definitions.
#define ZERO(val)
Definition: units.c:38
double fastf_t
Definition: defines.h:300
fastf_t rt_nurb_basis_eval(register struct knot_vector *knts, int interval, int order, fastf_t mu)
Definition: nurb_basis.c:63