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