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