/*
Check if three 3d points are colinera. I've been a slack and use the difference in the
directional unit vectors as the indicator.
*/
float
_colinear(const CParticleF& p, const CParticleF& q, const CParticleF& r)
{
	CParticleF u = UnitVector(Difference(q, p));
	CParticleF v = UnitVector(Difference(r, p));
	return Distance(u, v);
}
void NormalVector(GLfloat vector1[3],GLfloat vector2[3],GLfloat outVector[3])
{
    outVector[0] = vector1[1]*vector2[2]-vector1[2]*vector2[1];
    outVector[1] = vector1[2]*vector2[0]-vector1[0]*vector2[2];
    outVector[2] = vector1[0]*vector2[1]-vector1[1]*vector2[0];
    UnitVector(outVector);
}
/*
Check if lines a-b and c-d are parallel.
*/
bool
isParallel(CParticleF& a, CParticleF& b, CParticleF& c, CParticleF& d, float precision)
{
	CParticleF x = UnitVector(CParticleF(b.m_X - a.m_X, b.m_Y - a.m_Y, b.m_Z - a.m_Z));
	CParticleF y = UnitVector(CParticleF(d.m_X - c.m_X, d.m_Y - c.m_Y, d.m_Z - c.m_Z));

	CParticleF z = crossProduct(x, y);
	if (sqrt(z.m_X*z.m_X + z.m_Y*z.m_Y + z.m_Z*z.m_Z) < precision)
	{
		return true;
	}
	else
	{
		return false;
	}
}
Exemple #4
0
bool UnitVectorC(pMat3_t M, int ind, pVec3_t Vout)
{
  Vec3_t V1;
  if((ind < 0)||(ind > 2)) return false;
    for(int k=0;k<3;k++) V1.val[k] = M->val[k][ind]; 
  return UnitVector(&V1, Vout);
}
Exemple #5
0
  //-- returns false if Vin is zero or bad index
bool UnitVectorC(pMat2_t M, int ind, pVec2_t Vout) // creates a unit vector in direction of ind col of M 
{
  Vec2_t V1;
  if((ind < 0)||(ind > 1)) return false;
  V1.val[0] = M->val[0][ind]; V1.val[1] = M->val[1][ind];
  return UnitVector(&V1, Vout);
}
Exemple #6
0
void SurfaceNormal(struct coords *NP, struct coords *FP, struct coords *LP)
{

 NP->x = FP->y * LP->z - FP->z * LP->y;
 NP->y = FP->z * LP->x - FP->x * LP->z;
 NP->z = FP->x * LP->y - FP->y * LP->x;
 VectorMagnitude(NP);
 UnitVector(NP);

} /* SurfaceNormal() */
void SubDivide(GLfloat* v1,GLfloat* v2,GLfloat* v3,int depth)
{
    GLfloat v12[3],v23[3],v31[3];
    if(depth == 0)
    {
        DrawTriangle(v1,v2,v3);
        return;
    }
    for(int i=0;i<3;i++)
    {
        v12[i] = (v1[i]+v2[i])/2.0;
        v23[i] = (v2[i]+v3[i])/2.0;
        v31[i] = (v3[i]+v1[i])/2.0;
    }
    UnitVector(v12);
    UnitVector(v23);
    UnitVector(v31);
    SubDivide(v1,v12,v31,depth-1);
    SubDivide(v2,v23,v12,depth-1);
    SubDivide(v3,v31,v23,depth-1);
    SubDivide(v12,v23,v31,depth-1);
}
const UnitVector UnitVector::absolute() const
{
  return UnitVector(fabs(radians_));
}
const UnitVector UnitVector::operator-(const UnitVector &other) const
{
  return UnitVector(radians_ - other.radians_);
}
const UnitVector UnitVector::from_degrees(float angle)
{
    return UnitVector(angle / 180 * M_PI);
}
Angle	operator-(const SphericalCoordinates& s1, const SphericalCoordinates& s2) {
	return UnitVector(s1).angle(UnitVector(s2));
}
Exemple #12
0
pVec2_t Dot(pVec2_t V1, pVec2_t V2, pVec2_t Vout) // if V1 is zero, returns zero. otherwise, returns V2 projected onto V1
{
  Vec2_t tmp;
  if(!UnitVector(V1, &tmp)) return(SetZero(Vout));
  return(Mult_sv(Dot(V2, &tmp), &tmp, Vout));
}