//判断两直线的位置关系
int line_to_line(const Line &u, const Line &v)
{
    Plane s1(u.a, u.b, v.a), s2(u.a, u.b, v.b);
    if (sgn((pvec(s1) ^ pvec(s2)).norm())) return -1;//异面
    else if(parallel(u, v)) return 0;//平行
    else return 1;//相交
}
Exemplo n.º 2
0
 plane(point3 _a,point3 _b,point3 _c)
 {
     a=_a;
     b=_b;
     c=_c;
     o=pvec();
 }
Exemplo n.º 3
0
std::vector<float> SimpleRayCaster::castRay(Eigen::Vector2f &p) {

    std::vector<float> zvalues;

    /* distort the point with the lens parameters */
    Eigen::Vector2f pDist = distortPoint(p);

    /* convert 2d coordinate (0.0-1.0) to proper image coordinate */
    Eigen::Vector3f aP(pDist[0]*_res_x, 
                       pDist[1]*_res_y, 
                       1.0); 

    /* project with inverse camera calibration matrix 
     * to 3d vector in camera space */
    cv::Mat ptMat = (cv::Mat_<float>(3,1) << aP[0], aP[1], aP[2]);
    cv::Mat vec3d = _inverseCamMat * ptMat; 
    Eigen::Vector3f pvec(vec3d.at<float>(0,0),
                         vec3d.at<float>(1,0),
                         vec3d.at<float>(2,0));

    std::vector<Eigen::Vector3f> isecs = intersectRay(pvec);
    for (auto isec : isecs) {
        zvalues.push_back(isec.norm());
    }

    return zvalues;
}
Exemplo n.º 4
0
    Intersection Triangle::intersect(const Ray &r) const
    {
         const Vec3t edge1(V1-V0), edge2(V2-V0); // could precalculate
         Vec3t pvec(cross(r.getNormal(), edge2));
         DefType det=dot(edge1,pvec);

         if (det < MM_EPSILON)
             return Intersection();

         Vec3t tvec(r.getPoint()-V0);
         DefType u=dot(tvec,pvec);

         if (u < 0 || u > det)
             return Intersection();

         Vec3t qvec(cross(tvec,edge1));

         DefType v=dot(r.getPoint(),qvec);

         if (v < 0 || u+v > det)
             return Intersection();

         DefType t=dot(edge2, qvec)/det;

         return Intersection(r.positionAtTime(t), m_normal, t, true, true);
    }
Exemplo n.º 5
0
bool AmbientOcclusionEngine::rayIntersectsTriangle(Vec const& origin, Vec const& ray, 
   unsigned const triangle)
{
   Vec a(vertex(3*triangle+0));
   Vec b(vertex(3*triangle+1));
   Vec c(vertex(3*triangle+2));

   Vec ab(b-a);
   Vec ac(c-a);
   Vec pvec(ray^ac);

   double det(ab*pvec);
   if (std::abs(det) < Epsilon) return false;
   double invDet(1.0/det);

   Vec tvec(origin-a);
   double u(tvec*pvec);
   u *= invDet;
   if (u < 0.0 || u > 1.0) return false;

   Vec qvec(tvec^ab);
   double v(invDet*(ray*qvec));
   if (v < 0.0 || u + v > 1.0) return false;

   double t(ac*qvec);

   return t > Epsilon;
}
Exemplo n.º 6
0
/*!

\brief Decomposes the Matrix into three Euler angles.
\param[out] hy Heading in radians.
\param[out] px Pitch in radians.
\param[out] rz Roll in radians.

*/
void
dmz::Matrix::to_euler_angles (Float64 &hy, Float64 &px, Float64 &rz)  const {

   Vector hvec (Forward), pvec (Forward), rvec (Up);
   transform_vector(hvec);
   Matrix cmat (*this), hmat, pmat, rmat;

   hvec.set_y (0.0);

   if (hvec.is_zero ()) { hy = 0.0; }
   else {

      hvec.normalize_in_place ();
      hy = Forward.get_signed_angle (hvec);
      hmat.from_axis_and_angle (Up, hy);
      hmat.transpose_in_place ();
      cmat = hmat * cmat;
   }

   cmat.transform_vector (pvec);

   if (is_zero64 (pvec.get_y ())) { px = 0.0; }
   else {

      px = Forward.get_signed_angle (pvec);
      pmat.from_axis_and_angle (Right, px);
      pmat.transpose_in_place ();
      cmat = pmat * cmat;
   }

   cmat.transform_vector (rvec);

   if (is_zero64 (rvec.get_x ())) { rz = 0.0; }
   else { rz = Up.get_signed_angle (rvec); }
}
Exemplo n.º 7
0
 void input()
 {
     a.input();
     b.input();
     c.input();
     o=pvec();
 }
