[Plib-cvs] plib/src/sg sg.cxx,1.31,1.32 sg.h,1.33,1.34
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-06-12 05:45:16
|
Update of /cvsroot/plib/plib/src/sg In directory usw-pr-cvs1:/tmp/cvs-serv24219/plib/src/sg Modified Files: sg.cxx sg.h Log Message: Some fixes for sgTriangleSolver. ASS-to-SAA still fails for obtuse triangles (grrr!). Index: sg.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/sg/sg.cxx,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- sg.cxx 10 Jun 2002 05:42:33 -0000 1.31 +++ sg.cxx 12 Jun 2002 05:45:13 -0000 1.32 @@ -1701,7 +1701,7 @@ { /* Get the third angle */ - SGfloat angB = SG_180 - angA - angC ; + SGfloat angB = SG_180 - (angA + angC) ; /* Use Sine Rule to get length of a second side - then use SAStoArea. */ @@ -1756,7 +1756,6 @@ void sgTriangleSolver_SSStoAAA ( SGfloat lenA, SGfloat lenB, SGfloat lenC, SGfloat *angA, SGfloat *angB, SGfloat *angC ) { - SGfloat twoK = SG_TWO * sgTriangleSolver_SSStoArea ( lenA, lenB, lenC ) ; SGfloat aa, bb, cc ; int flag = ( lenA == SG_ZERO ) | @@ -1770,9 +1769,10 @@ switch ( flag ) { case 0 : /* no zero-lengthed sides */ - aa = sgASin ( twoK / ( lenB * lenC ) ) ; - bb = sgASin ( twoK / ( lenC * lenA ) ) ; - cc = sgASin ( twoK / ( lenA * lenB ) ) ; + /* Cosine law */ + aa = sgACos (( lenB*lenB + lenC*lenC - lenA*lenA )/(SG_TWO*lenB*lenC)) ; + bb = sgACos (( lenA*lenA + lenC*lenC - lenB*lenB )/(SG_TWO*lenA*lenC)) ; + cc = sgACos (( lenA*lenA + lenB*lenB - lenC*lenC )/(SG_TWO*lenA*lenB)) ; break ; case 1 : /* lenA is zero */ @@ -1818,14 +1818,7 @@ if ( lenB ) *lenB = lb ; - /* Get Area using SAStoArea */ - - SGfloat twoK = SG_TWO * sgTriangleSolver_SAStoArea ( lenA, angB, lenC ) ; - - if ( angA ) *angA = (lb*lenC == SG_ZERO ) ? SG_ZERO : - sgASin ( twoK / ( lb * lenC ) ) ; - if ( angC ) *angC = (lb*lenA == SG_ZERO ) ? SG_ZERO : - sgASin ( twoK / ( lb * lenA ) ) ; + sgTriangleSolver_SSStoAAA ( lenA, lenB, lenC, angA, NULL, angC ) ; } @@ -1834,7 +1827,7 @@ { /* Find the missing angle */ - SGfloat bb = SG_180 - angA - angC ; + SGfloat bb = SG_180 - (angA + angC) ; if ( angB ) *angB = bb ; @@ -1865,7 +1858,7 @@ /* Find the missing angle */ - SGfloat cc = SG_180 - aa - angB ; + SGfloat cc = SG_180 - (aa + angB) ; if ( angC ) *angC = cc ; @@ -1879,11 +1872,11 @@ { /* Find the missing angle */ - SGfloat cc = SG_180 - angB - angA ; + SGfloat cc = SG_180 - (angB + angA) ; if ( angC ) *angC = cc ; - sgTriangleSolver_ASAtoSAS ( cc, lenA, angB, lenB, NULL, lenC ) ; + sgTriangleSolver_ASAtoSAS ( cc, lenA, angB, lenC, NULL, lenB ) ; } Index: sg.h =================================================================== RCS file: /cvsroot/plib/plib/src/sg/sg.h,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- sg.h 10 Jun 2002 05:42:34 -0000 1.33 +++ sg.h 12 Jun 2002 05:45:13 -0000 1.34 @@ -866,7 +866,9 @@ // Fast code. Result is in the range 0..pi: inline SGfloat sgAngleBetweenNormalizedVec3 ( sgVec3 v1, sgVec3 v2 ) { - return (float)(acos(sgScalarProductVec3(v1,v2))*SG_RADIANS_TO_DEGREES) ; + float f = sgScalarProductVec3 ( v1, v2 ) ; + + return (float)(acos((f>=1.0f)?1.0f:(f<=-1.0f)?-1.0f:f)*SG_RADIANS_TO_DEGREES) ; } // Fast code. Result is in the range 0..pi: |