29 double& weight_a,
double& weight_b,
double& weight_c )
33 const double triarea = ba.
cross( ca ).
abs()*0.5;
41 const double distpa = pa.
abs();
44 weight_a = 1.; weight_b = 0.; weight_c = 0.;
48 const double distpb = pb.
abs();
51 weight_a = 0.; weight_b = 1.; weight_c = 0.;
55 const double distpc = pc.
abs();
58 weight_a = 0.; weight_b = 0.; weight_c = 1.;
62 const double totalinversedist = 1./distpa + 1./distpb + 1./distpc;
63 weight_a = 1./(distpa*totalinversedist);
64 weight_b = 1./(distpb*totalinversedist);
65 weight_c = 1./(distpc*totalinversedist);
69 const double triareapab = pa.
cross( pb ).
abs()*0.5;
70 const double triareapac = pa.
cross( pc ).
abs()*0.5;
71 const double triareapcb = pc.
cross( pb ).
abs()*0.5;
73 weight_a = triareapcb / triarea;
74 weight_b = triareapac / triarea;
75 weight_c = triareapab / triarea;
88 return v[0]*(v[4]*v[8]-v[5]*v[7])+v[1]*(v[5]*v[6]-v[3]*v[8])+
89 v[2]*(v[3]*v[7]-v[4]*v[6]);
98 const double d0[9] = { r1.
y, r1.
z, 1, r2.
y, r2.
z, 1, r3.
y, r3.
z, 1 };
99 const double d1[9] = { r1.
x, r1.
z, 1, r2.
x, r2.
z, 1, r3.
x, r3.
z, 1 };
100 const double d2[9] = { r1.
x, r1.
y, 1, r2.
x, r2.
y, 1, r3.
x, r3.
y, 1 };
101 const double d3[9] = { r1.
x, r1.
y, r1.
z, r2.
x, r2.
y, r2.
z, r3.
x, r3.
y,r3.
z};
108 const double* r2,
const double* r3 )
110 const double d0[9] = { r1[1], r1[2], r1[3], r2[1], r2[2], r2[3],
111 r3[1], r3[2], r3[3] };
112 const double d1[9] = { r1[0], r1[2], r1[3], r2[0], r2[2], r2[3],
113 r3[0], r3[2], r3[3] };
114 const double d2[9] = { r1[0], r1[1], r1[3], r2[0], r2[1], r2[3],
115 r3[0], r3[1], r3[3] };
116 const double d3[9] = { r1[0], r1[1], r1[2], r2[0], r2[1], r2[2],
117 r3[0], r3[1], r3[2] };
127 const Coord d12 = p1-p2;
128 const Coord d13 = p1-p3;
129 const Coord d = p1-pt;
130 const double deter=d13.
x*d12.
y-d13.
y*d12.
x;
131 const double a12 = ( p1.
dot(p1)-p2.dot(p2) )/2;
132 const double a13 = ( p1.
dot(p1)-p3.dot(p3) )/2;
133 center.
x = (a13*d12.
y-a12*d13.
y)/deter;
134 center.
y = (d13.
x*a12-d12.
x*a13)/deter;
135 return pt.sqAbs()-p1.
sqAbs()+2*center.
dot(d)<0;
146 const double t[9] = { ab.
x, ab.
y, ab.
z, ac.
x, ac.
y, ac.
z, ad.
x, ad.
y, ad.
z};
149 const double sqra = a.
x*a.
x+a.
y*a.
y+a.
z*a.
z;
150 const double d0 = (sqra-(b.x*b.x+b.y*b.y+b.z*b.z))/2;
151 const double d1 = (sqra-(c.x*c.x+c.y*c.y+c.z*c.z))/2;
152 const double d2 = (sqra-(d.x*d.x+d.y*d.y+d.z*d.z))/2;
153 const double t0[9] = { d0, ab.
y, ab.
z, d1, ac.
y, ac.
z, d2, ad.
y, ad.
z };
154 const double t1[9] = { ab.
x, d0, ab.
z, ac.
x, d1, ac.
z, ad.
x, d2, ad.
z };
155 const double t2[9] = { ab.
x, ab.
y, d0, ac.
x, ac.
y, d1, ad.
x, ad.
y, d2 };
160 return (p.
x*p.
x+p.
y*p.
y+p.
z*p.
z-sqra+
161 2*(centerx*(a.
x-p.
x)+centery*(a.
y-p.
y)+centerz*(a.
z-p.
z)))<0;
167 const Coord& a,
const Coord& b,
double epsilon )
169 double xdiff = b.
x-a.
x;
170 double ydiff = b.
y-a.
y;
171 return ((p1.
x-a.
x)*ydiff-(p1.
y-a.
y)*xdiff)*
172 ((p2.
x-a.
x)*ydiff-(p2.
y-a.
y)*xdiff)>=-epsilon;
180 const Coord3 cpp1 = (b-a).cross(p1-a);
181 const Coord3 cpp2 = (b-a).cross(p2-a);
182 return cpp1.
dot(cpp2)>=-epsilon;
188 const Coord& c,
double epsilon )
190 if ( (p.
x>a.
x && p.
x>b.
x && p.
x>c.
x) || (p.
x<a.
x && p.
x<b.
x && p.
x<c.
x) ||
191 (p.
y>a.
y && p.
y>b.
y && p.
y>c.
y) || (p.
y<a.
y && p.
y<b.
y && p.
y<c.
y) )
202 bool useangularmethod )
204 if ( !useangularmethod )
217 const double d1 = ap.
dot( bp );
218 const double d2 = bp.
dot( cp );
219 const double d3 = cp.
dot( ap );
236 const Coord pa = p-a;
237 const Coord ba = b-a;
238 const double t = pa.
dot(ba)/ba.
sqAbs();
243 const Coord pq = p-intersectpt;
244 return pq.
sqAbs()<epsilon*epsilon;
253 const double t = pa.
dot(ba)/ba.
sqAbs();
257 const Coord3 pq = pa-t*ba;
258 return pq.
sqAbs()<epsilon*epsilon;
268 const int nrvertices = plgknots.
size();
271 const double newepsilon = plgknots[0].distTo(plgknots[1])*0.001;
272 return pointOnEdge3D( pt, plgknots[0], plgknots[1], newepsilon );
274 else if ( nrvertices==3 )
280 double anglesum = 0, cosangle;
281 for (
int idx=0; idx<nrvertices; idx++ )
283 p1 = plgknots[idx] - pt;
284 p2 = plgknots[(idx+1)%nrvertices] - pt;
286 const double d1 = p1.
abs();
287 const double d2 = p2.
abs();
288 if ( d1*d2 <= epsilon*epsilon || d1 <= epsilon || d2 <= epsilon )
291 cosangle = p1.
dot(p2) / (d1*d2);
293 anglesum += acos( cosangle );
296 return mIsEqual( anglesum, 6.2831853071795862, 1e-4 );
317 bool checkforundefs );
331 Quaternion(
double s,
double x,
double y,
double z);
332 Quaternion(
const Vector3& axis,
float angle);
334 void setRotation(
const Vector3& axis,
float angle);
335 void getRotation(
Vector3& axis,
float& angle)
const;
339 Quaternion operator+(
const Quaternion&)
const;
340 Quaternion& operator+=(
const Quaternion&);
341 Quaternion
operator-(
const Quaternion&)
const;
342 Quaternion& operator-=(
const Quaternion&);
343 Quaternion
operator*(
const Quaternion&)
const;
344 Quaternion& operator*=(
const Quaternion&);
346 Quaternion inverse()
const;
365 ParamLine2(
double slope=0,
double intcpt=0);
366 ParamLine2(
const Coord&,
double slope);
374 Coord getPoint(
double t)
const;
376 double closestPoint(
const Coord& point)
const;
383 double sqDistanceToPoint(
const Coord&)
const;
400 Line2(
double slope=0,
double intcpt=0);
401 Line2(
const Coord&,
double slope);
412 Coord intersection(
const Line2&,
bool checkinlimit=
true)
const;
414 double distanceTo(
const Line2&)
const;
416 bool getParallelLine(Line2& line,
double dist)
const;
418 bool getPerpendicularLine(Line2& line,
const Coord& pt)
const;
420 bool isOnLine(
const Coord& pt)
const;
445 Line3(
double x0,
double y0,
double z0,
446 double alpha,
double beta,
double gamma );
451 const Vector3 res( alpha_, beta_, gamma_ );
452 return normalize ? res.
normalize() : res;
455 Coord3 getPoint(
double t)
const;
462 double sqDistanceToPoint(
const Coord3& point )
const;
463 double closestPoint(
const Coord3& point )
const;
466 void closestPoint(
const Line3& line,
double& t_this,
467 double& t_line )
const;
488 Plane3(
double,
double,
double,
double);
502 void set(
const Coord3&,
const Coord3&,
const Coord3& );
515 bool wichside=
false )
const;
527 bool onSameSide(
const Coord3& p1,
const Coord3& p2);
586 : radius(r),theta(t),phi(p) {}
589 : radius((float) crd.x),theta((float) crd.y)
590 , phi((float) crd.z) {}
593 {
return !(oth == *
this); }
599 static const Sphere& nullSphere();
612 inline
bool Sphere::operator ==( const Sphere& s )
const 614 const float dr = radius-s.radius;
615 const float dt = theta-s.theta;
616 const float dp = phi-s.phi;
Quaternion is an extension to complex numbers.
Definition: trigonometry.h:328
#define mExpClass(module)
Definition: commondefs.h:160
double alpha_
Definition: trigonometry.h:387
Coord start_
Definition: trigonometry.h:428
Coord3 getProjection(const Coord3 &pos)
double alpha_
Definition: trigonometry.h:474
Vector3 direction(bool normalize=true) const
Definition: trigonometry.h:449
#define M_2PI
Definition: commondefs.h:70
int operator-(const DateInfo &di1, const DateInfo &di2)
Definition: dateinfo.h:129
double determinent33(const double *v)
Here are some commonly used functions to judge the position relation between point and line...
Definition: trigonometry.h:86
Coord3 vec01_
Definition: trigonometry.h:572
float radius
Definition: trigonometry.h:595
double y0_
Definition: trigonometry.h:472
bool pointInPolygon(const Coord3 &pt, const TypeSet< Coord3 > &plgknots, double epsilon)
Definition: trigonometry.h:265
Coord3 Vector3
Definition: trigonometry.h:301
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:53
DistType dot(const Coord3 &) const
Definition: coord.h:249
double yintcpt_
Definition: trigonometry.h:423
#define mGlobal(module)
Definition: commondefs.h:163
#define mIsZero(x, eps)
Definition: commondefs.h:53
double gamma_
Definition: trigonometry.h:476
bool isInsideCircumSphere(const Coord3 &p, const Coord3 &a, const Coord3 &b, const Coord3 &c, const Coord3 &d)
Definition: trigonometry.h:140
const Plane3 & plane() const
Definition: trigonometry.h:558
double y0_
Definition: trigonometry.h:386
bool sameSide2D(const Coord &p1, const Coord &p2, const Coord &a, const Coord &b, double epsilon)
Definition: trigonometry.h:166
bool intersectWith(const Line3 &, Coord3 &) const
Sphere(const Coord3 &crd)
Definition: trigonometry.h:588
A cartesian coordinate in 2D space.
Definition: coord.h:25
A Plane3 is a plane in space, with the equation: Ax + By + Cz + D = 0.
Definition: trigonometry.h:484
A Line3 is a line in space, with the following equations:
Definition: trigonometry.h:441
Defines a 2D coordinate system on a 3D plane and transforms between the 3D space and the coordinate s...
Definition: trigonometry.h:543
Coord stop_
Definition: trigonometry.h:429
#define mIsEqual(x, y, eps)
Definition: commondefs.h:54
double determinent44(const Coord3 &r0, const Coord3 &r1, const Coord3 &r2, const Coord3 &r3)
Definition: trigonometry.h:95
double B_
Definition: trigonometry.h:532
T sqAbs() const
Definition: geometry.h:369
TypeSet< Vector3 > * makeSphereVectorSet(double dangle)
Divides a sphere in a number of vectors, divided by approximately dangle from each other...
const Plane3 plane_
Definition: trigonometry.h:569
Coord3 cross(const Coord3 &) const
Definition: coord.h:253
bool pointInTriangle3D(const Coord3 &p, const Coord3 &a, const Coord3 &b, const Coord3 &c, double epsilon, bool useangularmethod)
Definition: trigonometry.h:200
bool onSameSide(const Coord3 &p1, const Coord3 &p2)
double D_
Definition: trigonometry.h:534
Coord3 estimateAverageVector(const TypeSet< Coord3 > &, bool normalize, bool checkforundefs)
Computes an average of a number of vectors using:
double A_
Definition: trigonometry.h:531
bool pointOnEdge2D(const Coord &p, const Coord &a, const Coord &b, double epsilon)
Definition: trigonometry.h:233
double beta_
Definition: trigonometry.h:475
Coord3 normalize() const
Definition: coord.h:257
double C_
Definition: trigonometry.h:533
const Coord3 origin_
Definition: trigonometry.h:570
float phi
Definition: trigonometry.h:597
T y
Definition: geometry.h:67
double z0_
Definition: trigonometry.h:473
void interpolateOnTriangle2D(const Coord pt, const Coord a, const Coord b, const Coord c, double &weight_a, double &weight_b, double &weight_c)
Given a point pt in a triangle ABC, we calculate the interpolation weights for each vertex...
Definition: trigonometry.h:27
double x0_
Definition: trigonometry.h:471
double x0_
Definition: trigonometry.h:385
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:62
Sphere(float r=0, float t=0, float p=0)
Definition: trigonometry.h:585
float theta
Definition: trigonometry.h:596
A cartesian coordinate in 3D space.
Definition: coord.h:72
double xintcpt_
Definition: trigonometry.h:426
OrdType z
Definition: coord.h:125
Coord3 operator*(double f, const Coord3 &b)
Definition: coord.h:130
size_type size() const
Definition: typeset.h:254
bool isvertical_
Definition: trigonometry.h:425
bool pointInTriangle2D(const Coord &p, const Coord &a, const Coord &b, const Coord &c, double epsilon)
Definition: trigonometry.h:187
bool sameSide3D(const Coord3 &p1, const Coord3 &p2, const Coord3 &a, const Coord3 &b, double epsilon)
Definition: trigonometry.h:177
T x
Definition: geometry.h:66
double s_
Definition: trigonometry.h:348
double slope_
Definition: trigonometry.h:422
A ParamLine2 is a line in space, with the following equations:
Definition: trigonometry.h:362
bool isInsideCircle(const Coord &pt, const Coord &p1, const Coord &p2, const Coord &p3)
Definition: trigonometry.h:123
Vector3 vec_
Definition: trigonometry.h:349
Represents a point in spherical coordinates. The angle phi lies in the horizontal plane...
Definition: trigonometry.h:582
Coord3 vec10_
Definition: trigonometry.h:571
bool pointOnEdge3D(const Coord3 &p, const Coord3 &a, const Coord3 &b, double epsilon)
Definition: trigonometry.h:248
double beta_
Definition: trigonometry.h:388
TrcKeyZSampling::Dir direction(TrcKeyZSampling::Dir slctype, int dimnr)
Definition: trckeyzsampling.h:139
bool isok_
Definition: trigonometry.h:573
Coord3 normal() const
Definition: trigonometry.h:512
Sphere cartesian2Spherical(const Coord3 &, bool math)
virtual ~Plane3CoordSystem()
Definition: trigonometry.h:553
double distanceToPoint(const Coord3 &, bool wichside=false) const
Coord3 spherical2Cartesian(const Sphere &, bool math)
OrdType dot(const Coord &) const
A Line2 is a line on XY-plane, and it is defined in slope-intercept form y = slope*x + y-intercept; f...
Definition: trigonometry.h:397