[Plib-cvs] plib/src/sg sg.cxx,1.29,1.30 sg.h,1.31,1.32
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-06-10 03:46:56
|
Update of /cvsroot/plib/plib/src/sg In directory usw-pr-cvs1:/tmp/cvs-serv28169/plib/src/sg Modified Files: sg.cxx sg.h Log Message: Added sgTriangleSolver functions. Index: sg.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/sg/sg.cxx,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- sg.cxx 12 Apr 2002 14:49:26 -0000 1.29 +++ sg.cxx 10 Jun 2002 03:46:52 -0000 1.30 @@ -24,6 +24,38 @@ #include "sg.h" +/* Type-casted sqrt and sin/cos/tan/asin/acos/atan2 ARGUMENTS IN DEGREES */ + +inline SGDfloat sgdASin ( SGDfloat s ) + { return (SGDfloat) asin ( s ) * SGD_RADIANS_TO_DEGREES ; } +inline SGDfloat sgdACos ( SGDfloat s ) + { return (SGDfloat) acos ( s ) * SGD_RADIANS_TO_DEGREES ; } +inline SGDfloat sgdATan ( SGDfloat s ) + { return (SGDfloat) atan ( s ) * SGD_RADIANS_TO_DEGREES ; } [...316 lines suppressed...] + SGfloat bb = SG_180 - angA - angC ; + + if ( angB ) *angB = bb ; + + /* Use Sine Rule */ + + SGfloat sinB = sgSin ( bb ) ; + + if ( sinB == SG_ZERO ) + { + if ( lenA ) *lenA = lenB / SG_TWO ; /* One valid interpretation */ + if ( lenC ) *lenC = lenB / SG_TWO ; + } + else + { + if ( lenA ) *lenA = lenB * sgSin(angA) / sinB ; + if ( lenC ) *lenC = lenB * sgSin(angC) / sinB ; + } +} + Index: sg.h =================================================================== RCS file: /cvsroot/plib/plib/src/sg/sg.h,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- sg.h 25 Jan 2002 16:28:00 -0000 1.31 +++ sg.h 10 Jun 2002 03:46:52 -0000 1.32 @@ -36,6 +36,8 @@ #define SG_TWO 2.0f #define SG_THREE 3.0f #define SG_45 45.0f +#define SG_60 60.0f +#define SG_90 90.0f #define SG_180 180.0f #define SG_MAX FLT_MAX @@ -1310,9 +1312,12 @@ #define SGD_TWO 2.0 #define SGD_THREE 3.0 #define SGD_45 45.0 +#define SGD_60 60.0 +#define SGD_90 90.0 #define SGD_180 180.0 #define SGD_MAX DBL_MAX + #define SGD_X 0 #define SGD_Y 1 #define SGD_Z 2 @@ -2541,18 +2546,47 @@ */ int sgdIsectPlanePlane ( sgdVec3 point, sgdVec3 dir, - sgdVec4 plane1, sgdVec4 plane2 ) ; + sgdVec4 plane1, sgdVec4 plane2 ) ; int sgdIsectInfLinePlane ( sgdVec3 dst, - sgdVec3 l_org, sgdVec3 l_vec, - sgdVec4 plane ) ; + sgdVec3 l_org, sgdVec3 l_vec, + sgdVec4 plane ) ; int sgdIsectInfLineInfLine ( sgdVec3 dst, - sgdVec3 l1_org, sgdVec3 l1_vec, - sgdVec3 l2_org, sgdVec3 l2_vec ) ; + sgdVec3 l1_org, sgdVec3 l1_vec, + sgdVec3 l2_org, sgdVec3 l2_vec ) ; SGDfloat sgdIsectLinesegPlane ( sgdVec3 dst, - sgdVec3 v1, sgdVec3 v2, - sgdVec4 plane ) ; + sgdVec3 v1, sgdVec3 v2, + sgdVec4 plane ) ; bool sgdPointInTriangle ( sgdVec3 point, sgdVec3 tri[3] ); + +/* + TRIANGLE SOLVERS - These work for any triangle. + + SSS == Side-lengths for all three sides. + SAS == Side-lengths for two sides - plus the angle between them. + ASA == Two angles plus the length of the Side between them. + Area == The area of the triangle. +*/ + +SGfloat sgTriangleSolver_ASAtoArea ( SGfloat angA, SGfloat lenB, SGfloat angC ); +SGfloat sgTriangleSolver_SAStoArea ( SGfloat lenA, SGfloat angB, SGfloat lenC ); +SGfloat sgTriangleSolver_SSStoArea ( SGfloat lenA, SGfloat lenB, SGfloat lenC ); +void sgTriangleSolver_SSStoAAA ( SGfloat lenA, SGfloat lenB, SGfloat lenC, + SGfloat *angA, SGfloat *angB, SGfloat *angC ) ; +void sgTriangleSolver_SAStoASA ( SGfloat lenA, SGfloat angB, SGfloat lenC, + SGfloat *angA, SGfloat *lenB, SGfloat *angC ) ; +void sgTriangleSolver_ASAtoSAS ( SGfloat angA, SGfloat lenB, SGfloat angC, + SGfloat *lenA, SGfloat *angB, SGfloat *lenC ) ; + +SGDfloat sgdTriangleSolver_ASAtoArea(SGDfloat angA,SGDfloat lenB,SGDfloat angC); +SGDfloat sgdTriangleSolver_SAStoArea(SGDfloat lenA,SGDfloat angB,SGDfloat lenC); +SGDfloat sgdTriangleSolver_SSStoArea(SGDfloat lenA,SGDfloat lenB,SGDfloat lenC); +void sgdTriangleSolver_SSStoAAA(SGDfloat lenA,SGDfloat lenB, SGDfloat lenC, + SGDfloat *angA,SGDfloat *angB,SGDfloat *angC ) ; +void sgdTriangleSolver_SAStoASA(SGDfloat lenA,SGDfloat angB,SGDfloat lenC, + SGDfloat *angA,SGDfloat *lenB,SGDfloat *angC ) ; +void sgdTriangleSolver_ASAtoSAS(SGDfloat angA,SGDfloat lenB,SGDfloat angC, + SGDfloat *lenA,SGDfloat *angB,SGDfloat *lenC ) ; #endif |