//直线与平面关系
int line_to_plane(const Line &u, const Plane &s)
{
    if (sgn(pvec(s) * (u.b - u.a)) == 0)
    {
        if (point_on_plane(u.a, s)) return -1;//直线在平面上
        else return 0;//直线平行于平面
    }
    else return 1;//线面相交
}
void CollisionFace::RayTrace(const VC3 &position, const VC3 &direction, float ray_length, Storm3D_CollisionInfo &rti, bool accurate)
{
	// Begin calculating determinant - also used to calculate U parameter
	VC3 pvec(direction.y * e02.z - direction.z * e02.y, direction.z * e02.x - direction.x * e02.z, direction.x * e02.y - direction.y * e02.x);

	// If determinant is near zero, ray lies in plane of triangle
	float det = e01.x * pvec.x + e01.y*pvec.y + e01.z * pvec.z;
	if(det < 0.0001f) 
		return;

	// Calculate distance from vert0 to ray origin
	VC3 tvec(position.x - vertex0.x, position.y - vertex0.y, position.z - vertex0.z);

	// Calculate U parameter and test bounds
	float u = tvec.x * pvec.x + tvec.y * pvec.y + tvec.z * pvec.z;
	if((u < 0) || (u > det)) 
		return;

	// Prepare to test V parameter
	VC3 qvec(tvec.y * e01.z - tvec.z * e01.y, tvec.z * e01.x - tvec.x * e01.z, tvec.x * e01.y - tvec.y * e01.x);
	
	// Calculate V parameter and test bounds
	float v = direction.x * qvec.x + direction.y * qvec.y + direction.z * qvec.z;
	if((v < 0) || ((u + v) > det))
		return;

	// Calculate t, scale parameters, ray intersects triangle
	float t = e02.x * qvec.x + e02.y * qvec.y + e02.z * qvec.z;
	t /= det;

	// Set collision info
	if((t < rti.range) && (t < ray_length) && (t > 0))
	{
		rti.hit = true;
		rti.range = t;
		rti.position = position+direction*t;
		rti.plane_normal = plane.planenormal;
	}
}
Exemplo n.º 10
0
/*!

\brief Creates a Matrix from a single Vector.
\details The Matrix will look in the direction of the given vector. The Matrix will
only update heading a pitch and will not contain a roll component.
\param[in] Direction Vector pointing in the direction to look.

*/
void
dmz::Matrix::from_vector (const Vector &Direction) {

   Vector hvec (Direction), pvec (Direction);
   Matrix hmat, pmat;

   hvec.set_y (0.0);

   if (!hvec.is_zero ()) {

      hvec.normalize_in_place ();
      hmat.from_axis_and_angle (Up, Forward.get_signed_angle (hvec));
   }

   hmat.transpose ().transform_vector (pvec);

   if (!is_zero64 (pvec.get_y ())) {

      pmat.from_axis_and_angle (Right, Forward.get_signed_angle (pvec));
   }

   *this = hmat * pmat;
}
//线面求交
Point line_plane_intersection(const Line &u, const Plane &s)
{
    Point ret = pvec(s), der = u.b - u.a;
    double t = ret * (s.a - u.a) / (ret * (u.b - u.a));
    return u.a + der * t;
}
Exemplo n.º 12
0
main()
{
	int i,n=N;

	printf("isamax = %d\n",isamax(n,sx,1));
	printf("isamax = %d\n",isamax(n/2,sx,2));
	printf("isamax = %d\n",isamax(n,sy,1));

	printf("sasum = %g\n",sasum(n,sx,1));
	printf("sasum = %g\n",sasum(n/2,sx,2));
	printf("sasum = %g\n",sasum(n,sy,1));

	printf("snrm2 = %g\n",snrm2(n,sx,1));
	printf("snrm2 = %g\n",snrm2(n/2,sx,2));
	printf("snrm2 = %g\n",snrm2(n,sy,1));

	printf("sdot = %g\n",sdot(n,sx,1,sy,1));
	printf("sdot = %g\n",sdot(n/2,sx,2,sy,2));
	printf("sdot = %g\n",sdot(n/2,sx,-2,sy,2));
	printf("sdot = %g\n",sdot(n,sy,1,sy,1));

	printf("sscal\n");
	sscal(n,2.0,sx,1);
	pvec(n,sx);
	sscal(n,0.5,sx,1);
	pvec(n,sx);
	sscal(n/2,2.0,sx,2);
	pvec(n,sx);
	sscal(n/2,0.5,sx,2);
	pvec(n,sx);

	printf("sswap\n");
	sswap(n,sx,1,sy,1);
	pvec(n,sx); pvec(n,sy);
	sswap(n,sy,1,sx,1);
	pvec(n,sx); pvec(n,sy);
	sswap(n/2,sx,1,sx+n/2,-1);
	pvec(n,sx);
	sswap(n/2,sx,1,sx+n/2,-1);
	pvec(n,sx);
	sswap(n/2,sx,2,sy,2);
	pvec(n,sx); pvec(n,sy);
	sswap(n/2,sx,2,sy,2);
	pvec(n,sx); pvec(n,sy);

	printf("saxpy\n");
	saxpy(n,2.0,sx,1,sy,1);
	pvec(n,sx); pvec(n,sy);
	saxpy(n,-2.0,sx,1,sy,1);
	pvec(n,sx); pvec(n,sy);
	saxpy(n/2,2.0,sx,2,sy,2);
	pvec(n,sx); pvec(n,sy);
	saxpy(n/2,-2.0,sx,2,sy,2);
	pvec(n,sx); pvec(n,sy);
	saxpy(n/2,2.0,sx,-2,sy,1);
	pvec(n,sx); pvec(n,sy);
	saxpy(n/2,-2.0,sx,-2,sy,1);
	pvec(n,sx); pvec(n,sy);

	printf("scopy\n");
	scopy(n/2,sx,2,sy,2);
	pvec(n,sx); pvec(n,sy);
	scopy(n/2,sx+1,2,sy+1,2);
	pvec(n,sx); pvec(n,sy);
	scopy(n/2,sx,2,sy,1);
	pvec(n,sx); pvec(n,sy);
	scopy(n/2,sx+1,-2,sy+n/2,-1);
	pvec(n,sx); pvec(n,sy);
}
Exemplo n.º 13
0
int dots_onplane(point a, point b, point c, point d){
    return zero(Dot(pvec(a,b,c), d-a));
}
//判定两点在平面同侧,点在平面上返回0
bool same_side(const Point &p1, const Point &p2, const Plane &s)
{
    return (pvec(s) * (p1 - s.a)) * (pvec(s) * (p2 - s.a)) > eps;
}
Exemplo n.º 15
0
int main(void)
{
int i, nerrors, k, ianswer, ntests;
double (*fun1) (double);
double (*fun2) (double, double);
int (*fun3) (double);
double e;
union {double d;char c[8];} u, v;
struct oneargument test1[] =
{
  {"atan", atan, &ONE, &PIO4, 0},
  {"sin", sin, &PIO2, &ONE, 0},
#if 0
  {"cos", cos, &PIO4, &SQRTH, 0},
  {"sin", sin, 32767., 1.8750655394138942394239E-1, 0},
  {"cos", cos, 32767., 9.8226335176928229845654E-1, 0},
  {"tan", tan, 32767., 1.9089234430221485740826E-1, 0},
  {"sin", sin, 8388607., 9.9234509376961249835628E-1, 0},
  {"cos", cos, 8388607., -1.2349580912475928183718E-1, 0},
  {"tan", tan, 8388607., -8.0354556223613614748329E0, 0},
  /*
  {"sin", sin, 2147483647., -7.2491655514455639054829E-1, 0},
  {"cos", cos, 2147483647., -6.8883669187794383467976E-1, 0},
  {"tan", tan, 2147483647., 1.0523779637351339136698E0, 0},
  */
  {"cos", cos, &PIO2, 6.1232339957367574e-17, 1},
  {"sin", sin, &PIO4, &SQRTH, 1},
#endif
  {"acos", acos, &nan, &nan, 0},
  {"acos", acos, &ONE, &ZERO, 0},
  {"acos", acos, &TWO, &nan, 0},
  {"acos", acos, &MTWO, &nan, 0},
  {"asin", asin, &nan, &nan, 0},
  {"asin", asin, &ZERO, &ZERO, 0},
  {"asin", asin, &MZERO, &MZERO, 0},
  {"asin", asin, &TWO, &nan, 0},
  {"asin", asin, &MTWO, &nan, 0},
  {"atan", atan, &nan, &nan, 0},
  {"atan", atan, &ZERO, &ZERO, 0},
  {"atan", atan, &MZERO, &MZERO, 0},
  {"atan", atan, &INF, &PIO2, 0},
  {"atan", atan, &MINF, &MPIO2, 0},
  {"cos", cos, &nan, &nan, 0},
  {"cos", cos, &ZERO, &ONE, 0},
  {"cos", cos, &MZERO, &ONE, 0},
  {"cos", cos, &INF, &nan, 0},
  {"cos", cos, &MINF, &nan, 0},
  {"sin", sin, &nan, &nan, 0},
  {"sin", sin, &MZERO, &MZERO, 0},
  {"sin", sin, &ZERO, &ZERO, 0},
  {"sin", sin, &INF, &nan, 0},
  {"sin", sin, &MINF, &nan, 0},
  {"tan", tan, &nan, &nan, 0},
  {"tan", tan, &ZERO, &ZERO, 0},
  {"tan", tan, &MZERO, &MZERO, 0},
  {"tan", tan, &INF, &nan, 0},
  {"tan", tan, &MINF, &nan, 0},
  {"acosh", acosh, &nan, &nan, 0},
  {"acosh", acosh, &ONE, &ZERO, 0},
  {"acosh", acosh, &INF, &INF, 0},
  {"acosh", acosh, &HALF, &nan, 0},
  {"acosh", acosh, &MONE, &nan, 0},
  {"asinh", asinh, &nan, &nan, 0},
  {"asinh", asinh, &ZERO, &ZERO, 0},
  {"asinh", asinh, &MZERO, &MZERO, 0},
  {"asinh", asinh, &INF, &INF, 0},
  {"asinh", asinh, &MINF, &MINF, 0},
  {"atanh", atanh, &nan, &nan, 0},
  {"atanh", atanh, &ZERO, &ZERO, 0},
  {"atanh", atanh, &MZERO, &MZERO, 0},
  {"atanh", atanh, &ONE, &INF, 0},
  {"atanh", atanh, &MONE, &MINF, 0},
  {"atanh", atanh, &TWO, &nan, 0},
  {"atanh", atanh, &MTWO, &nan, 0},
  {"cosh", cosh, &nan, &nan, 0},
  {"cosh", cosh, &ZERO, &ONE, 0},
  {"cosh", cosh, &MZERO, &ONE, 0},
  {"cosh", cosh, &INF, &INF, 0},
  {"cosh", cosh, &MINF, &INF, 0},
  {"sinh", sinh, &nan, &nan, 0},
  {"sinh", sinh, &ZERO, &ZERO, 0},
  {"sinh", sinh, &MZERO, &MZERO, 0},
  {"sinh", sinh, &INF, &INF, 0},
  {"sinh", sinh, &MINF, &MINF, 0},
  {"tanh", tanh, &nan, &nan, 0},
  {"tanh", tanh, &ZERO, &ZERO, 0},
  {"tanh", tanh, &MZERO, &MZERO, 0},
  {"tanh", tanh, &INF, &ONE, 0},
  {"tanh", tanh, &MINF, &MONE, 0},
  {"exp", exp, &nan, &nan, 0},
  {"exp", exp, &ZERO, &ONE, 0},
  {"exp", exp, &MZERO, &ONE, 0},
  {"exp", exp, &INF, &INF, 0},
  {"exp", exp, &MINF, &ZERO, 0},
#if 0
  {"exp2", exp2, &nan, &nan, 0},
  {"exp2", exp2, &ZERO, &ONE, 0},
  {"exp2", exp2, &MZERO, &ONE, 0},
  {"exp2", exp2, &INF, &INF, 0},
  {"exp2", exp2, &MINF, &ZERO, 0},
#endif
  {"expm1", expm1, &nan, &nan, 0},
  {"expm1", expm1, &ZERO, &ZERO, 0},
  {"expm1", expm1, &MZERO, &MZERO, 0},
  {"expm1", expm1, &INF, &INF, 0},
  {"expm1", expm1, &MINF, &MONE, 0},
  {"log", log, &nan, &nan, 0},
  {"log", log, &ZERO, &MINF, 0},
  {"log", log, &MZERO, &MINF, 0},
  {"log", log, &ONE, &ZERO, 0},
  {"log", log, &MONE, &nan, 0},
  {"log", log, &INF, &INF, 0},
  {"log10", log10, &nan, &nan, 0},
  {"log10", log10, &ZERO, &MINF, 0},
  {"log10", log10, &MZERO, &MINF, 0},
  {"log10", log10, &ONE, &ZERO, 0},
  {"log10", log10, &MONE, &nan, 0},
  {"log10", log10, &INF, &INF, 0},
  {"log1p", log1p, &nan, &nan, 0},
  {"log1p", log1p, &ZERO, &ZERO, 0},
  {"log1p", log1p, &MZERO, &MZERO, 0},
  {"log1p", log1p, &MONE, &MINF, 0},
  {"log1p", log1p, &MTWO, &nan, 0},
  {"log1p", log1p, &INF, &INF, 0},
#if 0
  {"log2", log2, &nan, &nan, 0},
  {"log2", log2, &ZERO, &MINF, 0},
  {"log2", log2, &MZERO, &MINF, 0},
  {"log2", log2, &MONE, &nan, 0},
  {"log2", log2, &INF, &INF, 0},
#endif
  /*  {"fabs", fabs, nan, nan, 0}, */
  {"fabs", fabs, &ONE, &ONE, 0},
  {"fabs", fabs, &MONE, &ONE, 0},
  {"fabs", fabs, &ZERO, &ZERO, 0},
  {"fabs", fabs, &MZERO, &ZERO, 0},
  {"fabs", fabs, &INF, &INF, 0},
  {"fabs", fabs, &MINF, &INF, 0},
  {"cbrt", cbrt, &nan, &nan, 0},
  {"cbrt", cbrt, &ZERO, &ZERO, 0},
  {"cbrt", cbrt, &MZERO, &MZERO, 0},
  {"cbrt", cbrt, &INF, &INF, 0},
  {"cbrt", cbrt, &MINF, &MINF, 0},
/* Get these from cprob.shar */
  {"erf", erf, &nan, &nan, 0},
  {"erf", erf, &ZERO, &ZERO, 0},
  {"erf", erf, &MZERO, &MZERO, 0},
  {"erf", erf, &INF, &ONE, 0},
  {"erf", erf, &MINF, &MONE, 0},
  {"erfc", erfc, &nan, &nan, 0},
  {"erfc", erfc, &INF, &ZERO, 0},
  {"erfc", erfc, &MINF, &TWO, 0},
#if 0 /* our gamma() is just an alias of lgamma(), like in BSD */
  {"gamma", gamma, &nan, &nan, 0},
  {"gamma", gamma, &INF, &INF, 0},
  {"gamma", gamma, &MONE, &nan, 0},
  {"gamma", gamma, &ZERO, &nan, 0},
  {"gamma", gamma, &MINF, &nan, 0},
#endif
  {"lgamma", lgamma, &nan, &nan, 0},
  {"lgamma", lgamma, &INF, &INF, 0},
  {"lgamma", lgamma, &MONE, &INF, 0},
  {"lgamma", lgamma, &ZERO, &INF, 0},
  {"lgamma", lgamma, &MINF, &INF, 0},

  {"ceil", ceil, &nan, &nan, 0},
  {"ceil", ceil, &ZERO, &ZERO, 0},
  {"ceil", ceil, &MZERO, &MZERO, 0},
  {"ceil", ceil, &INF, &INF, 0},
  {"ceil", ceil, &MINF, &MINF, 0},
  {"floor", floor, &nan, &nan, 0},
  {"floor", floor, &ZERO, &ZERO, 0},
  {"floor", floor, &MZERO, &MZERO, 0},
  {"floor", floor, &INF, &INF, 0},
  {"floor", floor, &MINF, &MINF, 0},
  {"null", NULL, &ZERO, &ZERO, 0},
};

struct twoarguments test2[] =
{
  {"atan2", atan2, &ZERO, &ONE, &ZERO, 0},
  {"atan2", atan2, &MZERO, &ONE, &MZERO, 0},
  {"atan2", atan2, &ZERO, &ZERO, &ZERO, 0},
  {"atan2", atan2, &MZERO, &ZERO, &MZERO, 0},
  {"atan2", atan2, &ZERO, &MONE, &pi, 0},
  {"atan2", atan2, &MZERO, &MONE, &MPI, 0},
  {"atan2", atan2, &ZERO, &MZERO, &pi, 0},
  {"atan2", atan2, &MZERO, &MZERO, &MPI, 0},
  {"atan2", atan2, &ONE, &ZERO, &PIO2, 0},
  {"atan2", atan2, &ONE, &MZERO, &PIO2, 0},
  {"atan2", atan2, &MONE, &ZERO, &MPIO2, 0},
  {"atan2", atan2, &MONE, &MZERO, &MPIO2, 0},
  {"atan2", atan2, &ONE, &INF, &ZERO, 0},
  {"atan2", atan2, &MONE, &INF, &MZERO, 0},
  {"atan2", atan2, &INF, &ONE, &PIO2, 0},
  {"atan2", atan2, &INF, &MONE, &PIO2, 0},
  {"atan2", atan2, &MINF, &ONE, &MPIO2, 0},
  {"atan2", atan2, &MINF, &MONE, &MPIO2, 0},
  {"atan2", atan2, &ONE, &MINF, &pi, 0},
  {"atan2", atan2, &MONE, &MINF, &MPI, 0},
  {"atan2", atan2, &INF, &INF, &PIO4, 0},
  {"atan2", atan2, &MINF, &INF, &MPIO4, 0},
  {"atan2", atan2, &INF, &MINF, &THPIO4, 0},
  {"atan2", atan2, &MINF, &MINF, &MTHPIO4, 0},
  {"atan2", atan2, &ONE, &ONE, &PIO4, 0},
  {"atan2", atan2, &nan, &ONE, &nan, 0},
  {"atan2", atan2, &ONE, &nan, &nan, 0},
  {"atan2", atan2, &nan, &nan, &nan, 0},
  {"pow", pow, &ONE, &ZERO, &ONE, 0},
  {"pow", pow, &ONE, &MZERO, &ONE, 0},
  {"pow", pow, &MONE, &ZERO, &ONE, 0},
  {"pow", pow, &MONE, &MZERO, &ONE, 0},
  {"pow", pow, &INF, &ZERO, &ONE, 0},
  {"pow", pow, &INF, &MZERO, &ONE, 0},
  {"pow", pow, &nan, &ZERO, &ONE, 0},
  {"pow", pow, &nan, &MZERO, &ONE, 0},
  {"pow", pow, &TWO, &INF, &INF, 0},
  {"pow", pow, &MTWO, &INF, &INF, 0},
  {"pow", pow, &HALF, &INF, &ZERO, 0},
  {"pow", pow, &MHALF, &INF, &ZERO, 0},
  {"pow", pow, &TWO, &MINF, &ZERO, 0},
  {"pow", pow, &MTWO, &MINF, &ZERO, 0},
  {"pow", pow, &HALF, &MINF, &INF, 0},
  {"pow", pow, &MHALF, &MINF, &INF, 0},
  {"pow", pow, &INF, &HALF, &INF, 0},
  {"pow", pow, &INF, &TWO, &INF, 0},
  {"pow", pow, &INF, &MHALF, &ZERO, 0},
  {"pow", pow, &INF, &MTWO, &ZERO, 0},
  {"pow", pow, &MINF, &THREE, &MINF, 0},
  {"pow", pow, &MINF, &TWO, &INF, 0},
  {"pow", pow, &MINF, &MTHREE, &MZERO, 0},
  {"pow", pow, &MINF, &MTWO, &ZERO, 0},
  {"pow", pow, &nan, &ONE, &nan, 0},
  {"pow", pow, &ONE, &nan, &nan, 0},
  {"pow", pow, &nan, &nan, &nan, 0},
  {"pow", pow, &ONE, &INF, &nan, 0},
  {"pow", pow, &MONE, &INF, &nan, 0},
  {"pow", pow, &ONE, &MINF, &nan, 0},
  {"pow", pow, &MONE, &MINF, &nan, 0},
  {"pow", pow, &MTWO, &HALF, &nan, 0},
  {"pow", pow, &ZERO, &MTHREE, &INF, 0},
  {"pow", pow, &MZERO, &MTHREE, &MINF, 0},
  {"pow", pow, &ZERO, &MHALF, &INF, 0},
  {"pow", pow, &MZERO, &MHALF, &INF, 0},
  {"pow", pow, &ZERO, &THREE, &ZERO, 0},
  {"pow", pow, &MZERO, &THREE, &MZERO, 0},
  {"pow", pow, &ZERO, &HALF, &ZERO, 0},
  {"pow", pow, &MZERO, &HALF, &ZERO, 0},
  {"null", NULL, &ZERO, &ZERO, &ZERO, 0},
};

struct intans test3[] =
{
  {"isfinite", __isfinite, &ZERO, 1},
  {"isfinite", __isfinite, &INF, 0},
  {"isfinite", __isfinite, &MINF, 0},
  {"isnan", __isnan, &nan, 1},
  {"isnan", __isnan, &INF, 0},
  {"isnan", __isnan, &ZERO, 0},
  {"isnan", __isnan, &MZERO, 0},
  {"signbit", __signbit, &MZERO, 1},
  {"signbit", __signbit, &MONE, 1},
  {"signbit", __signbit, &ZERO, 0},
  {"signbit", __signbit, &ONE, 0},
  {"signbit", __signbit, &MINF, 1},
  {"signbit", __signbit, &INF, 0},
  {"null", NULL, &ZERO, 0},
};

  /* We test the IEEE conformance of fdlibm. */
  _LIB_VERSION = _IEEE_;

    /* This masks off fpu exceptions on i386.  */
  _setfpu(0x137f);
  _control87(PC_53, MCW_PC);
        
  nerrors = 0;
  ntests = 0;
  i = 0;
  for (;;)
    {
      fun1 = test1[i].func;
      if (fun1 == NULL)
	break;
      x1 = *(test1[i].arg1);
      y = (*(fun1)) (x1);
      answer = *(test1[i].answer);
      if (test1[i].thresh == 0)
	{
	  v.d = answer;
	  u.d = y;
	  if (memcmp(u.c, v.c, 8) != 0)
	    {
	      if( __isnan(v.d) && __isnan(u.d) )
		goto nxttest1;
	      goto wrongone;
	    }
	  else
	    goto nxttest1;
	}
      if (y != answer)
	{
	  e = y - answer;
	  if (answer != 0.0)
	    e = e / answer;
	  if (e < 0)
	    e = -e;
	  if (e > test1[i].thresh * MACHEP)
	    {
wrongone:
	      printf ("%s (%.16e) = %.16e\n    should be %.16e\n",
		      test1[i].name, x1, y, answer);
	      nerrors += 1;
	    }
	}
nxttest1:
      ntests += 1;
      i += 1;
    }

  i = 0;
  for (;;)
    {
      fun2 = test2[i].func;
      if (fun2 == NULL)
	break;
      x1 = *(test2[i].arg1);
      x2 = *(test2[i].arg2);
      y = (*(fun2)) (x1, x2);
      answer = *(test2[i].answer);
      if (test2[i].thresh == 0)
	{
	  v.d = answer;
	  u.d = y;
	  if (memcmp(u.c, v.c, 8) != 0)
	    {
	      if( __isnan(v.d) && __isnan(u.d) )
		goto nxttest2;
#if 0
	      if( isnan(v.d) )
		pvec(v.d);
	      if( isnan(u.d) )
		pvec(u.d);
#endif
	    goto wrongtwo;
	    }
	  else
	    goto nxttest2;
	}
      if (y != answer)
	{
	  e = y - answer;
	  if (answer != 0.0)
	    e = e / answer;
	  if (e < 0)
	    e = -e;
	  if (e > test2[i].thresh * MACHEP)
	    {
wrongtwo:
	      printf ("%s (%.16e, %.16e) = %.16e\n    should be %.16e\n",
		      test2[i].name, x1, x2, y, answer);
	      nerrors += 1;
	    }
	}
nxttest2:
      ntests += 1;
      i += 1;
    }


  i = 0;
  for (;;)
    {
      fun3 = test3[i].func;
      if (fun3 == NULL)
	break;
      x1 = *(test3[i].arg1);
      k = (*(fun3)) (x1);
      ianswer = test3[i].ianswer;
      if (k != ianswer)
	{
	  printf ("%s(%.16e) = %d\n should be %d\n",
		  test3[i].name, x1, k, ianswer);
	  nerrors += 1;
	}
      ntests += 1;
      i += 1;
    }

  printf ("testvect: %d errors in %d tests\n", nerrors, ntests);
#undef isnan(x)
  printf ("isnan(NAN): %d\n", isnan(NAN));
  exit (0);
}
//判定两点在平面异侧,点在平面上返回0
bool opposite_side(const Point &p1, const Point &p2, const Plane &s)
{
    return (pvec(s) * (p1 - s.a)) * (pvec(s) * (p2 - s.a)) < -eps;
}
//面面平行
bool parallel(const Plane &s1, const Plane &s2)
{
    return sgn((pvec(s1) ^ pvec(s2)).norm()) == 0;
}
double angle_sin(line3 l,plane3 s)
{
	return dmult(subt(l.a,l.b),pvec(s))/vlen(subt(l.a,l.b))/vlen(pvec(s));
}
Exemplo n.º 19
0
w_rc_t ShoreTPCBEnv::_pad_BRANCHES()
{
    ss_m* db = this->db();

    // lock the BRANCHES table
    branch_t* br = branch_man->table();
    std::vector<index_desc_t*>& br_idx = br->get_indexes();

    // lock the table and index(es) for exclusive access
    W_DO(ss_m::lm->intent_vol_lock(br->primary_idx()->stid().vol,
                okvl_mode::IX));
    W_DO(ss_m::lm->intent_store_lock(br->primary_idx()->stid(),
                okvl_mode::X));
    for(size_t i=0; i < br_idx.size(); i++) {
        W_DO(ss_m::lm->intent_store_lock(br_idx[i]->stid(), okvl_mode::X));
    }

    guard<ats_char_t> pts = new ats_char_t(br->maxsize());

    // copy and pad all tuples smaller than 4k

    // WARNING: this code assumes that existing tuples are packed
    // densly so that all padded tuples are added after the last
    // unpadded one

    bool eof;

    // we know you can't fit two 4k records on a single page
    static int const PADDED_SIZE = 4096;

    array_guard_t<char> padding = new char[PADDED_SIZE];
    std::vector<rid_t> hit_list;
    {
	table_scan_iter_impl<branch_t>* iter =
            new table_scan_iter_impl<branch_t>(branch_man->table());

	int count = 0;
	table_row_t row(br);
	rep_row_t arep(pts);
	int psize = br->maxsize()+1;

	W_DO(iter->next(db, eof, row));
	while (!eof) {
	    // figure out how big the old record is
	    int bsize = row.size();
	    if (bsize == psize) {
		TRACE(TRACE_ALWAYS,
                      "-> Found padded BRANCH record. Stopping search (%d)\n",
                      count);
		break;
	    }
	    else if (bsize > psize) {
		// too big... shrink it down to save on logging
		// handle->truncate_rec(bsize - psize);
                fprintf(stderr, "+");
                // CS: no more pin_i -> do nothing
	    }
	    else {
		// copy and pad the record (and mark the old one for deletion)
		rid_t new_rid;
		vec_t hvec(handle->hdr(), hsize);
		vec_t dvec(handle->body(), bsize);
		vec_t pvec(padding, PADDED_SIZE-bsize);
		W_DO(db->create_rec(br_fid, hvec, PADDED_SIZE, dvec, new_rid));
		W_DO(db->append_rec(new_rid, pvec));

                // mark the old record for deletion
		hit_list.push_back(handle->rid());

		// update the index(es)
		vec_t rvec(&row._rid, sizeof(rid_t));
		vec_t nrvec(&new_rid, sizeof(new_rid));
		for(int i=0; i < br_idx_count; i++) {
		    int key_sz = branch_man()->format_key(br_idx+i, &row, arep);
		    vec_t kvec(arep._dest, key_sz);

		    // destroy the old mapping and replace it with the new
                    // one.  If it turns out this is super-slow, we can
                    // look into probing the index with a cursor and
                    // updating it directly.
		    int pnum = _pbranch_man->get_pnum(&br_idx[i], &row);
		    stid_t fid = br_idx[i].fid(pnum);

                    W_DO(db->destroy_assoc(fid, kvec, rvec));
                    // now put the entry back with the new rid
                    W_DO(db->create_assoc(fid, kvec, nrvec));

		}
                fprintf(stderr, ".");
	    }

	    // next!
	    count++;
	    W_DO(iter->next(db, eof, row));
	}
        TRACE(TRACE_ALWAYS, "padded records added\n");

        delete iter;
    }

    // delete the old records
    int hlsize = hit_list.size();
    TRACE(TRACE_ALWAYS,
          "-> Deleting (%d) old BRANCH unpadded records\n",
          hlsize);
    for(int i=0; i < hlsize; i++) {
	W_DO(db->destroy_rec(hit_list[i]));
    }

    return (RCOK);
}
//面面垂直
bool vertical(const Plane &s1, const Plane &s2)
{
    return sgn(pvec(s1) * pvec(s2)) == 0;
}
Exemplo n.º 21
0
w_rc_t ShoreTPCCEnv::_post_init_impl()
{
#ifndef CFG_HACK
    return (RCOK);
#endif

    TRACE (TRACE_ALWAYS, "Padding WAREHOUSES");
    ss_m* db = this->db();

    // lock the WH table
    warehouse_t* wh = warehouse_desc();
    index_desc_t* idx = wh->indexes();
    int icount = wh->index_count();
    stid_t wh_fid = wh->fid();

    // lock the table and index(es) for exclusive access
    W_DO(db->lock(wh_fid, EX));
    for(int i=0; i < icount; i++) {
	for(int j=0; j < idx[i].get_partition_count(); j++)
	    W_DO(db->lock(idx[i].fid(j), EX));
    }

    guard<ats_char_t> pts = new ats_char_t(wh->maxsize());

    /* copy and pad all tuples smaller than 4k

       WARNING: this code assumes that existing tuples are packed
       densly so that all padded tuples are added after the last
       unpadded one
    */
    bool eof;
    static int const PADDED_SIZE = 4096; // we know you can't fit two 4k records on a single page
    array_guard_t<char> padding = new char[PADDED_SIZE];
    std::vector<rid_t> hit_list;
    {
	guard<warehouse_man_impl::table_iter> iter;
	{
	    warehouse_man_impl::table_iter* tmp;
	    W_DO(warehouse_man()->get_iter_for_file_scan(db, tmp));
	    iter = tmp;
	}

	int count = 0;
	table_row_t row(wh);
	rep_row_t arep(pts);
	int psize = wh->maxsize()+1;

	W_DO(iter->next(db, eof, row));
	while (1) {
	    pin_i* handle = iter->cursor();
	    if (!handle) {
		TRACE(TRACE_ALWAYS, " -> Reached EOF. Search complete (%d)\n", count);
		break;
	    }

	    // figure out how big the old record is
	    int hsize = handle->hdr_size();
	    int bsize = handle->body_size();
	    if (bsize == psize) {
		TRACE(TRACE_ALWAYS, " -> Found padded WH record. Stopping search (%d)\n", count);
		break;
	    }
	    else if (bsize > psize) {
		// too big... shrink it down to save on logging
		handle->truncate_rec(bsize - psize);
                fprintf(stderr, "+");
	    }
	    else {
		// copy and pad the record (and mark the old one for deletion)
		rid_t new_rid;
		vec_t hvec(handle->hdr(), hsize);
		vec_t dvec(handle->body(), bsize);
		vec_t pvec(padding, PADDED_SIZE-bsize);
		W_DO(db->create_rec(wh_fid, hvec, PADDED_SIZE, dvec, new_rid));
		W_DO(db->append_rec(new_rid, pvec));
                // for small databases, first padded record fits on this page
                if (not handle->up_to_date())
                    handle->repin();

                // mark the old record for deletion
		hit_list.push_back(handle->rid());

		// update the index(es)
		vec_t rvec(&row._rid, sizeof(rid_t));
		vec_t nrvec(&new_rid, sizeof(new_rid));
		for(int i=0; i < icount; i++) {
		    int key_sz = warehouse_man()->format_key(idx+i, &row, arep);
		    vec_t kvec(arep._dest, key_sz);

		    /* destroy the old mapping and replace it with the new
		       one.  If it turns out this is super-slow, we can
		       look into probing the index with a cursor and
		       updating it directly.
		    */
		    int pnum = _pwarehouse_man->get_pnum(&idx[i], &row);
		    stid_t fid = idx[i].fid(pnum);

		    if(idx[i].is_mr()) {
			W_DO(db->destroy_mr_assoc(fid, kvec, rvec));
			// now put the entry back with the new rid
			el_filler ef;
			ef._el.put(nrvec);
			W_DO(db->create_mr_assoc(fid, kvec, ef));
		    } else {
			W_DO(db->destroy_assoc(fid, kvec, rvec));
			// now put the entry back with the new rid
			W_DO(db->create_assoc(fid, kvec, nrvec));
		    }

		}
                fprintf(stderr, ".");
	    }

	    // next!
	    count++;
	    W_DO(iter->next(db, eof, row));
	}
        fprintf(stderr, "\n");

	// put the iter out of scope
    }

    // delete the old records
    int hlsize = hit_list.size();
    TRACE(TRACE_ALWAYS, "-> Deleting (%d) old unpadded records\n", hlsize);
    for(int i=0; i < hlsize; i++) {
	W_DO(db->destroy_rec(hit_list[i]));
    }

    return (RCOK);
}
//点面距离
double dist_point_to_plane(const Point &p, const Plane &s)
{
    Point pv = pvec(s);
    return fabs(pv * (p - s.a)) / pv.norm();
}
double angle_sin(point3 l1,point3 l2,point3 s1,point3 s2,point3 s3)
{
	return dmult(subt(l1,l2),pvec(s1,s2,s3))/vlen(subt(l1,l2))/vlen(pvec(s1,s2,s3));
}
//判断点在平面上
bool point_on_plane(const Point &p, const Plane &s)
{
    return sgn((p - s.a) * pvec(s)) == 0;
}