SrReal SrRay3D::distanceRaySquared(const SrRay3D& ray)const
{
	SrVector3D u = mBase - ray.mBase;
	SrReal a = mDirection.dot(mDirection);
	SrReal b = mDirection.dot(ray.mDirection);
	SrReal c = ray.mDirection.dot(ray.mDirection);
	SrReal d = mDirection.dot(u);
	SrReal e = ray.mDirection.dot(u);
	SrReal det = a*c - b*b;
	SrReal sNum,sDenom,tNum,tDenom;
	tDenom = sDenom = det;
	if( EQUAL(det,0) )
	{
		sNum = 0;
		tNum = e;
		tDenom = c;
	}
	else
	{
		sNum = b*e - c*d;
		tNum = a*e - b*d;
	}
	//check s
	if( LESS(sNum,0) )
	{
		sNum = 0;
		tNum = e;
		tDenom = c;
	}
	//check t
	if( LESS(tNum,0) )
	{
		tNum = 0;
		if( LESS(-d,0) )
		{
			sNum = 0;
		}
		else
		{
			sNum = -d;
			sDenom = a;
		}
	}
	// Parameters of nearest points on restricted domain
	SrReal s = 0  , t = 0;
	if( UNEQUAL(sDenom,0) )
		s= sNum / sDenom ;
	if( UNEQUAL(tDenom,0) )
		t = tNum / tDenom;
	SrVector3D v = u + s*mDirection - t*ray.mDirection;
	return v.dot(v);
}
Beispiel #2
0
double kernel::GaussianKernel(const std::vector<double> &X,
                              const std::vector<double> &Y,
                              double sigma)
{
    /**
     *  RBF kernel function
     */
    double _res = 0;
    EQUAL(X.size(), Y.size());
    UNEQUAL(sigma, 0);
    
    for (unsigned long i = 0; i < X.size(); ++i)
    {
        double diff = X[i] - Y[i];
        _res += diff * diff;
    }
    _res = _res / (-sigma * sigma);
    _res = std::exp(_res);
    return _res;
}
Beispiel #3
0
TEST(Fail, _unequal)
{
  UNEQUAL("Yaffut", "Yaffut");
}
SrReal SrRay3D::distanceSegmentSquared(const SrSegment3D& segment)const
{
	SrVector3D direction = segment.mPoint2 - segment.mPoint1;
	SrVector3D u = mBase - segment.mPoint1;
	SrReal a = mDirection.dot(mDirection);
	SrReal b = mDirection.dot(direction);
	SrReal c = direction.dot(direction);
	SrReal d = mDirection.dot(u);
	SrReal e = direction.dot(u);
	SrReal det = a*c - b*b;
	SrReal sNum,sDenom,tNum,tDenom;
	tDenom = sDenom = det;
	if( EQUAL(det,0) )
	{
		sNum = 0;
		tNum = e;
		tDenom = c;
	}
	else
	{
		sNum = b*e - c*d;
		tNum = a*e - b*d;
	}
	//check s
	if( LESS(sNum,0) )
	{
		sNum = 0;
		tNum = e;
		tDenom = c;
	}

	//check t
	if( LESS(tNum,0) )
	{
		tNum = 0;
		if( LESS(-d,0) )
		{
			sNum = 0;
		}
		else
		{
			sNum = -d;
			sDenom  = a;
		}
	}
	else if( GREATER(tNum,tDenom) )
	{
		tNum = tDenom;
		if( LESS((-d + b),0) )
			sNum = 0;
		else
		{
			sNum = -d + b;
			sDenom = a;
		}
	}
	// Parameters of nearest points on restricted domain
	SrReal s = 0  , t = 0;
	if( UNEQUAL(sDenom,0) )
		s= sNum / sDenom ;
	if( UNEQUAL(tDenom,0) )
		t = tNum / tDenom;

	SrVector3D v = u + s*mDirection - t*direction;
	return v.dot(v);
}