BRL-CAD
Loading...
Searching...
No Matches
plane.h
Go to the documentation of this file.
1/* P L A N E . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2026 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
21/*----------------------------------------------------------------------*/
22/** @addtogroup bg_plane
23 *
24 * Plane structures (from src/librt/plane.h) and plane/line/point calculations
25 *
26 * TODO - this API may need to be simplified. A lot of the closest point
27 * calculations, for example, should probably just concern themselves with the
28 * calculation itself and leave any tolerance based questions to a separate
29 * step.
30 */
31/** @{ */
32/* @file plane.h */
33
34#ifndef BG_PLANE_H
35#define BG_PLANE_H
36
37#include "common.h"
38#include "vmath.h"
39#include "bn/tol.h"
40#include "bg/defines.h"
41
42__BEGIN_DECLS
43
44
45#define MAXPTS 4 /**< All we need are 4 points */
46#define pl_A pl_points[0] /**< Synonym for A point */
48struct plane_specific {
49 size_t pl_npts; /**< number of points on plane */
50 point_t pl_points[MAXPTS]; /**< Actual points on plane */
51 vect_t pl_Xbasis; /**< X (B-A) vector (for 2d coords) */
52 vect_t pl_Ybasis; /**< Y (C-A) vector (for 2d coords) */
53 vect_t pl_N; /**< Unit-length Normal (outward) */
54 fastf_t pl_NdotA; /**< Normal dot A */
55 fastf_t pl_2d_x[MAXPTS]; /**< X 2d-projection of points */
56 fastf_t pl_2d_y[MAXPTS]; /**< Y 2d-projection of points */
57 fastf_t pl_2d_com[MAXPTS]; /**< pre-computed common-term */
58 struct plane_specific *pl_forw; /**< Forward link */
59 char pl_code[MAXPTS+1]; /**< Face code string. Decorative. */
60};
61
62/**
63 * Describe the tri_specific structure.
64 *
65 * DEPRECATED - removing this as public API. (marked 7.42.0)
66 */
67struct tri_specific {
68 point_t tri_A; /**< triangle vertex (A) */
69 vect_t tri_BA; /**< B - A (second point) */
70 vect_t tri_CA; /**< C - A (third point) */
71 vect_t tri_wn; /**< facet normal (non-unit) */
72 vect_t tri_N; /**< unit normal vector */
73 fastf_t *tri_normals; /**< unit vertex normals A, B, C (this is malloced storage) */
74 int tri_surfno; /**< solid specific surface number */
75 struct tri_specific *tri_forw; /**< Next facet */
76};
77
80/**
81 * A more memory conservative version
82 */
83struct tri_float_specific {
84 float tri_A[3]; /**< triangle vertex (A) */
85 float tri_BA[3]; /**< B - A (second point) */
86 float tri_CA[3]; /**< C - A (third point) */
87 float tri_wn[3]; /**< facet normal (non-unit) */
88 float tri_N[3]; /**< unit normal vector */
89 signed char *tri_normals; /**< unit vertex normals A, B, C (this is malloced storage) */
90 int tri_surfno; /**< solid specific surface number */
91 struct tri_float_specific *tri_forw;/**< Next facet */
92};
93
96
97/**
98 *@brief
99 * Calculate the square of the distance of closest approach for two
100 * lines.
101 *
102 * The lines are specified as a point and a vector each. The vectors
103 * need not be unit length, but must be nonzero. P and d define one line;
104 * Q and e define the other.
105 *
106 * @return 0 - normal return
107 * @return 1 - lines are parallel, dist[0] is set to 0.0
108 *
109 * Output values:
110 * dist[0] is the parametric distance along the first line P + dist[0] * d of the PCA
111 * dist[1] is the parametric distance along the second line Q + dist[1] * e of the PCA
112 * dist[2] is the square of the distance between the points of closest approach
113 * pt1 is the point of closest approach on the first line
114 * pt2 is the point of closest approach on the second line
115 *
116 * This algorithm is based on expressing the distance squared, taking
117 * partials with respect to the two unknown parameters (dist[0] and
118 * dist[1]), setting the two partials equal to 0, and solving the two
119 * simultaneous equations
120 */
121BG_EXPORT extern int bg_distsq_line3_line3(fastf_t dist[3],
122 const point_t P,
123 const vect_t d,
124 const point_t Q,
125 const vect_t e,
126 point_t pt1,
127 point_t pt2);
128
129/**
130 * Find the distance from a point P to a line described by the
131 * endpoint A and direction dir, and the point of closest approach
132 * (PCA).
133 * The line arguments are A followed by dir; P is the query point.
134 * dir need not be unit length. A zero direction is treated as a degenerate
135 * line located at A.
136 *
137 @code
138 // P
139 // *
140 // /.
141 // / .
142 // / .
143 // / . (dist)
144 // / .
145 // / .
146 // *------*-------->
147 // A PCA dir
148 @endcode
149 * There are three distinct cases, with these return codes -
150 * 0 => P is within tolerance of point A. *dist = 0, pca=A.
151 * 1 => P is within tolerance of line. *dist = 0, pca=computed.
152 * 2 => P is "above/below" line. *dist=|PCA-P|, pca=computed.
153 *
154 * TODO: For efficiency, a version of this routine that provides the
155 * distance squared would be faster.
156 */
157BG_EXPORT extern int bg_dist_pnt3_line3(fastf_t *dist,
158 point_t pca,
159 const point_t a,
160 const vect_t dir,
161 const point_t p,
162 const struct bn_tol *tol);
163
164/**
165 * calculate intersection or closest approach of a line and a line
166 * segment.
167 *
168 * returns:
169 * -2 -> line and line segment are parallel, not collinear.
170 * -1 -> line and line segment are parallel and collinear.
171 * 0 -> intersection between points a and b.
172 * 1 -> intersection outside a and b.
173 * 2 -> closest approach is between a and b.
174 * 3 -> closest approach is outside a and b.
175 *
176 * dist[0] is actual distance from p in d direction to
177 * closest portion of segment.
178 * dist[1] is ratio of distance from a to b (0.0 at a, and 1.0 at b),
179 * dist[1] may be less than 0 or greater than 1.
180 * For return values less than 0, closest approach is defined as the point
181 * pair whose point on the input line is closest to p; dist[0] is therefore
182 * closest to zero.
183 * A degenerate segment is treated as point a: the function returns 0 when
184 * that point is within tolerance of the line, otherwise it returns 3, with
185 * dist[1] set to 0.0.
186 * Direction vector, d, must be unit length.
187 *
188 */
189BG_EXPORT extern int bg_dist_line3_lseg3(fastf_t *dist,
190 const fastf_t *p,
191 const fastf_t *d,
192 const fastf_t *a,
193 const fastf_t *b,
194 const struct bn_tol *tol);
195
196/**
197 * Calculate closest approach of two lines
198 *
199 * returns:
200 * -2 -> lines are parallel and do not intersect
201 * -1 -> lines are parallel and collinear
202 * 0 -> lines intersect
203 * 1 -> lines do not intersect
204 *
205 * For return values less than zero, dist is not set. For return
206 * values of 0 or 1, dist[0] is the distance from p1 in the d1
207 * direction to the point of closest approach for that line. Similar
208 * for the second line. The lines are supplied as (p1, d1) and
209 * (p2, d2); d1 and d2 must be unit direction vectors.
210 *
211 * XXX How is this different from bg_isect_line3_line3() ?
212 * XXX Why are the calling sequences just slightly different?
213 * XXX Can we pick the better one, and get rid of the other one?
214 * XXX If not, can we document how they differ?
215 */
216BG_EXPORT extern int bg_dist_line3_line3(fastf_t dist[2],
217 const point_t p1,
218 const vect_t d1,
219 const point_t p2,
220 const vect_t d2,
221 const struct bn_tol *tol);
222
223/**
224 *@brief
225 * Find the distance from a point P to a line segment described by the
226 * two endpoints A and B, and the point of closest approach (PCA).
227 @verbatim
228 *
229 * P
230 * *
231 * /.
232 * / .
233 * / .
234 * / . (dist)
235 * / .
236 * / .
237 * *------*--------*
238 * A PCA B
239 @endverbatim
240 *
241 * @return 0 P is within tolerance of lseg AB. *dist isn't 0: (SPECIAL!!!)
242 * *dist = parametric dist = |PCA-A| / |B-A|. pca=computed.
243 * @return 1 P is within tolerance of point A. *dist = 0, pca=A.
244 * @return 2 P is within tolerance of point B. *dist = 0, pca=B.
245 * @return 3 P is to the "left" of point A. *dist=|P-A|, pca=A.
246 * @return 4 P is to the "right" of point B. *dist=|P-B|, pca=B.
247 * @return 5 P is "above/below" lseg AB. *dist=|PCA-P|, pca=computed.
248 *
249 * If A and B coincide, the segment is treated as point A: P within tolerance
250 * of A returns 1, and all other points return 3.
251 *
252 * This routine was formerly called bn_dist_pnt_lseg().
253 *
254 * XXX For efficiency, a version of this routine that provides the
255 * XXX distance squared would be faster.
256 */
257BG_EXPORT extern int bg_dist_pnt3_lseg3(fastf_t *dist,
258 point_t pca,
259 const point_t a,
260 const point_t b,
261 const point_t p,
262 const struct bn_tol *tol);
263
264/**
265 * PRIVATE: This is a new API and should be considered unpublished.
266 *
267 * Find the square of the distance from a point P to a line segment described
268 * by the two endpoints A and B.
269 *
270 * P
271 * *
272 * /.
273 * / .
274 * / .
275 * / . (dist)
276 * / .
277 * / .
278 * *------*--------*
279 * A PCA B
280 *
281 * There are six distinct cases, with these return codes -
282 * Return code precedence: 1, 2, 0, 3, 4, 5
283 *
284 * 0 P is within tolerance of lseg AB. *dist = 0.
285 * 1 P is within tolerance of point A. *dist = 0.
286 * 2 P is within tolerance of point B. *dist = 0.
287 * 3 PCA is within tolerance of A. *dist = |P-A|**2.
288 * 4 PCA is within tolerance of B. *dist = |P-B|**2.
289 * 5 P is "above/below" lseg AB. *dist=|PCA-P|**2.
290 *
291 * If both P and PCA and not within tolerance of lseg AB use
292 * these return codes -
293 *
294 * 3 PCA is to the left of A. *dist = |P-A|**2.
295 * 4 PCA is to the right of B. *dist = |P-B|**2.
296 *
297 * If A and B coincide, the segment is treated as point A: P within tolerance
298 * of A returns 1, and all other points return 3.
299 *
300 * This function is a test version of "bn_distsq_pnt3_lseg3".
301 *
302 */
303BG_EXPORT extern int bg_distsq_pnt3_lseg3_v2(fastf_t *distsq,
304 const fastf_t *a,
305 const fastf_t *b,
306 const fastf_t *p,
307 const struct bn_tol *tol);
308
309/**
310 * @brief
311 * Check to see if three points are collinear.
312 *
313 * The algorithm is designed to work properly regardless of the order
314 * in which the points are provided.
315 *
316 * @return 1 If 3 points are collinear
317 * @return 0 If they are not
318 */
319BG_EXPORT extern int bg_3pnts_collinear(point_t a,
320 point_t b,
322 const struct bn_tol *tol);
323
324/**
325 * @return 1 if the two points are equal, within the tolerance
326 * @return 0 if the two points are not "the same"
327 */
328BG_EXPORT extern int bg_pnt3_pnt3_equal(const point_t a,
329 const point_t b,
330 const struct bn_tol *tol);
331
332/**
333 *@brief
334 * Find the distance from a point P to a line segment described by the
335 * two endpoints A and B, and the point of closest approach (PCA).
336 @verbatim
337 * P
338 * *
339 * /.
340 * / .
341 * / .
342 * / . (dist)
343 * / .
344 * / .
345 * *------*--------*
346 * A PCA B
347 @endverbatim
348 * There are six distinct cases, with these return codes -
349 * @return 0 P is within tolerance of lseg AB. *dist isn't 0: (SPECIAL!!!)
350 * *dist = parametric dist = |PCA-A| / |B-A|. pca=computed.
351 * @return 1 P is within tolerance of point A. *dist = 0, pca=A.
352 * @return 2 P is within tolerance of point B. *dist = 0, pca=B.
353 * @return 3 P is to the "left" of point A. *dist=|P-A|**2, pca=A.
354 * @return 4 P is to the "right" of point B. *dist=|P-B|**2, pca=B.
355 * @return 5 P is "above/below" lseg AB. *dist=|PCA-P|**2, pca=computed.
356 *
357 * If A and B coincide, the segment is treated as point A: P within tolerance
358 * of A returns 1, and all other points return 3.
359 *
360 *
361 * Patterned after bg_dist_pnt3_lseg3().
362 */
363BG_EXPORT extern int bg_dist_pnt2_lseg2(fastf_t *dist_sq,
364 fastf_t pca[2],
365 const point_t a,
366 const point_t b,
367 const point_t p,
368 const struct bn_tol *tol);
369
370/**
371 *@brief
372 * Intersect two 3D line segments, defined by two points and two nonzero
373 * vectors. The vector magnitudes define the segment lengths.
374 *
375 *
376 * @return -3 missed
377 * @return -2 missed (line segments are parallel)
378 * @return -1 missed (collinear and non-overlapping)
379 * @return 0 hit (line segments collinear and overlapping)
380 * @return 1 hit (normal intersection)
381 *
382 * @param[out] dist
383 * The value at dist[] is set to the parametric distance of the
384 * intercept dist[0] is parameter along p, range 0 to 1, to
385 * intercept. dist[1] is parameter along q, range 0 to 1, to
386 * intercept. If within distance tolerance of the endpoints,
387 * these will be exactly 0.0 or 1.0, to ease the job of caller.
388 *
389 * CLARIFICATION: This function 'bg_isect_lseg3_lseg3'
390 * returns distance values scaled where an intersect at the start
391 * point of the line segment (within tol->dist) results in 0.0
392 * and when the intersect is at the end point of the line
393 * segment (within tol->dist), the result is 1.0. Intersects
394 * before the start point return a negative distance. Intersects
395 * after the end point result in a return value > 1.0.
396 *
397 * Special note: when return code is "0" for co-linearity, dist[1] has
398 * an alternate interpretation: it's the parameter along p (not q)
399 * which takes you from point p to the point (q + qdir), i.e., it's
400 * the endpoint of the q linesegment, since in this case there may be
401 * *two* intersections, if q is contained within span p to (p + pdir).
402 *
403 * @param p point 1
404 * @param pdir direction-1
405 * @param q point 2
406 * @param qdir direction-2
407 * @param tol tolerance values
408 */
409BG_EXPORT extern int bg_isect_lseg3_lseg3(fastf_t *dist,
410 const point_t p, const vect_t pdir,
411 const point_t q, const vect_t qdir,
412 const struct bn_tol *tol);
413
414BG_EXPORT extern int bg_lseg3_lseg3_parallel(const point_t sg1pt1, const point_t sg1pt2,
415 const point_t sg2pt1, const point_t sg2pt2,
416 const struct bn_tol *tol);
417
418/**
419 * Intersect two line segments, each in given in parametric form:
420 *
421 * X = p0 + pdist * pdir_i (i.e. line p0->p1)
422 * and
423 * X = q0 + qdist * qdir_i (i.e. line q0->q1)
424 *
425 * The input vectors 'pdir_i' and 'qdir_i' must be nonzero, but need not be
426 * unit length. The returned distances are Euclidean distances along the
427 * respective lines.
428 *
429 * The 'pdist' and 'qdist' values returned from this function are the
430 * actual distance to the intersect (i.e. not scaled). Distances may
431 * be negative, see below.
432 *
433 * @return -2 no intersection, lines are parallel.
434 * @return -1 no intersection
435 * @return 0 lines are co-linear (pdist and qdist returned) (see below)
436 * @return 1 intersection found (pdist and qdist returned) (see below)
437 *
438 * @param p0 point 1
439 * @param u direction 1
440 * @param q0 point 2
441 * @param v direction 2
442 * @param tol tolerance values
443 * @param[out] s (distances to intersection) (see below)
444 * @param[out] t (distances to intersection) (see below)
445 *
446 * When return = 1, pdist is the distance along line p0->p1 to the
447 * intersect with line q0->q1. If the intersect is along p0->p1 but
448 * in the opposite direction of vector pdir_i (i.e. occurring before
449 * p0 on line p0->p1) then the distance will be negative. The value
450 * if qdist is the same as pdist except it is the distance along line
451 * q0->q1 to the intersect with line p0->p1.
452 *
453 * When return code = 0 for co-linearity, pdist and qdist have a
454 * different meaning. pdist is the distance from point p0 to point q0
455 * and qdist is the distance from point p0 to point q1. If point q0
456 * occurs before point p0 on line segment p0->p1 then pdist will be
457 * negative. The same occurs for the distance to point q1.
458 */
459BG_EXPORT extern int bg_isect_line3_line3(fastf_t *s, fastf_t *t,
460 const point_t p0,
461 const vect_t u,
462 const point_t q0,
463 const vect_t v,
464 const struct bn_tol *tol);
465
466/**
467 * @brief
468 * Returns non-zero if the 3 lines are collinear to within tol->dist
469 * over the given distance range.
470 *
471 * Range should be at least one model diameter for most applications.
472 * 1e5 might be OK for a default for "vehicle sized" models.
473 *
474 * The direction vectors do not need to be unit length, but must be nonzero.
475 */
476BG_EXPORT extern int bg_2line3_colinear(const point_t p1,
477 const vect_t d1,
478 const point_t p2,
479 const vect_t d2,
480 double range,
481 const struct bn_tol *tol);
482
483/**
484 * @brief
485 * Intersect a point P with the line segment defined by two distinct
486 * points A and B.
487 *
488 * @return -2 P on line AB but outside range of AB,
489 * dist = parameter from A to P on line AB.
490 * @return -1 P not on line of AB within tolerance
491 * @return 1 P is at A
492 * @return 2 P is at B
493 * @return 3 P is on AB, dist = parameter from A to P on line AB.
494 @verbatim
495 B *
496 |
497 P'*-tol-*P
498 | / _
499 dist / /|
500 | / /
501 | / / AtoP
502 |/ /
503 A * /
504
505 tol = distance limit from line to pt P;
506 dist = parametric distance from A to P' (in terms of A to B)
507 @endverbatim
508*/
509BG_EXPORT extern int bg_isect_pnt2_lseg2(fastf_t *dist,
510 const point_t a,
511 const point_t b,
512 const point_t p,
513 const struct bn_tol *tol);
514
515/**
516 *@brief
517 * Intersect an infinite line in parametric form:
518 *
519 * X = P + s * D
520 *
521 * with a line segment defined by two distinct points A and B=(A+C).
522 *
523 * XXX probably should take point B, not vector C. Sigh.
524 * D must be nonzero and C must define a segment longer than tol->dist.
525 *
526 * @return -4 A and B are not distinct points
527 * @return -3 Lines do not intersect
528 * @return -2 Intersection exists, but outside segment, < A
529 * @return -1 Intersection exists, but outside segment, > B
530 * @return 0 Lines are co-linear (special meaning of dist[1])
531 * @return 1 Intersection at vertex A
532 * @return 2 Intersection at vertex B (A+C)
533 * @return 3 Intersection between A and B
534 *
535 * Implicit Returns -
536 * @param dist When explicit return >= 0, s is the parameter that describes
537 * the intersection of the line and the line segment.
538 * It may be negative because the full line is considered.
539 * The actual intersection coordinates can be found by
540 * solving P + s * D. However, note that for return codes
541 * 1 and 2 (intersection exactly at a vertex), it is
542 * strongly recommended that the original values passed in
543 * A or B are used instead of solving P + s * D, to prevent
544 * numeric error from creeping into the position of
545 * the endpoints.
546 *
547 * @param p point of first line
548 * @param d direction of first line
549 * @param a point of second line
550 * @param c direction of second line
551 * @param tol tolerance values
552 */
553BG_EXPORT extern int bg_isect_line2_lseg2(fastf_t *dist,
554 const point_t p,
555 const vect_t d,
556 const point_t a,
557 const vect_t c,
558 const struct bn_tol *tol);
559
560/**
561 *@brief
562 * Intersect two 2D line segments, defined by two points and two nonzero
563 * vectors. The vector magnitudes define the segment lengths.
564 *
565 * @return -2 missed (line segments are parallel)
566 * @return -1 missed (collinear and non-overlapping)
567 * @return 0 hit (line segments collinear and overlapping)
568 * @return 1 hit (normal intersection)
569 *
570 * @param dist The value at dist[] is set to the parametric distance of the
571 * intercept.
572 *@n dist[0] is parameter along p, range 0 to 1, to intercept.
573 *@n dist[1] is parameter along q, range 0 to 1, to intercept.
574 *@n If within distance tolerance of the endpoints, these will be
575 * exactly 0.0 or 1.0, to ease the job of caller.
576 *
577 * Special note: when return code is "0" for co-linearity, dist[1] has
578 * an alternate interpretation: it's the parameter along p (not q)
579 * which takes you from point p to the point (q + qdir), i.e., its
580 * the endpoint of the q linesegment, since in this case there may be
581 * *two* intersections, if q is contained within span p to (p + pdir).
582 * And either may be -10 if the point is outside the span.
583 *
584 * @param p point 1
585 * @param pdir direction1
586 * @param q point 2
587 * @param qdir direction2
588 * @param tol tolerance values
589 */
590BG_EXPORT extern int bg_isect_lseg2_lseg2(fastf_t *dist,
591 const point_t p,
592 const vect_t pdir,
593 const point_t q,
594 const vect_t qdir,
595 const struct bn_tol *tol);
596
597/**
598 * Intersect two lines, each in given in parametric form:
599 @verbatim
600
601 X = P + t * D
602 and
603 X = A + u * C
604
605 @endverbatim
606 *
607 * While the parametric form is usually used to denote a ray (i.e.,
608 * positive values of the parameter only), in this case the full line
609 * is considered.
610 *
611 * The direction vectors C and D need not have unit length, but must be
612 * nonzero.
613 *
614 * @return -1 no intersection, lines are parallel.
615 * @return 0 lines are co-linear
616 *@n dist[0] gives the parameter from P to A,
617 *@n dist[1] gives the parameter from P to (A+C) [not same as below]
618 * @return 1 intersection found (t and u returned)
619 *@n dist[0] gives the parameter from P to isect,
620 *@n dist[1] gives the parameter from A to isect.
621 *
622 * @param dist When explicit return > 0, dist[0] and dist[1] are the
623 * line parameters of the intersection point on the two lines. The
624 * actual intersection coordinates can be found by substituting either
625 * of these into the original line equations.
626 *
627 * @param p point of first line
628 * @param d direction of first line
629 * @param a point of second line
630 * @param c direction of second line
631 * @param tol tolerance values
632 *
633 * Note that for lines which are very nearly parallel, but not quite
634 * parallel enough to have the determinant go to "zero", the
635 * intersection can turn up in surprising places. (e.g. when
636 * det=1e-15 and det1=5.5e-17, t=0.5)
637 */
638BG_EXPORT extern int bg_isect_line2_line2(fastf_t *dist,
639 const point_t p,
640 const vect_t d,
641 const point_t a,
642 const vect_t c,
643 const struct bn_tol *tol);
644
645/**
646 * @brief
647 * Returns distance between two points.
648 */
649BG_EXPORT extern double bg_dist_pnt3_pnt3(const point_t a,
650 const point_t b);
652/**
653 * Check to see if three points are all distinct, i.e., ensure that
654 * there is at least sqrt(dist_tol_sq) distance between every pair of
655 * points.
656 *
657 * @return 1 If all three points are distinct
658 * @return 0 If two or more points are closer together than dist_tol_sq
659 */
660BG_EXPORT extern int bg_3pnts_distinct(const point_t a,
661 const point_t b,
662 const point_t c,
663 const struct bn_tol *tol);
664
665/**
666 * Check to see if the points are all distinct, i.e., ensure that
667 * there is at least sqrt(dist_tol_sq) distance between every pair of
668 * points.
669 *
670 * @return 1 If all the points are distinct
671 * @return 0 If two or more points are closer together than dist_tol_sq
672 */
673BG_EXPORT extern int bg_npnts_distinct(const int npts,
674 const point_t *pts,
675 const struct bn_tol *tol);
676
677/**
678 * Find the equation of a plane that contains three points. Note that
679 * normal vector created is expected to point out (see vmath.h), so
680 * the vector from A to C had better be counter-clockwise (about the
681 * point A) from the vector from A to B. This follows the BRL-CAD
682 * outward-pointing normal convention, and the right-hand rule for
683 * cross products.
684 *
685 @verbatim
686 *
687 * C
688 * *
689 * |\
690 * | \
691 * ^ N | \
692 * | \ | \
693 * | \ | \
694 * |C-A \ | \
695 * | \ | \
696 * | \ | \
697 * \| \
698 * *---------*
699 * A B
700 * ----->
701 * B-A
702 @endverbatim
703 *
704 * If the points are given in the order A B C (e.g.,
705 * *counter*-clockwise), then the outward pointing surface normal:
706 *
707 * N = (B-A) x (C-A).
708 *
709 * @return 0 OK
710 * @return -1 Failure. At least two of the points were not distinct,
711 * or all three were collinear.
712 *
713 * @param[out] plane The plane equation is stored here.
714 * @param[in] a point 1
715 * @param[in] b point 2
716 * @param[in] c point 3
717 * @param[in] tol Tolerance values for doing calculation
718 */
719BG_EXPORT extern int bg_make_plane_3pnts(plane_t plane,
720 const point_t a,
721 const point_t b,
722 const point_t c,
723 const struct bn_tol *tol);
724
725/**
726 *@brief
727 * Given the description of three planes, compute the point of intersection, if
728 * any. The direction vectors of the planes need not be of unit length.
729 *
730 * Find the solution to a system of three equations in three unknowns:
731 @verbatim
732 * Px * Ax + Py * Ay + Pz * Az = -A3;
733 * Px * Bx + Py * By + Pz * Bz = -B3;
734 * Px * Cx + Py * Cy + Pz * Cz = -C3;
735 *
736 * OR
737 *
738 * [ Ax Ay Az ] [ Px ] [ -A3 ]
739 * [ Bx By Bz ] * [ Py ] = [ -B3 ]
740 * [ Cx Cy Cz ] [ Pz ] [ -C3 ]
741 *
742 @endverbatim
743 *
744 * @return 0 OK
745 * @return -1 Failure. Intersection is a line or plane.
746 *
747 * @param[out] pt The point of intersection is stored here.
748 * @param a plane 1
749 * @param b plane 2
750 * @param c plane 3
751 */
752
753BG_EXPORT extern int bg_make_pnt_3planes(point_t pt,
754 const plane_t a,
755 const plane_t b,
756 const plane_t c);
757
758/**
759 * Intersect an infinite line (specified in point and direction vector
760 * form) with a plane that has an outward pointing normal. The
761 * direction vector need not have unit length. The first three
762 * elements of the plane equation must form a unit length vector.
763 *
764 * @return -2 missed (ray is outside halfspace)
765 * @return -1 missed (ray is inside)
766 * @return 0 line lies on plane
767 * @return 1 hit (ray is entering halfspace)
768 * @return 2 hit (ray is leaving)
769 *
770 * @param[out] dist set to the parametric distance of the intercept
771 * @param[in] pt origin of ray
772 * @param[in] dir direction of ray
773 * @param[in] plane equation of plane
774 * @param[in] tol tolerance values
775 */
776BG_EXPORT extern int bg_isect_line3_plane(fastf_t *dist,
777 const point_t pt,
778 const vect_t dir,
779 const plane_t plane,
780 const struct bn_tol *tol);
781
782/**
783 *@brief
784 * Given two planes, find the line of intersection between them, if
785 * one exists. The line of intersection is returned in parametric
786 * line (point & direction vector) form.
787 *
788 * In order that all the geometry under consideration be in "front" of
789 * the ray, it is necessary to pass the minimum point of the model
790 * RPP. If this convention is unnecessary, just pass (0, 0, 0) as
791 * rpp_min.
792 *
793 * @return 0 success, line of intersection stored in 'pt' and 'dir'
794 * @return -1 planes are coplanar
795 * @return -2 planes are parallel but not coplanar
796 * @return -3 error, should be intersection but unable to find
797 *
798 * @param[out] pt Starting point of line of intersection
799 * @param[out] dir Direction vector of line of intersection (unit length)
800 * @param[in] a plane 1 (normal must be unit length)
801 * @param[in] b plane 2 (normal must be unit length)
802 * @param[in] rpp_min minimum point of model RPP
803 * @param[in] tol tolerance values
804 */
805BG_EXPORT extern int bg_isect_2planes(point_t pt,
806 vect_t dir,
807 const plane_t a,
808 const plane_t b,
809 const vect_t rpp_min,
810 const struct bn_tol *tol);
811BG_EXPORT extern int bg_isect_2lines(fastf_t *t,
812 fastf_t *u,
813 const point_t p,
814 const vect_t d,
815 const point_t a,
816 const vect_t c,
817 const struct bn_tol *tol);
818
819/**
820 *@brief
821 * Intersect a line in parametric form:
822 *
823 * X = P + t * D
824 *
825 * with a line segment defined by two distinct points A and B.
826 *
827 *
828 * @return -4 A and B are not distinct points
829 * @return -3 Intersection exists, < A (t is returned)
830 * @return -2 Intersection exists, > B (t is returned)
831 * @return -1 Lines do not intersect
832 * @return 0 Lines are co-linear (t for A is returned)
833 * @return 1 Intersection at vertex A
834 * @return 2 Intersection at vertex B
835 * @return 3 Intersection between A and B
836 *
837 * Implicit Returns -
838 *
839 * When explicit return >= 0, t is the Euclidean distance along the ray,
840 * not the coefficient s in P + s * D. The actual intersection coordinates
841 * can be found by adding t times the unitized D to P. D must be nonzero.
842 * However, note that for return codes 1 and 2 (intersection exactly
843 * at a vertex), it is strongly recommended that the original values
844 * passed in A or B are used instead of computing P + t * unit(D), to prevent
845 * numeric error from creeping into the position of the endpoints.
846 *
847 * XXX should probably be called bg_isect_line3_lseg3()
848 * XXX should probably be changed to return dist[2]
849 */
850BG_EXPORT extern int bg_isect_line_lseg(fastf_t *t, const point_t p,
851 const vect_t d,
852 const point_t a,
853 const point_t b,
854 const struct bn_tol *tol);
855
856/**
857 * Given a parametric line defined by PT + t * DIR and a point A,
858 * return the closest distance between the line and the point.
859 *
860 * 'dir' need not have unit length. A zero direction is treated as a
861 * degenerate line located at PT.
862 *
863 * Find parameter for PCA along line with unitized DIR:
864 * d = VDOT(f, dir) / MAGNITUDE(dir);
865 * Find distance g from PCA to A using Pythagoras:
866 * g = sqrt(MAGSQ(f) - d**2)
867 *
868 * Return -
869 * Distance
870 */
871BG_EXPORT extern double bg_dist_line3_pnt3(const point_t pt,
872 const vect_t dir,
873 const point_t a);
874
875/**
876 * Given a parametric line defined by PT + t * DIR and a point A,
877 * return the square of the closest distance between the line and the
878 * point.
879 *
880 * 'dir' need not have unit length. A zero direction is treated as a
881 * degenerate line located at PT.
882 *
883 * Return -
884 * Distance squared
885 */
886BG_EXPORT extern double bg_distsq_line3_pnt3(const point_t pt,
887 const vect_t dir,
888 const point_t a);
889
890/**
891 *@brief
892 * Given a parametric line defined by PT + t * DIR, return the closest
893 * distance between the line and the origin.
894 *
895 * 'dir' need not have unit length. A zero direction is treated as a
896 * degenerate line located at PT.
897 *
898 * @return Distance
899 */
900BG_EXPORT extern double bg_dist_line_origin(const point_t pt,
901 const vect_t dir);
903/**
904 *@brief
905 * Given a parametric line defined by PT + t * DIR and a point A,
906 * return the closest distance between the line and the point.
907 *
908 * 'dir' need not have unit length. A zero direction is treated as a
909 * degenerate line located at PT.
910 *
911 * @return Distance
912 */
913BG_EXPORT extern double bg_dist_line2_point2(const point_t pt,
914 const vect_t dir,
915 const point_t a);
916
917/**
918 *@brief
919 * Given a parametric line defined by PT + t * DIR and a point A,
920 * return the closest distance between the line and the point,
921 * squared.
922 *
923 * 'dir' need not have unit length. A zero direction is treated as a
924 * degenerate line located at PT.
925 *
926 * @return
927 * Distance squared
928 */
929BG_EXPORT extern double bg_distsq_line2_point2(const point_t pt,
930 const vect_t dir,
931 const point_t a);
932
933/**
934 *@brief
935 * Returns the area of a triangle. Algorithm by Jon Leech 3/24/89.
936 */
937BG_EXPORT extern double bg_area_of_triangle(const point_t a,
938 const point_t b,
939 const point_t c);
940
941/**
942 *@brief
943 * Intersect a point P with the line segment defined by two distinct
944 * points A and B.
945 *
946 * @return -2 P on line AB but outside range of AB,
947 * dist = parameter from A to P on line AB.
948 * @return -1 P not on line of AB within tolerance
949 * @return 1 P is at A
950 * @return 2 P is at B
951 * @return 3 P is on AB, dist = parameter from A to P on line AB.
952 @verbatim
953 B *
954 |
955 P'*-tol-*P
956 | / _
957 dist / /|
958 | / /
959 | / / AtoP
960 |/ /
961 A * /
962
963 tol = distance limit from line to pt P;
964 dist = parametric distance from A to P' (in terms of A to B)
965 @endverbatim
966 *
967 * @param p point
968 * @param a start of lseg
969 * @param b end of lseg
970 * @param tol tolerance values
971 * @param[out] dist parametric distance from A to P' (in terms of A to B)
972 */
973BG_EXPORT extern int bg_isect_pnt_lseg(fastf_t *dist,
974 const point_t a,
975 const point_t b,
976 const point_t p,
977 const struct bn_tol *tol);
978
979BG_EXPORT extern double bg_dist_pnt_lseg(point_t pca,
980 const point_t a,
981 const point_t b,
982 const point_t p,
983 const struct bn_tol *tol);
984
985/**
986 *@brief
987 * Transform a bounding box (RPP) by the given 4x4 matrix. There are
988 * 8 corners to the bounding RPP. Each one needs to be transformed
989 * and min/max'ed. This is not minimal, but does fully contain any
990 * internal object, using an axis-aligned RPP.
991 */
992BG_EXPORT extern void bg_rotate_bbox(point_t omin,
993 point_t omax,
994 const mat_t mat,
995 const point_t imin,
996 const point_t imax);
997
998/**
999 *@brief
1000 * Transform a plane equation by the given 4x4 matrix.
1001 */
1002BG_EXPORT extern void bg_rotate_plane(plane_t oplane,
1003 const mat_t mat,
1004 const plane_t iplane);
1005
1006/**
1007 *@brief
1008 * Test if two planes are identical. If so, their dot products will
1009 * be either +1 or -1, with the distance from the origin equal in
1010 * magnitude.
1011 *
1012 * @return -1 not coplanar, parallel but distinct
1013 * @return 0 not coplanar, not parallel. Planes intersect.
1014 * @return 1 coplanar, same normal direction
1015 * @return 2 coplanar, opposite normal direction
1016 */
1017BG_EXPORT extern int bg_coplanar(const plane_t a,
1018 const plane_t b,
1019 const struct bn_tol *tol);
1020
1021
1022
1023/**
1024 *@brief
1025 * Test if a set of points are coplanar. Note: if 0 < pt_cnt <=3 the point(s)
1026 * are trivially coplanar, and 1 will be returned.
1027 *
1028 * @return -1 error
1029 * @return 0 not coplanar
1030 * @return 1 coplanar
1031 */
1032BG_EXPORT extern int bg_coplanar_pts(const point_t *pts,
1033 int pt_cnt,
1034 const struct bn_tol *tol);
1035
1036
1037/**
1038 * Using two perpendicular vectors (x_dir and y_dir) which lie in the
1039 * same plane as 'vec', return the angle (in radians) of 'vec' from
1040 * x_dir, going CCW around the perpendicular x_dir CROSS y_dir.
1041 *
1042 * Trig note -
1043 *
1044 * theta = atan2(x, y) returns an angle in the range -pi to +pi.
1045 * Here, we need an angle in the range of 0 to 2pi. This could be
1046 * implemented by adding 2pi to theta when theta is negative, but this
1047 * could have nasty numeric ambiguity right in the vicinity of theta =
1048 * +pi, which is a very critical angle for the applications using this
1049 * routine.
1050 *
1051 * So, an alternative formulation is to compute gamma = atan2(-x, -y),
1052 * and then theta = gamma + pi. Now, any error will occur in the
1053 * vicinity of theta = 0, which can be handled much more readily.
1054 *
1055 * If theta is negative, or greater than two pi, wrap it around.
1056 * These conditions only occur if there are problems in atan2().
1057 *
1058 * @return vec == x_dir returns 0,
1059 * @return vec == y_dir returns pi/2,
1060 * @return vec == -x_dir returns pi,
1061 * @return vec == -y_dir returns 3*pi/2.
1062 *
1063 * In all cases, the returned value is between 0 and bg_twopi.
1064 */
1065BG_EXPORT extern double bg_angle_measure(vect_t vec,
1066 const vect_t x_dir,
1067 const vect_t y_dir);
1068
1069/**
1070 *@brief
1071 * Return the parametric distance t of a point X along a line defined
1072 * as a ray, i.e. solve X = P + t * D. If the point X does not lie on
1073 * the line, then t is the distance of the perpendicular projection of
1074 * point X onto the line. D need not have unit length. A zero D returns
1075 * 0.0 because the degenerate line has no unique parameter.
1076 */
1077BG_EXPORT extern double bg_dist_pnt3_along_line3(const point_t p,
1078 const vect_t d,
1079 const point_t x);
1080
1081/**
1082 *@brief
1083 * Return the parametric distance t of a point X along a line defined
1084 * as a ray, i.e. solve X = P + t * D. If the point X does not lie on
1085 * the line, then t is the distance of the perpendicular projection of
1086 * point X onto the line. D need not have unit length. A zero D returns
1087 * 0.0 because the degenerate line has no unique parameter.
1088 */
1089BG_EXPORT extern double bg_dist_pnt2_along_line2(const point_t p,
1090 const vect_t d,
1091 const point_t x);
1092
1093/**
1094 *
1095 * @return 1 if left <= mid <= right
1096 * @return 0 if mid is not in the range.
1097 */
1098BG_EXPORT extern int bg_between(double left,
1099 double mid,
1100 double right,
1101 const struct bn_tol *tol);
1102
1103/**
1104 * @deprecated Use bg_isect_tri_line.
1105 *
1106 * Test whether the infinite line pt + t * dir intersects a triangle. The
1107 * output point is the final argument for historical compatibility.
1108 *
1109 * @return 0 No intersection
1110 * @return 1 Intersection, 'inter' has intersect point.
1111 */
1112DEPRECATED BG_EXPORT extern int bg_does_ray_isect_tri(const point_t pt,
1113 const vect_t dir,
1114 const point_t V,
1115 const point_t A,
1116 const point_t B,
1117 point_t inter);
1118
1119/**
1120 *@brief
1121 * Classify a halfspace, specified by its plane equation, against a
1122 * bounding RPP.
1123 *
1124 * @return BG_CLASSIFY_INSIDE
1125 * @return BG_CLASSIFY_OVERLAPPING
1126 * @return BG_CLASSIFY_OUTSIDE
1127 */
1128BG_EXPORT extern int bg_hlf_class(const plane_t half_eqn,
1129 const vect_t min, const vect_t max,
1130 const struct bn_tol *tol);
1131
1132
1133#define BG_CLASSIFY_UNIMPLEMENTED 0x0000
1134#define BG_CLASSIFY_INSIDE 0x0001
1135#define BG_CLASSIFY_OVERLAPPING 0x0002
1136#define BG_CLASSIFY_OUTSIDE 0x0003
1139/**
1140 *@brief
1141 * Calculates the point that is the minimum distance from all the
1142 * planes in the "planes" array. If the planes intersect at a single
1143 * point, that point is the solution.
1144 *
1145 * The method used here is based on:
1146
1147 * An expression for the distance from a point to a plane is:
1148 * VDOT(pt, plane)-plane[H].
1149 * Square that distance and sum for all planes to get the "total"
1150 * distance.
1151 * For minimum total distance, the partial derivatives of this
1152 * expression (with respect to x, y, and z) must all be zero.
1153 * This produces a set of three equations in three unknowns (x, y, z).
1154
1155 * This routine sets up the three equations as [matrix][pt] = [hpq]
1156 * and solves by inverting "matrix" into "inverse" and
1157 * [pt] = [inverse][hpq].
1158 *
1159 * There is likely a more economical solution rather than matrix
1160 * inversion, but bg_mat_inv was handy at the time.
1161 *
1162 * Checks if these planes form a singular matrix and returns.
1163 *
1164 * @return 0 - all is well
1165 * @return 1 - planes form a singular matrix (no solution)
1166 */
1167BG_EXPORT extern int bg_isect_planes(point_t pt,
1168 const plane_t planes[],
1169 const size_t pl_count);
1170
1171
1172/**
1173 * @brief
1174 * Given an origin and a normal, create a plane_t.
1175 */
1176BG_EXPORT extern int bg_plane_pt_nrml(plane_t *p, point_t pt, vect_t nrml);
1177
1179 * @brief
1180 * Calculates the best fit plane for a set of points
1181 *
1182 * Use SVD algorithm from Soderkvist to fit a plane to vertex points
1183 * https://www.ltu.se/cms_fs/1.51590!/svd-fitting.pdf
1184 *
1185 * Returns a center point and a normal direction for the plane
1186 */
1187BG_EXPORT extern int bg_fit_plane(point_t *c, vect_t *n, size_t npnts, point_t *pnts);
1188
1190 * @brief
1191 * Find the closest U,V point on the plane p to 3d point pt.
1192 */
1193BG_EXPORT extern int bg_plane_closest_pt(fastf_t *u, fastf_t *v, plane_t *p, point_t *pt);
1194
1196 * @brief
1197 * Return the 3D point on the plane at parametric coordinates u, v.
1198 */
1199BG_EXPORT extern int bg_plane_pt_at(point_t *pt, plane_t *p, fastf_t u, fastf_t v);
1200
1202
1203__END_DECLS
1204
1205#endif /* BG_PLANE_H */
1206/** @} */
1207/*
1208 * Local Variables:
1209 * mode: C
1210 * tab-width: 8
1211 * indent-tabs-mode: t
1212 * c-file-style: "stroustrup"
1213 * End:
1214 * ex: shiftwidth=4 tabstop=8
1215 */
Header file for the BRL-CAD common definitions.
int bg_make_pnt_3planes(point_t pt, const plane_t a, const plane_t b, const plane_t c)
Given the description of three planes, compute the point of intersection, if any. The direction vecto...
int bg_plane_pt_at(point_t *pt, plane_t *p, fastf_t u, fastf_t v)
Return the 3D point on the plane at parametric coordinates u, v.
int bg_pnt3_pnt3_equal(const point_t a, const point_t b, const struct bn_tol *tol)
int bg_isect_line3_line3(fastf_t *s, fastf_t *t, const point_t p0, const vect_t u, const point_t q0, const vect_t v, const struct bn_tol *tol)
int bg_plane_pt_nrml(plane_t *p, point_t pt, vect_t nrml)
Given an origin and a normal, create a plane_t.
int bg_isect_line_lseg(fastf_t *t, const point_t p, const vect_t d, const point_t a, const point_t b, const struct bn_tol *tol)
Intersect a line in parametric form:
int bg_coplanar(const plane_t a, const plane_t b, const struct bn_tol *tol)
Test if two planes are identical. If so, their dot products will be either +1 or -1,...
double bg_dist_pnt3_along_line3(const point_t p, const vect_t d, const point_t x)
Return the parametric distance t of a point X along a line defined as a ray, i.e. solve X = P + t * D...
int bg_plane_closest_pt(fastf_t *u, fastf_t *v, plane_t *p, point_t *pt)
Find the closest U,V point on the plane p to 3d point pt.
int bg_isect_2lines(fastf_t *t, fastf_t *u, const point_t p, const vect_t d, const point_t a, const vect_t c, const struct bn_tol *tol)
int bg_isect_planes(point_t pt, const plane_t planes[], const size_t pl_count)
Calculates the point that is the minimum distance from all the planes in the "planes" array....
double bg_dist_line_origin(const point_t pt, const vect_t dir)
Given a parametric line defined by PT + t * DIR, return the closest distance between the line and the...
int bg_distsq_pnt3_lseg3_v2(fastf_t *distsq, const fastf_t *a, const fastf_t *b, const fastf_t *p, const struct bn_tol *tol)
int bg_dist_line3_line3(fastf_t dist[2], const point_t p1, const vect_t d1, const point_t p2, const vect_t d2, const struct bn_tol *tol)
int bg_isect_line3_plane(fastf_t *dist, const point_t pt, const vect_t dir, const plane_t plane, const struct bn_tol *tol)
void bg_rotate_plane(plane_t oplane, const mat_t mat, const plane_t iplane)
Transform a plane equation by the given 4x4 matrix.
double bg_dist_line2_point2(const point_t pt, const vect_t dir, const point_t a)
Given a parametric line defined by PT + t * DIR and a point A, return the closest distance between th...
double bg_dist_pnt2_along_line2(const point_t p, const vect_t d, const point_t x)
Return the parametric distance t of a point X along a line defined as a ray, i.e. solve X = P + t * D...
double bg_dist_pnt3_pnt3(const point_t a, const point_t b)
Returns distance between two points.
int bg_hlf_class(const plane_t half_eqn, const vect_t min, const vect_t max, const struct bn_tol *tol)
Classify a halfspace, specified by its plane equation, against a bounding RPP.
double bg_area_of_triangle(const point_t a, const point_t b, const point_t c)
Returns the area of a triangle. Algorithm by Jon Leech 3/24/89.
int bg_3pnts_distinct(const point_t a, const point_t b, const point_t c, const struct bn_tol *tol)
int bg_lseg3_lseg3_parallel(const point_t sg1pt1, const point_t sg1pt2, const point_t sg2pt1, const point_t sg2pt2, const struct bn_tol *tol)
int bg_make_plane_3pnts(plane_t plane, const point_t a, const point_t b, const point_t c, const struct bn_tol *tol)
double bg_dist_pnt_lseg(point_t pca, const point_t a, const point_t b, const point_t p, const struct bn_tol *tol)
int bg_2line3_colinear(const point_t p1, const vect_t d1, const point_t p2, const vect_t d2, double range, const struct bn_tol *tol)
Returns non-zero if the 3 lines are collinear to within tol->dist over the given distance range.
int bg_isect_pnt2_lseg2(fastf_t *dist, const point_t a, const point_t b, const point_t p, const struct bn_tol *tol)
Intersect a point P with the line segment defined by two distinct points A and B.
#define MAXPTS
Definition plane.h:46
DEPRECATED int bg_does_ray_isect_tri(const point_t pt, const vect_t dir, const point_t V, const point_t A, const point_t B, point_t inter)
int bg_3pnts_collinear(point_t a, point_t b, point_t c, const struct bn_tol *tol)
Check to see if three points are collinear.
double bg_distsq_line3_pnt3(const point_t pt, const vect_t dir, const point_t a)
double bg_dist_line3_pnt3(const point_t pt, const vect_t dir, const point_t a)
int bg_isect_lseg2_lseg2(fastf_t *dist, const point_t p, const vect_t pdir, const point_t q, const vect_t qdir, const struct bn_tol *tol)
Intersect two 2D line segments, defined by two points and two nonzero vectors. The vector magnitudes ...
int bg_between(double left, double mid, double right, const struct bn_tol *tol)
void bg_rotate_bbox(point_t omin, point_t omax, const mat_t mat, const point_t imin, const point_t imax)
Transform a bounding box (RPP) by the given 4x4 matrix. There are 8 corners to the bounding RPP....
int bg_fit_plane(point_t *c, vect_t *n, size_t npnts, point_t *pnts)
Calculates the best fit plane for a set of points.
int bg_dist_pnt2_lseg2(fastf_t *dist_sq, fastf_t pca[2], const point_t a, const point_t b, const point_t p, const struct bn_tol *tol)
Find the distance from a point P to a line segment described by the two endpoints A and B,...
int bg_coplanar_pts(const point_t *pts, int pt_cnt, const struct bn_tol *tol)
Test if a set of points are coplanar. Note: if 0 < pt_cnt <=3 the point(s) are trivially coplanar,...
int bg_dist_pnt3_lseg3(fastf_t *dist, point_t pca, const point_t a, const point_t b, const point_t p, const struct bn_tol *tol)
Find the distance from a point P to a line segment described by the two endpoints A and B,...
int bg_distsq_line3_line3(fastf_t dist[3], const point_t P, const vect_t d, const point_t Q, const vect_t e, point_t pt1, point_t pt2)
Calculate the square of the distance of closest approach for two lines.
int bg_isect_line2_line2(fastf_t *dist, const point_t p, const vect_t d, const point_t a, const vect_t c, const struct bn_tol *tol)
int bg_isect_line2_lseg2(fastf_t *dist, const point_t p, const vect_t d, const point_t a, const vect_t c, const struct bn_tol *tol)
Intersect an infinite line in parametric form:
double bg_angle_measure(vect_t vec, const vect_t x_dir, const vect_t y_dir)
int bg_npnts_distinct(const int npts, const point_t *pts, const struct bn_tol *tol)
double bg_distsq_line2_point2(const point_t pt, const vect_t dir, const point_t a)
Given a parametric line defined by PT + t * DIR and a point A, return the closest distance between th...
int bg_isect_pnt_lseg(fastf_t *dist, const point_t a, const point_t b, const point_t p, const struct bn_tol *tol)
Intersect a point P with the line segment defined by two distinct points A and B.
int bg_dist_line3_lseg3(fastf_t *dist, const fastf_t *p, const fastf_t *d, const fastf_t *a, const fastf_t *b, const struct bn_tol *tol)
int bg_isect_lseg3_lseg3(fastf_t *dist, const point_t p, const vect_t pdir, const point_t q, const vect_t qdir, const struct bn_tol *tol)
Intersect two 3D line segments, defined by two points and two nonzero vectors. The vector magnitudes ...
int bg_dist_pnt3_line3(fastf_t *dist, point_t pca, const point_t a, const vect_t dir, const point_t p, const struct bn_tol *tol)
int bg_isect_2planes(point_t pt, vect_t dir, const plane_t a, const plane_t b, const vect_t rpp_min, const struct bn_tol *tol)
Given two planes, find the line of intersection between them, if one exists. The line of intersection...
#define DEPRECATED
Definition common.h:439
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition vmath.h:351
double fastf_t
fastest 64-bit (or larger) floating point type
Definition vmath.h:336
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:372
fastf_t plane_t[ELEMENTS_PER_PLANE]
Definition of a plane equation.
Definition vmath.h:399
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:357
Definition tol.h:72
char pl_code[MAXPTS+1]
Definition plane.h:60
fastf_t pl_2d_x[MAXPTS]
Definition plane.h:56
fastf_t pl_2d_com[MAXPTS]
Definition plane.h:58
size_t pl_npts
Definition plane.h:50
struct plane_specific * pl_forw
Definition plane.h:59
vect_t pl_Xbasis
Definition plane.h:52
vect_t pl_Ybasis
Definition plane.h:53
fastf_t pl_NdotA
Definition plane.h:55
point_t pl_points[MAXPTS]
Definition plane.h:51
fastf_t pl_2d_y[MAXPTS]
Definition plane.h:57
vect_t pl_N
Definition plane.h:54
float tri_A[3]
Definition plane.h:85
float tri_BA[3]
Definition plane.h:86
signed char * tri_normals
Definition plane.h:90
float tri_wn[3]
Definition plane.h:88
float tri_N[3]
Definition plane.h:89
struct tri_float_specific * tri_forw
Definition plane.h:92
float tri_CA[3]
Definition plane.h:87
int tri_surfno
Definition plane.h:75
fastf_t * tri_normals
Definition plane.h:74
vect_t tri_N
Definition plane.h:73
vect_t tri_BA
Definition plane.h:70
vect_t tri_CA
Definition plane.h:71
vect_t tri_wn
Definition plane.h:72
point_t tri_A
Definition plane.h:69
struct tri_specific * tri_forw
Definition plane.h:76
fundamental vector, matrix, quaternion math macros