Revision: 40995
http://brlcad.svn.sourceforge.net/brlcad/?rev=40995&view=rev
Author: r_weiss
Date: 2010-10-14 22:24:32 +0000 (Thu, 14 Oct 2010)
Log Message:
-----------
Updated function bn_coplanar. Improved the algorithm, used distance tolerance
for testing for coplanar, used a very tight tolerance (<= SMALL_FASTF) for
testing for parallel. Since these are planes, if they are not as close to
parallel as we can measure then they will intersect. Added bu_bomb for invalid
input. The input test will slow things down some but, for now, it is better
than cascade failure.
Modified Paths:
--------------
brlcad/trunk/src/libbn/plane.c
Modified: brlcad/trunk/src/libbn/plane.c
===================================================================
--- brlcad/trunk/src/libbn/plane.c 2010-10-14 21:07:56 UTC (rev 40994)
+++ brlcad/trunk/src/libbn/plane.c 2010-10-14 22:24:32 UTC (rev 40995)
@@ -2191,33 +2191,30 @@
{
register fastf_t f;
register fastf_t dot;
-
+ vect_t pt_a, pt_b;
+
BN_CK_TOL(tol);
- /* Check to see if the planes are parallel */
dot = VDOT(a, b);
- if (dot >= 0) {
- /* Normals head in generally the same directions */
- if (dot < tol->para)
- return 0; /* Planes intersect */
+ VSCALE(pt_a, a, a[3]);
+ VSCALE(pt_b, b, b[3]);
- /* Planes have "exactly" the same normal vector */
- f = a[3] - b[3];
- if (NEAR_ZERO(f, tol->dist)) {
- return 1; /* Coplanar, same direction */
- }
- return -1; /* Parallel but distinct */
+ if (NEAR_ZERO(MAGSQ(pt_a), SQRT_SMALL_FASTF) || NEAR_ZERO(MAGSQ(pt_b),
SQRT_SMALL_FASTF)) {
+ bu_bomb("bn_coplanar(): zero magnitude input vector\n");
}
- /* Normals head in generally opposite directions */
- if (-dot < tol->para)
- return 0; /* Planes intersect */
- /* Planes have "exactly" opposite normal vectors */
- f = a[3] + b[3];
- if (NEAR_ZERO(f, tol->dist)) {
- return 2; /* Coplanar, opposite directions */
+ if ((dot < 0) ? (-dot >= (1 - SMALL_FASTF)) : (dot >= (1 - SMALL_FASTF)))
{ /* test for parallel */
+ if (bn_pt3_pt3_equal(pt_a, pt_b, tol)) { /* test for coplanar */
+ if ( dot > 0 ) { /* test normals in same direction */
+ return 1;
+ } else {
+ return 2;
+ }
+ } else {
+ return -1;
+ }
}
- return -1; /* Parallel but distinct */
+ return 0;
}
/**
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits