]> git.lizzy.rs Git - plan9front.git/blob - sys/man/2/arith3
merge
[plan9front.git] / sys / man / 2 / arith3
1 .TH ARITH3 2
2 .SH NAME
3 add3, sub3, neg3, div3, mul3, eqpt3, closept3, dot3, cross3, len3, dist3, unit3, midpt3, lerp3, reflect3, nearseg3, pldist3, vdiv3, vrem3, pn2f3, ppp2f3, fff2p3, pdiv4, add4, sub4 \- operations on 3-d points and planes
4 .SH SYNOPSIS
5 .B
6 #include <draw.h>
7 .br
8 .B
9 #include <geometry.h>
10 .PP
11 .B
12 Point3 add3(Point3 a, Point3 b)
13 .PP
14 .B
15 Point3 sub3(Point3 a, Point3 b)
16 .PP
17 .B
18 Point3 neg3(Point3 a)
19 .PP
20 .B
21 Point3 div3(Point3 a, double b)
22 .PP
23 .B
24 Point3 mul3(Point3 a, double b)
25 .PP
26 .B
27 int eqpt3(Point3 p, Point3 q)
28 .PP
29 .B
30 int closept3(Point3 p, Point3 q, double eps)
31 .PP
32 .B
33 double dot3(Point3 p, Point3 q)
34 .PP
35 .B
36 Point3 cross3(Point3 p, Point3 q)
37 .PP
38 .B
39 double len3(Point3 p)
40 .PP
41 .B
42 double dist3(Point3 p, Point3 q)
43 .PP
44 .B
45 Point3 unit3(Point3 p)
46 .PP
47 .B
48 Point3 midpt3(Point3 p, Point3 q)
49 .PP
50 .B
51 Point3 lerp3(Point3 p, Point3 q, double alpha)
52 .PP
53 .B
54 Point3 reflect3(Point3 p, Point3 p0, Point3 p1)
55 .PP
56 .B
57 Point3 nearseg3(Point3 p0, Point3 p1, Point3 testp)
58 .PP
59 .B
60 double pldist3(Point3 p, Point3 p0, Point3 p1)
61 .PP
62 .B
63 double vdiv3(Point3 a, Point3 b)
64 .PP
65 .B
66 Point3 vrem3(Point3 a, Point3 b)
67 .PP
68 .B
69 Point3 pn2f3(Point3 p, Point3 n)
70 .PP
71 .B
72 Point3 ppp2f3(Point3 p0, Point3 p1, Point3 p2)
73 .PP
74 .B
75 Point3 fff2p3(Point3 f0, Point3 f1, Point3 f2)
76 .PP
77 .B
78 Point3 pdiv4(Point3 a)
79 .PP
80 .B
81 Point3 add4(Point3 a, Point3 b)
82 .PP
83 .B
84 Point3 sub4(Point3 a, Point3 b)
85 .SH DESCRIPTION
86 These routines do arithmetic on points and planes in affine or projective 3-space.
87 Type
88 .B Point3
89 is
90 .IP
91 .EX
92 .ta 6n
93 typedef struct Point3 Point3;
94 struct Point3{
95         double x, y, z, w;
96 };
97 .EE
98 .PP
99 Routines whose names end in
100 .B 3
101 operate on vectors or ordinary points in affine 3-space, represented by their Euclidean
102 .B (x,y,z)
103 coordinates.
104 (They assume
105 .B w=1
106 in their arguments, and set
107 .B w=1
108 in their results.)
109 .TF reflect3
110 .TP
111 Name
112 Description
113 .TP
114 .B add3
115 Add the coordinates of two points.
116 .TP
117 .B sub3
118 Subtract coordinates of two points.
119 .TP
120 .B neg3
121 Negate the coordinates of a point.
122 .TP
123 .B mul3
124 Multiply coordinates by a scalar.
125 .TP
126 .B div3
127 Divide coordinates by a scalar.
128 .TP
129 .B eqpt3
130 Test two points for exact equality.
131 .TP
132 .B closept3
133 Is the distance between two points smaller than 
134 .IR eps ?
135 .TP
136 .B dot3
137 Dot product.
138 .TP
139 .B cross3
140 Cross product.
141 .TP
142 .B len3
143 Distance to the origin.
144 .TP
145 .B dist3
146 Distance between two points.
147 .TP
148 .B unit3
149 A unit vector parallel to
150 .IR p .
151 .TP
152 .B midpt3
153 The midpoint of line segment 
154 .IR pq .
155 .TP
156 .B lerp3
157 Linear interpolation between 
158 .I p
159 and
160 .IR q .
161 .TP
162 .B reflect3
163 The reflection of point
164 .I p
165 in the segment joining 
166 .I p0
167 and
168 .IR p1 .
169 .TP
170 .B nearseg3
171 The closest point to 
172 .I testp
173 on segment
174 .IR "p0 p1" .
175 .TP
176 .B pldist3
177 The distance from 
178 .I p
179 to segment
180 .IR "p0 p1" .
181 .TP
182 .B vdiv3
183 Vector divide \(em the length of the component of 
184 .I a
185 parallel to
186 .IR b ,
187 in units of the length of
188 .IR b .
189 .TP
190 .B vrem3
191 Vector remainder \(em the component of 
192 .I a
193 perpendicular to
194 .IR b .
195 Ignoring roundoff, we have 
196 .BR "eqpt3(add3(mul3(b, vdiv3(a, b)), vrem3(a, b)), a)" .
197 .PD
198 .PP
199 The following routines convert amongst various representations of points
200 and planes.  Planes are represented identically to points, by duality;
201 a point
202 .B p
203 is on a plane
204 .B q
205 whenever
206 .BR p.x*q.x+p.y*q.y+p.z*q.z+p.w*q.w=0 .
207 Although when dealing with affine points we assume
208 .BR p.w=1 ,
209 we can't make the same assumption for planes.
210 The names of these routines are extra-cryptic.  They contain an
211 .B f
212 (for `face') to indicate a plane,
213 .B p
214 for a point and
215 .B n
216 for a normal vector.
217 The number
218 .B 2
219 abbreviates the word `to.'
220 The number
221 .B 3
222 reminds us, as before, that we're dealing with affine points.
223 Thus
224 .B pn2f3
225 takes a point and a normal vector and returns the corresponding plane.
226 .TF reflect3
227 .TP
228 Name
229 Description
230 .TP
231 .B pn2f3
232 Compute the plane passing through
233 .I p
234 with normal
235 .IR n .
236 .TP
237 .B ppp2f3
238 Compute the plane passing through three points.
239 .TP
240 .B fff2p3
241 Compute the intersection point of three planes.
242 .PD
243 .PP
244 The names of the following routines end in
245 .B 4
246 because they operate on points in projective 4-space,
247 represented by their homogeneous coordinates.
248 .TP
249 pdiv4
250 Perspective division.  Divide
251 .B p.w
252 into
253 .IR p 's
254 coordinates, converting to affine coordinates.
255 If
256 .B p.w
257 is zero, the result is the same as the argument.
258 .TP
259 add4
260 Add the coordinates of two points.
261 .PD
262 .TP
263 sub4
264 Subtract the coordinates of two points.
265 .SH SOURCE
266 .B /sys/src/libgeometry
267 .SH "SEE ALSO
268 .IR matrix (2)