Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Point projection in to a plane Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
takis

April 13, 2005, 11:49 AM

Hello,

I am trying to rotate points that lay on a mesh into a given plane.
I manage it so far, but sometimes it does not rotate into the given plane.
Could someone help me?

Polygon A with a point p on it.
Polygon B with a point q on it.
I want to rotate point q in the plane describe by polygon A.

  1.  
  2. Vec3 d=q-p;
  3.  
  4. // building local system around p
  5. Vec3 localZ=A.normal; // the normal of polygon A
  6. Vec3 localY=cross(localZ,d); // rotation axis
  7. localY.normalize();
  8. Vec3 localX=cross(localY,localZ);
  9. localX.normalize();
  10.  
  11. // projection of d into local system
  12. float x=dot(localX, d);
  13. float y=dot(localY, d);
  14. float z=dot(localZ, d);
  15.  
  16. // calculating rotation angle
  17. float a=atan2f(z, x);
  18.  
  19. // do the rotation
  20. Vec3 Pos;
  21. Pos.rotateAroundAxis(d, localY, a);
  22. Pos+=p; // result
  23.  
  24.  
  25. void Vec3::rotateAroundAxis(const Vec3& p, const Vec3& axis, float a)
  26. {
  27.  // axis is normalised
  28.  float s=sinf(a);
  29.  float c=cosf(a);
  30.  
  31.  Vec3 vpar=axis*dot(p,axis);
  32.  Vec3 vprp=p-vpar;
  33.  Vec3 vcrs;
  34.  vcrs.cross(axis,p);
  35.  
  36.  m_values[0]=vpar[0]+c*vprp[0]+s*vcrs[0];
  37.  m_values[1]=vpar[1]+c*vprp[1]+s*vcrs[1];
  38.  m_values[2]=vpar[2]+c*vprp[2]+s*vcrs[2];
  39. }
  40.  

 
This thread contains 1 message.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.