73 double d = x*plane[0] + y*plane[1] + z*plane[2] + plane[3];
83 if ( (d+epsilon) > 0 )
89 static void add(
const double *p,
double *dest,
unsigned int tstride,
unsigned int &pcount)
91 char *d = (
char *) dest;
92 d = d + pcount*tstride;
98 assert( pcount <= 4 );
103 static void intersect(
const double *p1,
const double *p2,
double *split,
const double *
plane)
111 dir[0] = p2[0] - p1[0];
112 dir[1] = p2[1] - p1[1];
113 dir[2] = p2[2] - p1[2];
115 double dot1 = dir[0]*plane[0] + dir[1]*plane[1] + dir[2]*plane[2];
116 double dot2 = dp1 - plane[3];
118 double t = -(plane[3] + dot2 ) / dot1;
120 split[0] = (dir[0]*t)+p1[0];
121 split[1] = (dir[1]*t)+p1[1];
122 split[2] = (dir[2]*t)+p1[2];
132 void set(
const double *p)
151 polygon(
const double *p1,
const double *p2,
const double *p3)
154 mVertices[0].set(p1);
155 mVertices[1].set(p2);
156 mVertices[2].set(p3);
164 if ( index < 0 ) index+=mVcount;
165 return mVertices[index];
169 void set(
const point *pts,
int count)
171 for (
int i=0; i<count; i++)
173 mVertices[i] = pts[i];
195 return p.
x*normal.x + p.
y*normal.y + p.
z*normal.z + D;
205 int out_c = 0, in_c = 0;
208 ptA = poly->
Vertex (count - 1);
210 for (
int i = -1; ++i < count;)
220 outpts[out_c++] = inpts[in_c++] = v;
222 outpts[out_c++] = ptB;
230 outpts[out_c++] = inpts[in_c++] = v;
235 outpts[out_c++] = inpts[in_c++] = ptB;
240 front.
set(&outpts[0], out_c);
241 back.
set(&inpts[0], in_c);
245 const double *triangle,
246 unsigned int tstride,
249 unsigned int &fcount,
251 unsigned int &bcount)
257 const char *tsource = (
const char *) triangle;
260 const double *p1 = (
const double *) (tsource);
261 const double *p2 = (
const double *) (tsource+tstride);
262 const double *p3 = (
const double *) (tsource+tstride*2);
269 if ( r1 == r2 && r1 == r3 )
273 add(p1,front,tstride,fcount);
274 add(p2,front,tstride,fcount);
275 add(p3,front,tstride,fcount);
279 add(p1,back,tstride,bcount);
280 add(p2,back,tstride,bcount);
281 add(p3,back,tstride,bcount);
293 for (
int i=0; i<pfront.
mVcount; i++)
298 for (
int i=0; i<pback.
mVcount; i++)
305 if ( fcount == 0 && bcount )
308 if ( bcount == 0 && fcount )
polygon(const double *p1, const double *p2, const double *p3)
static double DistToPt(const double *p, const double *plane)
const point & Vertex(int index)
int NumVertices(void) const
void set(const point *pts, int count)
PlaneTriResult planeTriIntersection(const double *_plane, const double *triangle, unsigned int tstride, double epsilon, double *front, unsigned int &fcount, double *back, unsigned int &bcount)
double Classify_Point(const point &p)
static PlaneTriResult getSidePlane(const double *p, const double *plane, double epsilon)
static void add(const double *p, double *dest, unsigned int tstride, unsigned int &pcount)
static void intersect(const double *p1, const double *p2, double *split, const double *plane)
void Split_Polygon(polygon *poly, plane *part, polygon &front, polygon &back)