bool IsHyperplane(const Point2D& p0, const Point2D& p1, const Point2D& q)
{
	Vector2D e = p1 - p0;
	Vector2D norm = Vector2D(-e.y, e.x);
	printf("		%f\n",norm.dot(q - p0));
	if( GREATER(norm.dot(q - p0) , 0) )
		return true;
	return false;
}
Vector2D
Vector2D::proj(Vector2D s, Vector2D t)
{

	t.normalise();
	Vector2D proj = t;
	float multiple = proj.dot(s, t) / proj.dot(t, t);
	proj.mult(multiple);
	return proj;

}
/*
\brief 暴力算法,求多边形上方向是u的极点,设凸多边形是逆时针顺序的。
*/
int ExtremePoint_Naive( const Point2D* p, int n, const Vector2D& u)
{
	int i , mxI = 0;
	int count = 0;
	Real mx = u.dot(p[0]);
	for( i=1 ; i<n ; i++ )
	{
		if( u.dot(p[i]) > mx )
		{
			mx = u.dot(p[i]);
			mxI = i;
		}
	}
	return mxI;
}
/*
\brief 判断e与u是否同方向。
\return	返回1,	若e与u同方向;
		返回0,	若e与u垂直;
		返回-1,若e与u方向相反;
*/
int Direction(const Vector2D& e, const Vector2D& u)
{
	Real d = e.dot(u);
	if( fabs(d) < EPS )	return 0;
	if( d < 0 )		return -1;
	return 1;
}
Example #5
0
 int intersect(const Circle2D& c, Vector2D& p1, Vector2D& p2) {
     if(center == c.center) {
         if(noEps(r - c.r) == 0) return -1; // overlap
         else return 0;
     }
     Vector2D v0 = Vector2D((c.center - center)*2);
     double u = c.center.dot(c.center) - center.dot(center) + sqr(r) - sqr(c.r);
     if(noEps(v0.x) != 0) return intersect(Line2D(Vector2D(u/v0.x, 0), ~v0), p1, p2);
     else return intersect(Line2D(Vector2D(0, u/v0.y), ~v0), p1, p2);
 }
double SurfaceToImplicit2::signedDistanceLocal(
    const Vector2D& otherPoint) const {
    Vector2D x = _surface->closestPoint(otherPoint);
    Vector2D n = _surface->closestNormal(otherPoint);
    n = (isNormalFlipped) ? -n : n;
    if (n.dot(otherPoint - x) < 0.0) {
        return -x.distanceTo(otherPoint);
    } else {
        return x.distanceTo(otherPoint);
    }
}
int IsPointInConv(const Point2D* v, int n, const Point2D& p)
{
	int left = 0 , right = 0 , middle;
	Vector2D edge , normal;
	Real tmp;
	while(true)
	{
		if( (right - left + n) % n == 1 )
		{
			edge = v[right] - v[left];
			Vector2D e0 = p - v[left];
			normal.set(edge.y , -edge.x);
			tmp = normal.dot(e0);
			if( GREATER(tmp,0) )
				return OUTSIDE;
			else if( LESS(tmp,0) )
				return INSIDE;
			if( LESS(edge.dot(e0),0) )
				return OUTSIDE;
			SrVector2D e1 = p - v[right];
			if( GREATER(edge.dot(e1),0) )
				return OUTSIDE;
			return ON;
		}
		middle = left < right?((left + right) >> 1):((left + right + n) >> 1) % n;

		edge = v[middle] - v[left];
		normal.set(edge.y , -edge.x);

		tmp = normal.dot(p - v[left]);
		if( GEQUAL(tmp,0) )
			right = middle;
		else
			left = middle;
	}
}
/*
\brief 判断点a是否在b的下方。
*/
bool IsBelow(const Point2D& a , const Point2D& b, const Vector2D& u)
{
	return u.dot(a-b) < 0;
}
/*
\brief 判断点a是否在b的上方。
*/
bool IsAbove(const Point2D& a , const Point2D& b, const Vector2D& u)
{
	return u.dot(a-b) > 0;
}