POV-Ray : Newsgroups : povray.newusers : Positioning an object in 3 space. : Re: Positioning an object in 3 space. Server Time
18 May 2024 23:36:24 EDT (-0400)
  Re: Positioning an object in 3 space.  
From: Slime
Date: 21 Jan 2005 21:54:26
Message: <41f1c062$1@news.povray.org>
> I have an object with a defined up (say the y-direction) and a defined
> forward (say the x-direction).  I'd like to place this object at a new
> location with a new orientation specified by given new up and forward
> vectors.

This is practically what matrix transformations are *for*. The matrix
transformation can be thought of as four vectors: what the X axis is mapped
to, what the Y axis is mapped to, what the Z axis is mapped to, and what to
translate by afterwards. So let's say you have the two vectors that you want
to map the Y and X axes to, called newydir and newxdir. First, you calculate
what you'll be mapping the Z axis to via a cross product (assuming newydir
and newxdir are normalized):

#declare newzdir = vcross(newxdir, newydir);

Then you just use a matrix transformation like so:

matrix <
    newxdir.x, newxdir.y, newxdir.z,
    newydir.x, newydir.y, newydir.z,
    newzdir.x, newzdir.y, newzdir.z,
    transamnt.x, transamnt.y, transamnt.z
>

where transamnt is where you want to translate the object to.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.