c++ - Rounding a 3D point relative to a plane -


i have plane class holds n normal , q point on plane. have point p lies on plane. how go rounding p nearest unit on plane. snapping cursor 3d grid grid can rotating plane.

image explain: enter image description here

red current point. green rounded point i'm trying get.

probably easiest way achieve taking plane define rotated , shifted coordinate system. allows construct matrices transforming point in global coordinates plane coordinates , back. once have this, can transform point plane coordinates, perform rounding/projection in trivial manner, , convert world coordinates.

of course, problem underspecified way pose question: transformation need has 6 degrees of freedom, plane equation yields 3 constraints. need add more information: location of origin within plane, , rotation of grid around plane normal.

personally, start deriving plane description in parametric form:

xvec = alpha*direction1 + beta*direction2 + x0 

of course, such description contains 9 variables (three vectors), can normalize 2 direction vectors, , can constrain 2 direction vectors orthogonal, reduces amount of freedoms six.

the 2 normalized direction vectors, normalized normal, base vectors of rotated coordinate system, can construct rotation matrix putting these 3 vectors together. inverse rotation, transpose resulting matrix. add translation / inverse translation on appropriate side of rotation, , done.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -