00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
#ifndef DIME_LINEAR_H
00031
#define DIME_LINEAR_H
00032
00033
#include <dime/Basic.h>
00034
#include <stdio.h>
00035
#include <stdlib.h>
00036
#include <math.h>
00037
00038 class DIME_DLL_API dimeVec2f
00039 {
00040
public:
00041 dimeVec2f() {}
00042 dimeVec2f(
const dimeVec2f &vec) {x = vec.
x; y = vec.
y;}
00043 dimeVec2f(dxfdouble _x, dxfdouble _y) {x = _x; y = _y;}
00044
void setValue(
const dxfdouble _x,
const dxfdouble _y) {x = _x; y = _y;}
00045
00046
00047
00048
00049
00050
void print()
const { printf(
"Coord2: (%.3f, %.3f)\n", x,y);}
00051
void print(
const char *s) {printf(
"%s: (%.3f, %.3f)\n", s,x,y);}
00052 dxfdouble x,y;
00053
00054 };
00055
00056 class DIME_DLL_API dimeVec3f
00057 {
00058
public:
00059 dxfdouble x, y, z;
00060
00061 dimeVec3f(
void) {};
00062 dimeVec3f(
const dxfdouble X,
const dxfdouble Y,
const dxfdouble Z)
00063 { x=X; y=Y; z=Z; };
00064 dimeVec3f(
const dxfdouble *xyz)
00065 { x = xyz[0]; y = xyz[1]; z = xyz[2]; }
00066 dimeVec3f (
const dimeVec3f& v)
00067 { x=v.
x; y=v.
y; z=v.
z; };
00068 dimeVec3f cross(
const dimeVec3f &v)
const
00069
{
return dimeVec3f(y*v.
z-z*v.
y, z*v.
x-x*v.
z, x*v.
y-y*v.
x); }
00070 dxfdouble dot(
const dimeVec3f &v)
const
00071
{
return x*v.
x+y*v.
y+z*v.
z; }
00072
00073
bool equals(
const dimeVec3f &v)
00074 {
return (x == v.
x && y == v.
y && z == v.
z); }
00075
bool equals(
const dimeVec3f &v, dxfdouble tol)
00076 {
return (fabs(x-v.
x) <= tol && fabs(y-v.
y) <= tol && fabs(z-v.
z) <= tol); }
00077
00078 operator dxfdouble *() {
return &x; }
00079
const dxfdouble *getValue()
const {
return &x; }
00080
void getValue(dxfdouble &_x, dxfdouble &_y, dxfdouble &_z)
const
00081
{ _x = x; _y = y; _z = z;}
00082 dxfdouble length()
const
00083
{
return (dxfdouble) sqrt(x*x+y*y+z*z); }
00084 dxfdouble sqrLength(
void)
const
00085
{
return x*x+y*y+z*z; }
00086
void negate(
void)
00087 { x = -x; y = -y; z = -z; }
00088
void setValue(
const dxfdouble *v)
00089 { x = v[0]; y = v[1]; z = v[2]; }
00090
void setValue(
const dxfdouble X,
const dxfdouble Y,
const dxfdouble Z)
00091 { x=X; y=Y; z=Z; }
00092
00093 dxfdouble operator [] (
const int i)
const
00094
{
return( (i==0)?x:((i==1)?y:z) ); };
00095 dxfdouble & operator [] (
const int i)
00096 {
return( (i==0)?x:((i==1)?y:z) ); };
00097
00098 dimeVec3f &operator *= (
const dxfdouble s)
00099 { x*=s; y*=s; z*=s;
return *
this; }
00100 dimeVec3f &operator /= (
const dxfdouble s)
00101 { x/=s; y/=s; z/=s;
return *
this; }
00102 dimeVec3f &operator += (
const dimeVec3f &v)
00103 { x+=v.
x; y+=v.
y; z+=v.
z;
return *
this; }
00104 dimeVec3f &operator -= (
const dimeVec3f &v)
00105 { x-=v.
x; y-=v.
y; z-=v.
z;
return *
this;}
00106 dimeVec3f operator -()
const
00107
{
return dimeVec3f(-x, -y, -z); }
00108
friend dimeVec3f operator *(
const dimeVec3f &v, dxfdouble s)
00109 {
return dimeVec3f(v.
x*s, v.
y*s, v.
z*s); }
00110
friend dimeVec3f operator *(dxfdouble s,
const dimeVec3f &v)
00111 {
return dimeVec3f(v.
x*s, v.
y*s, v.
z*s); }
00112
friend dimeVec3f operator / (
const dimeVec3f &v, dxfdouble s)
00113 {
return dimeVec3f(v.
x/s, v.
y/s, v.
z/s); }
00114
friend dimeVec3f operator + (
const dimeVec3f &v1,
const dimeVec3f &v2)
00115 {
return dimeVec3f(v1.
x+v2.
x, v1.
y+v2.
y, v1.
z+v2.
z); }
00116
friend dimeVec3f operator - (
const dimeVec3f &v1,
const dimeVec3f &v2)
00117 {
return dimeVec3f(v1.
x-v2.
x, v1.
y-v2.
y, v1.
z-v2.
z); }
00118
00119
friend bool operator ==(
const dimeVec3f &v1,
const dimeVec3f &v2)
00120 {
return (v1.
x == v2.
x && v1.
y == v2.
y && v1.
z == v2.
z); }
00121
friend bool operator !=(
const dimeVec3f &v1,
const dimeVec3f &v2)
00122 {
return (v1.
x != v2.
x || v1.
y != v2.
y || v1.
z != v2.
z); }
00123
00124 dimeVec3f& operator = (
const dimeVec3f &v)
00125 { x=v.
x; y=v.
y; z=v.
z;
return *
this; }
00126
00127
void multMatrix(dxfdouble *matrix)
00128 {
00129 dxfdouble tx, ty, tz;
00130 tx = ty = tz = 0.0f;
00131 tx = matrix[0]*x+matrix[1]*y+matrix[2]*z;
00132 ty = matrix[4]*x+matrix[5]*y+matrix[6]*z;
00133 tz = matrix[8]*x+matrix[9]*y+matrix[10]*z;
00134 x = tx, y = ty, z = tz;
00135 }
00136
00137
void print()
const
00138 { printf(
"dimeVec3f: (%.3f, %.3f, %.3f)\n",x, y, z); }
00139
void print(
const char *s)
const
00140
{ printf(
"%s: (%.3f, %.3f, %.3f)\n",s, x, y, z); }
00141
00142
00143 dimeVec3f multComponents(
const dimeVec3f &v)
const
00144
{
return dimeVec3f(x*v.
x, y*v.
y, z*v.
z); }
00145
00146 dxfdouble angle(
const dimeVec3f &v2);
00147
void normalize();
00148
00149 };
00150
00151 class DIME_DLL_API dimeMatrix
00152 {
00153
public:
00154 dimeMatrix() {}
00155 dimeMatrix(
const dimeMatrix &matrix);
00156
00157 dimeMatrix(dxfdouble a11, dxfdouble a12, dxfdouble a13, dxfdouble a14,
00158 dxfdouble a21, dxfdouble a22, dxfdouble a23, dxfdouble a24,
00159 dxfdouble a31, dxfdouble a32, dxfdouble a33, dxfdouble a34,
00160 dxfdouble a41, dxfdouble a42, dxfdouble a43, dxfdouble a44);
00161
void transpose();
00162
void makeIdentity();
00163
bool isIdentity()
const;
00164
void setTransform(
const dimeVec3f &translation,
00165
const dimeVec3f &scalefactor,
00166
const dimeVec3f &rotAngles);
00167 dimeMatrix &multRight(
const dimeMatrix &m);
00168 dimeMatrix &multLeft(
const dimeMatrix &m);
00169
00170
00171
void setRotate(
const dimeVec3f &rot);
00172
00173
void setRotate(
const dimeVec3f &x,
const dimeVec3f &y,
const dimeVec3f &z);
00174
00175
00176
void setRotation(
const dimeVec3f &u,
const dxfdouble angle);
00177
00178
00179
void setScale(
const dxfdouble s);
00180
00181
00182
void setScale(
const dimeVec3f &s);
00183
00184
00185
void setTranslate(
const dimeVec3f &t);
00186
00187
00188
void multMatrixVec(
const dimeVec3f &src, dimeVec3f &dst)
const;
00189
00190
00191
void multMatrixVec(dimeVec3f &vec)
const;
00192
00193
00194
00195
00196
00197 operator dxfdouble *() {
return &matrix[0][0]; }
00198
00199
00200 dxfdouble *operator [](
int i) {
return &matrix[i][0]; }
00201
const dxfdouble * operator [](
int i)
const {
return &matrix[i][0];}
00202
00203 dimeMatrix &operator =(
const dimeMatrix &m);
00204
00205
00206 dimeMatrix &operator *=(
const dimeMatrix &m) {
return multRight(m); }
00207
00208
00209
static dimeMatrix identity();
00210
bool inverse();
00211
bool inverse2();
00212 dxfdouble determinant(
const int i=-2,
const int j=-1);
00213
00214
void operator *=(
const dxfdouble val);
00215
00216
private:
00217 dxfdouble matrix[4][4];
00218
00219 };
00220
00221
#endif // ! DIME_LINEAR_H
00222