1#ifndef __JBXL_CPP_VECTOR_H_
2#define __JBXL_CPP_VECTOR_H_
36#define VECTOR4 Vector4
42#define BOUNDARY_BLANK 5
67 Vector(T X=0, T Y=0, T Z=0,
double N=0.0,
double C=1.0,
int D=0) { set(X, Y, Z, N, C, D);}
70 T
norm2(
void) {
return (x*x + y*y + z*z);}
71 double norm(
void) { n = (double)sqrt(x*x + y*y + z*z);
return n;}
74 void init(
double C=1.0) { x = y = z = (T)0; n = 0.0; c = C; d = 0;}
75 void set(T X, T Y=0, T Z=0,
double N=0.0,
double C=1.0,
int D=0);
81 T&
element(
int i) {
if(i==1)
return x;
else if(i==2)
return y;
else if(i==3)
return z;
else return x;}
83 template <
typename R>
Vector<T>& operator = (
const Vector<R> a) { x=(T)a.
x; y=(T)a.
y; z=(T)a.
z; n=a.
n; c=a.
c; d=a.
d;
return *
this;}
89 double nrm = (double)sqrt(x*x + y*y + z*z);
110template <
typename T>
inline void Vector<T>::set(T X, T Y, T Z,
double N,
double C,
int D)
120 n = (double)sqrt(x*x + y*y + z*z);
141{
return Vector<T>(a.
x + (T)c, a.
y + (T)c, a.
z + (T)c, 0.0, a.
c, a.
d); }
145{
return Vector<T>((T)c + a.
x, (T)c + a.
y, (T)c + a.
z, 0.0, a.
c, a.
d); }
153{
return Vector<T>(a.
x - (T)c, a.
y - (T)c, a.
z - (T)c, 0.0, a.
c, a.
d); }
157{
return Vector<T>((T)c - a.
x, (T)c - a.
y, (T)c - a.
z, 0.0, a.
c, a.
d); }
180{ a = a + b;
return a; }
184{ a = a + Cast<T>(b);
return a; }
188{ a = a - b;
return a; }
192{ a = a - Cast<T>(b);
return a; }
202{
return (a.
x*b.
x + a.
y*b.
y + a.
z*b.
z); }
206{
return (v1.
x == v2.
x && v1.
y == v2.
y && v1.
z == v2.
z); }
210{
return (v1.
x != v2.
x || v1.
y != v2.
y || v1.
z != v2.
z); }
227 if (v1.
x != v2.
x)
return v1.
x < v2.
x;
228 if (v1.
y != v2.
y)
return v1.
y < v2.
y;
229 if (v1.
z != v2.
z)
return v1.
z < v2.
z;
246 T d2 = dx*dx + dy*dy + dz*dz;
249 if ((
double)d2>t2)
return false;
257 if (v==NULL)
return NULL;
259 for (
int i=0; i<n; i++) v[i] = a[i];
273 if (cs>=1.0)
return 0.0;
274 else if (cs<=-1.0)
return PI;
292 vect.
x = (v1.
y-v2.
y)*(v1.
z+v2.
z) + (v2.
y-v3.
y)*(v2.
z+v3.
z) + (v3.
y-v1.
y)*(v3.
z+v1.
z);
293 vect.
y = (v1.
z-v2.
z)*(v1.
x+v2.
x) + (v2.
z-v3.
z)*(v2.
x+v3.
x) + (v3.
z-v1.
z)*(v3.
x+v1.
x);
294 vect.
z = (v1.
x-v2.
x)*(v1.
y+v2.
y) + (v2.
x-v3.
x)*(v2.
y+v3.
y) + (v3.
x-v1.
x)*(v3.
y+v1.
y);
297 vect.
c =
Min(v3.
c, vect.
c);
313 vect.
x = (v1.
y-v2.
y)*(v1.
z+v2.
z) + (v2.
y-v3.
y)*(v2.
z+v3.
z) + (v3.
y-v4.
y)*(v3.
z+v4.
z) + (v4.
y-v1.
y)*(v4.
z+v1.
z);
314 vect.
y = (v1.
z-v2.
z)*(v1.
x+v2.
x) + (v2.
z-v3.
z)*(v2.
x+v3.
x) + (v3.
z-v4.
z)*(v3.
x+v4.
x) + (v4.
z-v1.
z)*(v4.
x+v1.
x);
315 vect.
z = (v1.
x-v2.
x)*(v1.
y+v2.
y) + (v2.
x-v3.
x)*(v2.
y+v3.
y) + (v3.
x-v4.
x)*(v3.
y+v4.
y) + (v4.
x-v1.
x)*(v4.
y+v1.
y);
318 vect.
c =
Min(v3.
c, vect.
c);
319 vect.
c =
Min(v4.
c, vect.
c);
344 double c0 = (t2 - t)*0.5 + (1.0 - t3)*0.16666666666666667;
345 double c1 = t3*0.5 - t2 + 0.66666666666666667;
346 double c2 = (t + t2 - t3)*0.5 + 0.16666666666666667;
347 double c3 = t3*0.16666666666666667;
349 Vector<T> vect = c0*q0 + c1*p0 + c2*p1 + c3*q3;
386 for (
int i=0; i<dim; i++) point[i] = new Vector<T>();
391 void set(
int m, T x, T y=0, T z=0,
double n=0.0) {
392 if (m>=0 && m<dim && point!=NULL) point[m]->
set(x, y, z, n);
397 for (
int i=0; i<dim; i++) point[i]->set((T)0);
403 for (
int i=0; i<dim; i++)
delete(point[i]);
437 RBound(T XMin=(T)0, T XMax=(T)0, T YMin=(T)0, T YMax=(T)0, T ZMin=(T)0, T ZMax=(T)0, T TMin=(T)0, T TMax=(T)0) {
438 set(XMin, XMax, YMin, YMax, ZMin, ZMax, TMin, TMax);
444 void set(T XMin=(T)0, T XMax=(T)0, T YMin=(T)0, T YMax=(T)0, T ZMin=(T)0, T ZMax=(T)0, T TMin=(T)0, T TMax=(T)0){
455 void init() { xmin = xmax = ymin = ymax = zmin = zmax = tmin = tmax = (T)0;}
494 xmin =
Min(xmin, vect.
x);
495 ymin =
Min(ymin, vect.
y);
496 zmin =
Min(zmin, vect.
z);
497 xmax =
Max(xmax, vect.
x);
498 ymax =
Max(ymax, vect.
y);
499 zmax =
Max(zmax, vect.
z);
558 return vect.
x < xmin || vect.
x > xmax ||
559 vect.
y < ymin || vect.
y > ymax ||
560 vect.
z < zmin || vect.
z > zmax;
565 return x < xmin || x > xmax ||
566 y < ymin || y > ymax ||
567 z < zmin || z > zmax;
607 UVMap(T U=0, T V=0,
int d=0) { set(U, V, d);}
610 void init(
void) { u = v = (T)0; d = 0;}
611 void set(T U, T V=0,
int D=0) { u = U, v = V; d = D;}
613 UVMap flip(
void) { u = (T)(1.0 - u); v = (T)(1.0 - v);
return *
this;}
617 template <
typename R>
UVMap<T>& operator = (
const UVMap<R> a) { u = (T)a.
u; v = (T)a.
v; d = a.
d;
return *
this;}
673{
return (a.
u == b.
u && a.
v == b.
v); }
677{
return (a.
u != b.
u || a.
v != b.
v); }
681{ a = a + b;
return a; }
685{ a = a + Cast<T>(b);
return a; }
689{ a = a - b;
return a; }
692{ a = a - Cast<T>(b);
return a; }
719 Vector4(T X=0, T Y=0, T Z=0, T U=0,
double N=0.0,
double C=1.0,
int D=0) { set(X, Y, Z, U, N, C, D);}
722 T
norm2(
void) {
return (x*x + y*y + z*z + t*t);}
723 double norm(
void) { n = (double)sqrt(x*x + y*y + z*z + t*t);
return n;}
726 void init(
double C=1.0) { x = y = z = t = (T)0; n = 0.0; c = C; d = 0;}
727 void set(T X, T Y=0, T Z=0, T U=0,
double N=0.0,
double C=1.0,
int D=0);
734 T&
element(
int i) {
if(i==1)
return x;
else if(i==2)
return y;
else if(i==3)
return z;
else if(i==4)
return t;
else return x;}
742 double nrm = (double)sqrt(x*x + y*y + z*z + t*t);
764template <
typename T>
inline void Vector4<T>::set(T X, T Y, T Z, T U,
double N,
double C,
int D)
775 n = (double)sqrt(x*x + y*y + z*z + t*t);
796{
return Vector4<T>(a.
x + (T)c, a.
y + (T)c, a.
z + (T)c, a.
t + (T)c, 0.0, a.
c, a.
d); }
800{
return Vector4<T>((T)c + a.
x, (T)c + a.
y, (T)c + a.
z, (T)c + a.
t, 0.0, a.
c, a.
d); }
808{
return Vector4<T>(a.
x - (T)c, a.
y - (T)c, a.
z - (T)c, a.
t - (T)c, 0.0, a.
c, a.
d); }
812{
return Vector4<T>((T)c - a.
x, (T)c - a.
y, (T)c - a.
z, (T)c - a.
t, 0.0, a.
c, a.
d); }
816{
return Vector4<T>((T)d*a.
x, (T)d*a.
y, (T)d*a.
z, (T)d*a.
t, (T)d*a.
n, a.
c, a.
d); }
820{
return Vector4<T>(a.
x*(T)d, a.
y*(T)d, a.
z*(T)d, a.
t*(T)d, a.
n*(T)d, a.
c, a.
d); }
824{
return Vector4<T>(a.
x/(T)d, a.
y/(T)d, a.
z/(T)d, a.
t/(T)d, a.
n/(T)d, a.
c, a.
d); }
828{
return Vector4<T>((T)d/a.
x, (T)d/a.
y, (T)d/a.
z, (T)d/a.
t, 0.0, a.
c, a.
d) ;}
832{ a = a + b;
return a; }
836{ a = a + Cast<T>(b);
return a; }
840{ a = a - b;
return a; }
843{ a = a - Cast<T>(b);
return a; }
848{
return (a.
x*b.
x + a.
y*b.
y + a.
z*b.
z + a.
t*b.
t); }
852{
return (v1.
x == v2.
x && v1.
y == v2.
y && v1.
z == v2.
z && v1.
t == v2.
t); }
856{
return (v1.
x != v2.
x || v1.
y != v2.
y || v1.
z != v2.
z || v1.
t != v2.
t); }
874 if (v1.
x != v2.
x)
return v1.
x < v2.
x;
875 if (v1.
y != v2.
y)
return v1.
y < v2.
y;
876 if (v1.
z != v2.
z)
return v1.
z < v2.
z;
877 if (v1.
t != v2.
t)
return v1.
t < v2.
t;
894 T d2 = dx*dx + dy*dy + dz*dz + dt*dt;
897 if ((
double)d2>t2)
return false;
905 if (v==NULL)
return NULL;
907 for (
int i=0; i<n; i++) v[i] = a[i];
921 if (cs>=1.0)
return 0.0;
922 else if (cs<=-1.0)
return PI;
void set(int m, T x, T y=0, T z=0, double n=0.0)
virtual ~PCoordinate(void)
RBound(T XMin=(T) 0, T XMax=(T) 0, T YMin=(T) 0, T YMax=(T) 0, T ZMin=(T) 0, T ZMax=(T) 0, T TMin=(T) 0, T TMax=(T) 0)
void set(T XMin=(T) 0, T XMax=(T) 0, T YMin=(T) 0, T YMax=(T) 0, T ZMin=(T) 0, T ZMax=(T) 0, T TMin=(T) 0, T TMax=(T) 0)
bool outofBounds(Vector< T > vect)
ベクトルが位置ベクトルの場合,その点は境界外か? 境界外:true,境界内:false
void fusion(T x, T y, T z)
ポイントと融合させる
void fusion(Vector< T > vect)
ベクトル vect と融合させる
void cutdown(T x, T y, T z)
bool outofBounds(T x, T y, T z)
その点は境界外か? 境界外:true,境界内:false
void enlarge(T f)
境界構造体 bound を広げる
void fusion(RBound< T > bound)
境界構造体 bound と融合させる
void cutdown(RBound< T > bound)
切り出した場合の境界
void cutdown(Vector< T > vect)
void commonarea(RBound< T > bound)
境界構造体 bound との共通領域 共通領域がない場合は,min>max になる
void set(T U, T V=0, int D=0)
UVMap(T U=0, T V=0, int d=0)
Vector4(T X=0, T Y=0, T Z=0, T U=0, double N=0.0, double C=1.0, int D=0)
Vector4< T > normalize(void)
void set(T X, T Y=0, T Z=0, T U=0, double N=0.0, double C=1.0, int D=0)
Vector< T > normalize(void)
void set(T X, T Y=0, T Z=0, double N=0.0, double C=1.0, int D=0)
Vector(T X=0, T Y=0, T Z=0, double N=0.0, double C=1.0, int D=0)
Vector< T > operator-=(Vector< T > &a, const Vector< T > b)
bool disJunctBounds(RBound< T > b1, RBound< T > b2)
AffineTrans< T > operator*(AffineTrans< T > a, AffineTrans< T > b)
Vector4< T > * dupVector4(Vector4< T > *a, int n)
Matrix< T > operator+(const Matrix< T > a, const Matrix< T > b)
double Vector4Dist(const Vector4< T > a, const Vector4< T > b)
点a と b の距離 (a,b は位置ベクトル)
double Zero_Eps
1に対して 0とするトレランス
Vector< T > BSplineInterp4(Vector< T > p0, Vector< T > p1, double t)
Matrix< T > operator/(const Matrix< T > a, const R d)
bool operator==(const Matrix< T > v1, const Matrix< T > v2)
bool operator!=(const Quaternion< T > q1, const Quaternion< T > q2)
~ 共役
TVector< T > operator^(const TVector< T > a, const TVector< T > b)
Cross product 外積
Vector< T > operator+=(Vector< T > &a, const Vector< T > b)
double VectorDist(const Vector< T > a, const Vector< T > b)
点a と b の距離 (a,b は位置ベクトル)
Vector< T > MidPoint(const Vector< T > a, const Vector< T > b)
bool operator<(const Vector< T > v1, const Vector< T > v2)
double Vector4Angle(Vector4< T > a, Vector4< T > b)
double VectorAngle(Vector< T > a, Vector< T > b)
Vector< T > NewellMethod4(Vector< T > v1, Vector< T > v2, Vector< T > v3, Vector< T > v4)
Vector< T > NewellMethod(Vector< T > v1, Vector< T > v2, Vector< T > v3)
Normal Vector of 3 Vectors with Newell Mothod.
Matrix< T > operator-(const Matrix< T > a)
Vector< T > * dupVector(Vector< T > *a, int n)
Vector< T > NewellMethod3(Vector< T > v1, Vector< T > v2, Vector< T > v3)
bool same_vector(Vector< T > v1, Vector< T > v2)
Vector< T > Cast(Vector< R > v)