Advertisement
suremarc

Untitled

Dec 8th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.61 KB | None | 0 0
  1. function VectorAboutAxis(th, ax, ay, az, px, py, pz)
  2.     local m = ax*ax+ay*ay+az*az;
  3.     if abs(1-m)>1e-6 then
  4.         local r = 1/sqrt(m);
  5.         ax, ay, az = ax*r, ay*r, az*r;
  6.     end
  7.    
  8.     -- vector projection
  9.     local d = dot(px,py,pz,ax,ay,az);
  10.     local ux, uy, uz = d*ax, d*ay, d*az;
  11.     --   (the vector rejection is simply <px-ux, py-uy, pz-uz>, so we'll use that later)
  12.     -- cross product
  13.     local vx, vy, vz = cross(ax,ay,az,px,py,pz);
  14.     -- sine & cosine of our angle offset
  15.     local c, s = cos(th), sin(th);
  16.     -- return new vector    u + (p-u)*c + v*s
  17.     return      ux  +(px-ux)*+vx*s,
  18.             uy  +(py-uy)*+vy*s,
  19.             uz  +(pz-uz)*+vz*s;
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement