예제 #1
0
BrlCadInterface::HitType BrlCadInterface::shootRay(vec3_t x, vec3_t v, vec3_t &x_hit, vec3_t &n_hit, double &r)
{
  HitType hit_type = Miss;
  v.normalise();
  vec3_t x_in, x_out, n_in, n_out;
  double r_in, r_out;
  if (brlCadShootRay(x, v, x_in, x_out, n_in, n_out, r_in, r_out)) {
    double d_in = (x_in - x)*v;
    if (d_in > 0) {
      x_hit = x_in;
      n_hit = n_in;
      r = r_in;
      hit_type = HitIn;
    }
    double d_out = (x_out - x)*v;
    if (d_out > 0) {
      if (hit_type == Miss || d_out < d_in) {
        x_hit = x_out;
        n_hit = n_out;
        hit_type = HitOut;
        r = r_out;
      }
    }
  }
  return hit_type;
}
예제 #2
0
vec3_t rotate(vec3_t v, vec3_t axis, double theta)
{
  axis.normalise();
  
  // transposed base of rotate system
  mat3_t g_t;

  // compute projection of v in axis direction
  vec3_t v_axis = (axis*v)*axis;

  // compute first orthogonal vector (first base vector)
  g_t[0] = v-v_axis;
  
  //In case of points on the rotation axis, do nothing
  if(g_t[0].abs()==0) return v;
  
  g_t[0].normalise();

  // second base vector is the normalised axis
  g_t[1] = axis;

  // compute second orthogonal vector (third base vector)
  g_t[2] = g_t[0].cross(g_t[1]);

  // base of rotate system
  mat3_t g = g_t.transp();

  // matrix for rotation around g_t[1];
  mat3_t rot = mat3_t::identity();
  rot[0][0] =  cos(theta);
  rot[0][2] =  sin(theta);
  rot[2][0] = -sin(theta);
  rot[2][2] =  cos(theta);

  // transfer v to rotate system
  vec3_t v_r = g_t*v;

  // rotate the vector and transfer it back
  v_r = rot*v_r;
  v = g*v_r;

  return v;
}
예제 #3
0
bool CreateCadTesselation::shootRay(vec3_t x, vec3_t v, vec3_t &x_in, vec3_t &x_out, vec3_t &n_in, vec3_t &n_out)
{
  v.normalise();
  double r_hit;
  vec3_t x_hit, n_hit;
  CadInterface::HitType hit_type = m_CadInterface->shootRay(x, v, x_hit, n_hit, r_hit);
  if (hit_type == CadInterface::Miss || hit_type == CadInterface::HitOut) {
    return false;
  }
  x_in = x_hit;
  n_in = n_hit;
  x = x_in;
  do {
    x += 1e-10*v;
    hit_type = m_CadInterface->shootRay(x, v, x_hit, n_hit, r_hit);
    if (hit_type == CadInterface::HitOut) {
      x_out = x_hit;
      n_out = n_hit;
    }
    x = x_hit;
  } while (hit_type == CadInterface::HitIn);
  return true;
}
예제 #4
0
vec3_t intersectionOnPlane(vec3_t v, vec3_t A, vec3_t nA, vec3_t B, vec3_t nB)
{
  vec3_t u = B-A;
//   u.normalise();
  v.normalise();
  v = u.abs()*v;
  
  //cout<<"u="<<u<<" v="<<v<<endl;
  
  vec2_t p_A(0,0);
  vec2_t p_B(1,0);
  vec2_t p_nA = projectVectorOnPlane(nA,u,v);
  vec2_t p_nB = projectVectorOnPlane(nB,u,v);
  
  vec2_t p_tA = turnRight(p_nA);
  vec2_t p_tB = turnRight(p_nB);
  
  double k1, k2;
  vec2_t p_K;
  if(!intersection(k1, k2, p_A, p_tA, p_B, p_tB)) {
    //qDebug()<<"WARNING: No intersection found!!!";
    p_K = 0.5*(p_A + p_B);
  }
  else {
    p_K = p_A + k1*p_tA;
  }
  
  //cout<<"nA="<<nA<<endl;
  //cout<<"p_nA="<<p_nA<<endl;
  //cout<<"p_tA="<<p_tA<<endl;
  //cout<<"p_K="<<p_K<<endl;
  if(p_K[0]<0) p_K[0] = 0;
  if(p_K[0]>1) p_K[0] = 1;
  vec3_t K = A + p_K[0]*u + p_K[1]*v;
  //cout<<"K="<<K<<endl;
  return K;
}
예제 #5
0
 foreach (vec3_t nf, m_Faces) {
   nf.normalise();
   double h = nf*n0;
   hf = min(h, hf);
 }