ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/o_cone.c
Revision: 2.1
Committed: Tue Nov 12 17:09:26 1991 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +0 -0 lines
Log Message:
updated revision number for release 2.0

File Contents

# Content
1 /* Copyright (c) 1990 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * o_cone.c - routine to determine ray intersection with cones.
9 *
10 * 2/13/86
11 */
12
13 #include "ray.h"
14
15 #include "otypes.h"
16
17 #include "cone.h"
18
19
20 o_cone(o, r) /* intersect ray with cone */
21 OBJREC *o;
22 register RAY *r;
23 {
24 FVECT rox, rdx;
25 double a, b, c;
26 double root[2];
27 int nroots, rn;
28 register CONE *co;
29 register int i;
30
31 /* get cone structure */
32 co = getcone(o, 1);
33
34 /*
35 * To intersect a ray with a cone, we transform the
36 * ray into the cone's normalized space. This greatly
37 * simplifies the computation.
38 * For a cone or cup, normalization results in the
39 * equation:
40 *
41 * x*x + y*y - z*z == 0
42 *
43 * For a cylinder or tube, the normalized equation is:
44 *
45 * x*x + y*y - r*r == 0
46 *
47 * A normalized ring obeys the following set of equations:
48 *
49 * z == 0 &&
50 * x*x + y*y >= r0*r0 &&
51 * x*x + y*y <= r1*r1
52 */
53
54 /* transform ray */
55 multp3(rox, r->rorg, co->tm);
56 multv3(rdx, r->rdir, co->tm);
57 /* compute intersection */
58
59 if (o->otype == OBJ_CONE || o->otype == OBJ_CUP) {
60
61 a = rdx[0]*rdx[0] + rdx[1]*rdx[1] - rdx[2]*rdx[2];
62 b = 2.0*(rdx[0]*rox[0] + rdx[1]*rox[1] - rdx[2]*rox[2]);
63 c = rox[0]*rox[0] + rox[1]*rox[1] - rox[2]*rox[2];
64
65 } else if (o->otype == OBJ_CYLINDER || o->otype == OBJ_TUBE) {
66
67 a = rdx[0]*rdx[0] + rdx[1]*rdx[1];
68 b = 2.0*(rdx[0]*rox[0] + rdx[1]*rox[1]);
69 c = rox[0]*rox[0] + rox[1]*rox[1] - CO_R0(co)*CO_R0(co);
70
71 } else { /* OBJ_RING */
72
73 if (rdx[2] <= FTINY && rdx[2] >= -FTINY)
74 return(0); /* parallel */
75 root[0] = -rox[2]/rdx[2];
76 if (root[0] <= FTINY || root[0] >= r->rot)
77 return(0); /* distance check */
78 b = root[0]*rdx[0] + rox[0];
79 c = root[0]*rdx[1] + rox[1];
80 a = b*b + c*c;
81 if (a < CO_R0(co)*CO_R0(co) || a > CO_R1(co)*CO_R1(co))
82 return(0); /* outside radii */
83 r->ro = o;
84 r->rot = root[0];
85 for (i = 0; i < 3; i++)
86 r->rop[i] = r->rorg[i] + r->rdir[i]*r->rot;
87 VCOPY(r->ron, co->ad);
88 r->rod = -rdx[2];
89 r->rox = NULL;
90 return(1); /* good */
91 }
92 /* roots for cone, cup, cyl., tube */
93 nroots = quadratic(root, a, b, c);
94
95 for (rn = 0; rn < nroots; rn++) { /* check real roots */
96 if (root[rn] <= FTINY)
97 continue; /* too small */
98 if (root[rn] >= r->rot)
99 break; /* too big */
100 /* check endpoints */
101 for (i = 0; i < 3; i++) {
102 rox[i] = r->rorg[i] + root[rn]*r->rdir[i];
103 rdx[i] = rox[i] - CO_P0(co)[i];
104 }
105 b = DOT(rdx, co->ad);
106 if (b < 0.0)
107 continue; /* before p0 */
108 if (b > co->al)
109 continue; /* after p1 */
110 r->ro = o;
111 r->rot = root[rn];
112 VCOPY(r->rop, rox);
113 /* get normal */
114 if (o->otype == OBJ_CYLINDER)
115 a = CO_R0(co);
116 else if (o->otype == OBJ_TUBE)
117 a = -CO_R0(co);
118 else { /* OBJ_CONE || OBJ_CUP */
119 c = CO_R1(co) - CO_R0(co);
120 a = CO_R0(co) + b*c/co->al;
121 if (o->otype == OBJ_CUP) {
122 c = -c;
123 a = -a;
124 }
125 }
126 for (i = 0; i < 3; i++)
127 r->ron[i] = (rdx[i] - b*co->ad[i])/a;
128 if (o->otype == OBJ_CONE || o->otype == OBJ_CUP)
129 for (i = 0; i < 3; i++)
130 r->ron[i] = (co->al*r->ron[i] - c*co->ad[i])
131 /co->sl;
132 r->rod = -DOT(r->rdir, r->ron);
133 r->rox = NULL;
134 return(1); /* good */
135 }
136 return(0);
137 }