Beispiel #1
0
// Converts the vector to a unit vector
// USE ONLY ON VECTORS, NOT COORDINATES!
// Return Coordinates or void?
Coordinates unitVector( Coordinates& point )
{
	if (abs(point.norm() - 1) < .00001)
	{
		return point;
	}
	float norm = point.norm();
	Coordinates newPoint((point.x / norm),
						 (point.y / norm),
						 (point.y / norm));
	return newPoint;
}
Beispiel #2
0
// this calculates the angle between two planes.  In this case,
// we take as arguments a precalculated set of coordinates for 
// one plane (to reduce the number of computations), the second
// residue in question, and the index for the center that we
// are curious about
float calculateAngleBetweenPlanes( Coordinates& planeP,
                                   AminoAcid& aa2,
                                   int index2 )
{
  Coordinates planeQ;
  
  float normV;
  float normP;
  float dotProd;
  float cosValue;

  // get the plane equation for the center we are curious about
  getPlaneEquation( *(aa2.center[index2].plane_info[ C__PLANE_COORD_AG]),
                    *(aa2.center[index2].plane_info[O_1_PLANE_COORD_AG]),
                    *(aa2.center[index2].plane_info[O_2_PLANE_COORD_AG]),
                    &planeQ);

  // calculate the norms of these planes
  normV = planeP.norm();
  normP = planeQ.norm();

  // and their dot product
  dotProd = dotProduct( planeP,
                        planeQ );

  // and use them to calculate the value of the cosine of the angle
  cosValue = dotProd / ( normV * normP );

  // error check
  if( cosValue < -1 || cosValue > 1 )
    {
      cerr << red << "Error" << reset << ":Error: Cosine of angle, " << cosValue << ", lies outside of -1 and 1" << endl;
      return 1000;            
    }
  else
    {
      // and actually calculate the angle value
      float angle = acos(cosValue) * 180 / 3.14159;
      if(angle > 90)
        {
          angle = 180.0 - angle;
        }
      return angle;
    }

}
Beispiel #3
0
// Calculate the angle between a plane and a line
float angleBetweenPlaneAndLine ( Coordinates& plane,
                                 Coordinates& point1,
                                 Coordinates& point2 )
{
  float normalv;
  float normalp;
  float dotProd;
  float angle;
  float cosValue;

  Coordinates tempCoord;
  
  // Calculate the norm of the plane coordinates
  normalv = plane.norm();

  // subtract the 2 points together and get their norm
  tempCoord = point2 - point1;
  normalp = tempCoord.norm();

  // get the dot producted between the plane and difference of the points
  dotProd = dotProduct(plane, tempCoord);

  // Now we can get the cosine value with this information
  cosValue = dotProd/(normalv * normalp);

  // double check that we aren't doing anything illegal with arccos
  if( cosValue < -1.0 || cosValue > 1.0 )
    {
      cerr << red << "Error" << reset << ":Error: Cosine of angle, " << cosValue << ", lies outside of -1 and 1" << endl;
      angle = 1000;
    }
  else
    {
      // and actually calculate the angle
      angle = abs ( 90 - ( acos(cosValue) * 180 / 3.14159  ) );
    }
  return angle;
}