46 int trimax,emax = 200;
51 double xp,yp,x1,y1,x2,y2,x3,y3,xc,yc,r;
52 double xmin,xmax,ymin,ymax,xmid,ymid;
57 if ((complete = malloc(trimax*
sizeof(
int))) == NULL) {
63 if ((edges = malloc(emax*(
long)
sizeof(
IEDGE))) == NULL) {
77 if (pxyz[i].x < xmin) xmin = pxyz[i].
x;
78 if (pxyz[i].x > xmax) xmax = pxyz[i].
x;
79 if (pxyz[i].y < ymin) ymin = pxyz[i].
y;
80 if (pxyz[i].y > ymax) ymax = pxyz[i].
y;
84 dmax = (dx > dy) ? dx : dy;
85 xmid = (xmax + xmin) / 2.0;
86 ymid = (ymax + ymin) / 2.0;
95 pxyz[nv+0].
x = xmid - 20 * dmax;
96 pxyz[nv+0].
y = ymid - dmax;
99 pxyz[nv+1].
y = ymid + 20 * dmax;
101 pxyz[nv+2].
x = xmid + 20 * dmax;
102 pxyz[nv+2].
y = ymid - dmax;
125 for (j=0;j<(*ntri);j++) {
128 x1 = pxyz[v[j].
p1].
x;
129 y1 = pxyz[v[j].
p1].
y;
130 x2 = pxyz[v[j].
p2].
x;
131 y2 = pxyz[v[j].
p2].
y;
132 x3 = pxyz[v[j].
p3].
x;
133 y3 = pxyz[v[j].
p3].
y;
134 inside =
CircumCircle(xp,yp,x1,y1,x2,y2,x3,y3,&xc,&yc,&r);
135 if (xc < xp && ((xp-xc)*(xp-xc)) > r)
139 if (nedge+3 >= emax) {
141 if ((edges = realloc(edges,emax*(
long)
sizeof(
IEDGE))) == NULL) {
146 edges[nedge+0].
p1 = v[j].
p1;
147 edges[nedge+0].
p2 = v[j].
p2;
148 edges[nedge+1].
p1 = v[j].
p2;
149 edges[nedge+1].
p2 = v[j].
p3;
150 edges[nedge+2].
p1 = v[j].
p3;
151 edges[nedge+2].
p2 = v[j].
p1;
154 complete[j] = complete[(*ntri)-1];
165 for (j=0;j<nedge-1;j++) {
166 for (k=j+1;k<nedge;k++) {
167 if ((edges[j].p1 == edges[k].p2) && (edges[j].p2 == edges[k].p1)) {
174 if ((edges[j].p1 == edges[k].p1) && (edges[j].p2 == edges[k].p2)) {
188 for (j=0;j<nedge;j++) {
189 if (edges[j].p1 < 0 || edges[j].p2 < 0)
191 if ((*ntri) >= trimax) {
195 v[*ntri].
p1 = edges[j].
p1;
196 v[*ntri].
p2 = edges[j].
p2;
198 complete[*ntri] =
FALSE;
207 for (i=0;i<(*ntri);i++) {
208 if (v[i].p1 >= nv || v[i].p2 >= nv || v[i].p3 >= nv) {
228 double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
229 double *xc,
double *yc,
double *rsqr)
231 double m1,m2,mx1,mx2,my1,my2;
233 double fabsy1y2 = fabs(y1-y2);
234 double fabsy2y3 = fabs(y2-y3);
241 m2 = - (x3-x2) / (y3-y2);
242 mx2 = (x2 + x3) / 2.0;
243 my2 = (y2 + y3) / 2.0;
244 *xc = (x2 + x1) / 2.0;
245 *yc = m2 * (*xc - mx2) + my2;
246 }
else if (fabsy2y3 <
EPSILON) {
247 m1 = - (x2-x1) / (y2-y1);
248 mx1 = (x1 + x2) / 2.0;
249 my1 = (y1 + y2) / 2.0;
250 *xc = (x3 + x2) / 2.0;
251 *yc = m1 * (*xc - mx1) + my1;
253 m1 = - (x2-x1) / (y2-y1);
254 m2 = - (x3-x2) / (y3-y2);
255 mx1 = (x1 + x2) / 2.0;
256 mx2 = (x2 + x3) / 2.0;
257 my1 = (y1 + y2) / 2.0;
258 my2 = (y2 + y3) / 2.0;
259 *xc = (m1 * mx1 - m2 * mx2 + my2 - my1) / (m1 - m2);
260 if (fabsy1y2 > fabsy2y3) {
261 *yc = m1 * (*xc - mx1) + my1;
263 *yc = m2 * (*xc - mx2) + my2;
269 *rsqr = dx*dx + dy*dy;
273 drsqr = dx*dx + dy*dy;
int Triangulate(int nv, XYZ *pxyz, ITRIANGLE *v, int *ntri)
int CircumCircle(double xp, double yp, double x1, double y1, double x2, double y2, double x3, double y3, double *xc, double *yc, double *rsqr)