Esempio n. 1
0
int InCircle(const Point2d& a, const Point2d& b,
			 const Point2d& c, const Point2d& d)
// Returns TRUE if the point d is inside the circle defined by the
// points a, b, c. See Guibas and Stolfi (1985) p.107.
{
	return (a.x*a.x + a.y*a.y) * TriArea(b, c, d) -
	       (b.x*b.x + b.y*b.y) * TriArea(a, c, d) +
	       (c.x*c.x + c.y*c.y) * TriArea(a, b, d) -
	       (d.x*d.x + d.y*d.y) * TriArea(a, b, c) > 0;
}
Esempio n. 2
0
void CalcUVMapPolygon(Object *obj, Vec3 *P, double *u, double *v)
{
  PolygonData *p = obj->data.polygon;
	double area, a1, a2, a3, pu, pv;
	float *P1, *P2, *P3;
	int A, B;

	/*
	 * Project the triangle vertices to the 2D plane
	 * that is most perpendicular to the plane normal.
	 * We use the triangle formed by the first three vertices
	 * of the polygon.
	 */
	switch(p->axis )
	{
		case X_AXIS:
			A = 1;
			B = 2;
			pu = P->y;
			pv = P->z;
			break;
		case Y_AXIS:
			A = 0;
			B = 2;
			pu = P->x;
			pv = P->z;
			break;
		default:  /* Z_AXIS. */
			A = 0;
			B = 1;
			pu = P->x;
			pv = P->y;
			break;
	}

	P1 = p->pts;
	P2 = &p->pts[3];
	P3 = &p->pts[6];

	/* Determine barycentric coordinates of point... */
	area = TriArea(P1[A], P1[B], P2[A], P2[B], P3[A], P3[B]);
	a1 =   TriArea(pu, pv, P2[A], P2[B], P3[A], P3[B]) / area;
	a2 =   TriArea(P1[A], P1[B], pu, pv, P3[A], P3[B]) / area;
	a3 =   1.0 - a1 - a2;

	/*
	 * ...and use them to interpolate between the UV coordinates
	 * for each vertex to get actual UV position.
	 */
	*u = 1.0 - a1;
	*v = a3;
}
static void TriDlDx(double dldx[][2], double const_term[],
                    const double p0[], const double p1[], const double p2[]){
  
	const double area = TriArea(p0,p1,p2);
	const double tmp1 = 0.5 / area;
  
	const_term[0] = tmp1*(p1[0]*p2[1]-p2[0]*p1[1]);
	const_term[1] = tmp1*(p2[0]*p0[1]-p0[0]*p2[1]);
	const_term[2] = tmp1*(p0[0]*p1[1]-p1[0]*p0[1]);
  
	dldx[0][0] = tmp1*(p1[1]-p2[1]);
	dldx[1][0] = tmp1*(p2[1]-p0[1]);
	dldx[2][0] = tmp1*(p0[1]-p1[1]);
  
	dldx[0][1] = tmp1*(p2[0]-p1[0]);
	dldx[1][1] = tmp1*(p0[0]-p2[0]);
	dldx[2][1] = tmp1*(p1[0]-p0[0]);
}
Esempio n. 4
0
int ccw(const Point2d& a, const Point2d& b, const Point2d& c)
// Returns TRUE if the points a, b, c are in a counterclockwise order
{
	return (TriArea(a, b, c) > 0);
}