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.

April 13, 2005, 11:49 AM


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.

  2. Vec3 d=q-p;
  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();
  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);
  16. // calculating rotation angle
  17. float a=atan2f(z, x);
  19. // do the rotation
  20. Vec3 Pos;
  21. Pos.rotateAroundAxis(d, localY, a);
  22. Pos+=p; // result
  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);
  31.  Vec3 vpar=axis*dot(p,axis);
  32.  Vec3 vprp=p-vpar;
  33.  Vec3 vcrs;
  34.  vcrs.cross(axis,p);
  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. }

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