pkgeomf.h

Go to the documentation of this file.
00001 
00002 /* ///////////////////////////////////////////////////////////////////////// */
00003 /* This file is a part of the BSTools package                                */
00004 /* written by Przemyslaw Kiciak                                              */
00005 /* ///////////////////////////////////////////////////////////////////////// */
00006 /* (C) Copyright by Przemyslaw Kiciak, 2005, 2012                            */
00007 /* this package is distributed under the terms of the                        */
00008 /* Lesser GNU Public License, see the file COPYING.LIB                       */
00009 /* ///////////////////////////////////////////////////////////////////////// */
00010 
00011 /* Header file for the libgeom library of C procedures - */
00012 /* basic 2D, 3D and 4D affine geometry                   */ 
00013 
00014 #ifndef PKGEOMF_H
00015 #define PKGEOMF_H
00016 
00017 #ifndef PKVARIA_H
00018 #include "pkvaria.h"
00019 #endif
00020 
00021 #ifdef __cplusplus   
00022 extern "C" {
00023 #endif
00024 
00025 typedef union trans2f {
00026   struct {
00027     /* affine transformation of a 2D space  */
00028     float a11, a12, a13,   /* coefficients of the transformation   */
00029           a21, a22, a23;
00030   } U0;
00031   struct {
00032     float a[2][3];
00033     short detsgn;   /* sign of the determinant : -1, 0 or 1 */
00034   } U1;
00035 } trans2f;
00036 
00037 typedef struct Box2f {
00038     float x0, x1, y0, y1;
00039   } Box2f;
00040 
00041 typedef union trans3f {
00042   struct {
00043     /* affine transformation of a 3D space  */
00044     float a11, a12, a13, a14,   /* coefficients of the transformation   */
00045           a21, a22, a23, a24,
00046           a31, a32, a33, a34;
00047   } U0;
00048   struct {
00049     float a[3][4];
00050     short detsgn;   /* sign of the determinant : -1, 0 or 1 */
00051   } U1;
00052 } trans3f;
00053 
00054 typedef struct Box3f {
00055     float x0, x1, y0, y1, z0, z1;
00056   } Box3f;
00057 
00058 typedef struct ray3f {
00059   /* ray, ie. a halfline in 3D space */
00060   point3f  p;  /* origin point of the ray */
00061   vector3f v;  /* direction               */
00062 } ray3f;
00063 
00064 typedef vector4f quaternionf;
00065 
00066 typedef struct {
00067     float amin, amax;
00068     short code;  
00069   } ConvexCone2f;
00070 
00071 /* /////////////////////////////////////////////////////////////////////////// */
00072 
00073 void SetPoint2f ( point2f *p, float x, float y );
00074 #define SetVector2f(v,x,y) SetPoint2f ( v, x, y )
00075 
00076 void TransPoint2f ( const trans2f *tr, const point2f *p, point2f *q );
00077 void TransVector2f ( const trans2f *tr, const vector2f *p, vector2f *q );
00078 void IdentTrans2f ( trans2f *tr );
00079 void CompTrans2f ( trans2f *s, trans2f *t, trans2f *u );
00080 void ShiftTrans2f ( trans2f *tr, float tx, float ty );
00081 void RotTrans2f ( trans2f *tr, float angle );
00082 void ScaleTrans2f ( trans2f *tr, float sx, float sy );
00083 void Trans2Shiftf ( trans2f *tr, float tx, float ty );
00084 void Trans2Rotf ( trans2f *tr, float angle );
00085 void Trans2Scalef ( trans2f *tr, float sx, float sy );
00086 boolean InvertTrans2f ( trans2f *tr );
00087 
00088 void MultVector2f ( double a, const vector2f *v, vector2f *w );
00089 void SubtractPoints2f ( const point2f *p1, const point2f *p2, vector2f *v );
00090 void AddVector2f ( const point2f *p, const vector2f *v, point2f *q );
00091 void AddVector2Mf ( const point2f *p, const vector2f *v, double t, point2f *q );
00092 void InterPoint2f ( const point2f *p1, const point2f *p2, double t, point2f *q );
00093 void Interp3Vectors2f ( const vector2f *p0, const vector2f *p1, const vector2f *p2,
00094                         const float *coeff, vector2f *p );
00095 void NormalizeVector2f ( vector2f *v );
00096 void MidPoint2f ( const point2f *p1, const point2f *p2, point2f *q );
00097 
00098 double DotProduct2f ( const vector2f *v1, const vector2f *v2 );
00099 double det2f ( const vector2f *v1, const vector2f *v2 );
00100 void OrtVector2f ( const vector2f *v1, const vector2f *v2, vector2f *v );
00101 
00102 void ProjectPointOnLine2f ( const point2f *p0, const point2f *p1,
00103                             point2f *q );
00104 
00105 double Point2Distancef ( point2f *p, point2f *q );
00106 
00107 short ExtendConvexCone2f ( ConvexCone2f *cone, float a );
00108 short ExtendConvexCone2fv ( ConvexCone2f *cone, vector2f *v );
00109 boolean InsideConvexCone2f ( ConvexCone2f *cone, float a );
00110 
00111 /* /////////////////////////////////////////////////////////////////////////// */
00112 void Trans2Point3f ( const trans2f *tr, const point3f *p, point3f *q );
00113 
00114 /* /////////////////////////////////////////////////////////////////////////// */
00115 
00116 void SetPoint3f ( point3f *p, float x, float y, float z );
00117 #define SetVector3f(v,x,y,z) SetPoint3f ( v, x, y, z )
00118 
00119 void Point3to2f ( const point3f *P, point2f *p );
00120 void Point2to3f ( const point2f *p, float w, point3f *P );
00121 void Point4to2f ( const point4f *P, point2f *p );
00122 void Point2to4f ( const point2f *p, float w, point4f *P );
00123 
00124 void TransPoint3f ( const trans3f *tr, const point3f *p, point3f *q );
00125 void TransVector3f ( const trans3f *tr, const vector3f *v, vector3f *w );
00126 void TransContra3f ( const trans3f *tri, const vector3f *v, vector3f *w );
00127 void Trans3Point2f ( const trans3f *tr, const point2f *p, point2f *q );
00128 void Trans3Point4f ( const trans3f *tr, const point4f *p, point4f *q );
00129 
00130 void Trans3Shiftf ( trans3f *tr, float tx, float ty, float tz );
00131 void Trans3Mirrorf ( trans3f *tr, vector3f *n );
00132 void Trans3Rotf ( trans3f *tr, byte j, byte k, float angle );
00133 #define Trans3RotXf(tr,angle) Trans3Rotf ( tr, 2, 3, angle )
00134 #define Trans3RotYTf(tr,angle) Trans3Rotf ( tr, 3, 1, angle )
00135 #define Trans3RotZTf(tr,angle) Trans3Rotf ( tr, 1, 2, angle )
00136 void Trans3RotVf ( trans3f *tr, vector3f *v, float angle );
00137 void Trans3Scalef ( trans3f *tr, float sx, float sy, float sz );
00138 
00139 void IdentTrans3f ( trans3f *tr );
00140 void CompTrans3f ( trans3f *s, trans3f *t, trans3f *u );
00141 void GeneralAffineTrans3f ( trans3f *tr, vector3f *v1, vector3f *v2,
00142                             vector3f *v3 );
00143 void ShiftTrans3f ( trans3f *tr, float tx, float ty, float tz );
00144 void MirrorTrans3f ( trans3f *tr, vector3f *n );
00145 
00146 void RotTrans3f ( trans3f *tr, byte j, byte k, float angle );
00147 void EulerRotTrans3f ( trans3f *tr, float psi, float theta, float phi );
00148 #define RotXTrans3f(tr,angle) RotTrans3f ( tr, 2, 3, angle )
00149 #define RotYTrans3f(tr,angle) RotTrans3f ( tr, 3, 1, angle )
00150 #define RotZTrans3f(tr,angle) RotTrans3f ( tr, 1, 2, angle )
00151 
00152 void FindRotVEulerf ( const vector3f *v, float angle,
00153                       float *psi, float *theta, float *phi );
00154 void RotVTrans3f ( trans3f *tr, vector3f *v, float angle );
00155 void ScaleTrans3f ( trans3f *tr, float sx, float sy, float sz );
00156 boolean InvertTrans3f ( trans3f *tr );
00157 float TrimAnglef ( float angle );
00158 void CompEulerRotf ( float psi1, float theta1, float phi1, float psi2,
00159                      float theta2, float phi2, float *psi, float *theta,
00160                      float *phi );
00161 void CompRotV3f ( const vector3f *v1, float a1, const vector3f *v2, float a2,
00162                   vector3f *v, float *a );
00163 
00164 void MultVector3f ( double a, const vector3f *v, vector3f *w );
00165 void SubtractPoints3f ( const point3f *p1, const point3f *p2, vector3f *v );
00166 void AddVector3f ( const point3f *p, const vector3f *v, point3f *q );
00167 void AddVector3Mf ( const point3f *p, const vector3f *v, double t,
00168                     point3f *q );
00169 void InterPoint3f ( const point3f *p1, const point3f *p2, double t,
00170                     point3f *q );
00171 void MidPoint3f ( const point3f *p1, const point3f *p2, point3f *q );
00172 void Interp3Vectors3f ( const vector3f *p0, const vector3f *p1, const vector3f *p2,
00173                         const float *coeff, vector3f *p );
00174 void NormalizeVector3f ( vector3f *v );
00175 
00176 double DotProduct3f ( const vector3f *v1, const vector3f *v2 );
00177 void CrossProduct3f ( const vector3f *v1, const vector3f *v2, vector3f *v );
00178 double det3f ( const vector3f *v1, const vector3f *v2, const vector3f *v3 );
00179 void OrtVector3f ( const vector3f *v1, const vector3f *v2, vector3f *v );
00180 
00181 void ProjectPointOnLine3f ( const point3f *p0, const point3f *p1,
00182                             point3f *q );
00183 void ProjectPointOnPlane3f ( const point3f *p0, const point3f *p1, const point3f *p2,
00184                              point3f *q );
00185 
00186 double Point3Distancef ( point3f *p, point3f *q );
00187 
00188 /* /////////////////////////////////////////////////////////////////////////// */
00189 void SetPoint4f ( point4f *p, float X, float Y, float Z, float W );
00190 #define SetVector4f(v,X,Y,Z,W) SetPoint4f ( v, X, Y, Z, W )
00191 
00192 void Point4to3f ( const point4f *P, point3f *p );
00193 void Point3to4f ( const point3f *p, float w, point4f *P );
00194 
00195 void SubtractPoints4f ( const point4f *p1, const point4f *p2, vector4f *v );
00196 void AddVector4f ( const point4f *p, const vector4f *v, point4f *q );
00197 void AddVector4Mf ( const point4f *p, const vector4f *v, double t,
00198                     point4f *q );
00199 void MultVector4f ( double a, const vector4f *v, vector4f *w );
00200 
00201 void InterPoint4f ( const point4f *p1, const point4f *p2, double t,
00202                     point4f *q );
00203 void MidPoint4f ( const point4f *p1, const point4f *p2, point4f *q );
00204 void Interp3Vectors4f ( const vector4f *p0, const vector4f *p1, const vector4f *p2,
00205                         const float *coeff, vector4f *p );
00206 void NormalizeVector4f ( vector4f *v );
00207 
00208 double det4f ( const vector4f *v0, const vector4f *v1,
00209                const vector4f *v2, const vector4f *v3 );
00210 void CrossProduct4f (const vector4f *v0, const vector4f *v1,
00211                      const vector4f *v2, vector4f *v );
00212 void CrossProduct4P3f ( const vector4f *v0, const vector4f *v1,
00213                         const vector4f *v2, vector3f *v );
00214 double DotProduct4f ( const vector4f *v0, const vector4f *v1 );
00215 void OutProduct4P3f ( const vector4f *v0, const vector4f *v1, vector3f *v );
00216 
00217 void OrtVector4f ( const vector4f *v1, const vector4f *v2, vector4f *v );
00218 
00219 void ProjectPointOnLine4f ( const point4f *p0, const point4f *p1,
00220                             point4f *q );
00221 void ProjectPointOnPlane4f ( const point4f *p0, const point4f *p1, const point4f *p2,
00222                              point4f *q );
00223 
00224 float pkg_LineRayDist3f ( ray3f *ray, point3f *q0, point3f *q1,
00225                           float *rparam, float *lparam,
00226                           point3f *rp, point3f *lp );
00227 
00228 /* /////////////////////////////////////////////////////////////////////////// */
00229 #define SetQuaternionf(q,a,x,y,z) SetVector4f ( q, x, y, z, a )
00230 #define AddQuaternionsf AddVectors4f
00231 
00232 void QuaternionMultf ( quaternionf *q1, quaternionf *q2, quaternionf *q );
00233 void QuaternionMultInvf ( quaternionf *q1, quaternionf *q2, quaternionf *q );
00234 void QuaternionInvMultf ( quaternionf *q1, quaternionf *q2, quaternionf *q );
00235 
00236 void QuaternionRotTrans3f ( trans3f *tr, quaternionf *q );
00237 void Trans3QuaternionRotf ( trans3f *tr, quaternionf *q );
00238 
00239 #ifdef __cplusplus
00240 }
00241 #endif
00242 
00243 #endif /*PKGEOMF_H*/
00244