POV-Ray : Newsgroups : povray.advanced-users : Box pointing to target vector Server Time
24 Nov 2024 01:33:14 EST (-0500)
  Box pointing to target vector (Message 1 to 3 of 3)  
From: MadKairon
Subject: Box pointing to target vector
Date: 28 Mar 2010 07:00:00
Message: <web.4baf35a774e65dc05e975f010@news.povray.org>
I have this box:

box { <-.025,0,-.025>, <.025,1,.025> pigment { rgb .2} }

And this 3D vector:

#declare vect = <1,1,-1>;

Question:

How do I rotate my box so that the top faces the vector "vect"?

I've been trying with some trigonometrical functions... atan2() helps but my
skills are failing me here :( this is as far as I could get

#declare rad = VDist(<0,0,0>,vect);
#declare cat1 = <0,rad,0>;
#declare cat2 = VDist(cat1,vect);
box { <-.025,0,-.025>, <.025,VDist(<0,0,0>, vect),.025> pigment { rgb <.2,0,0>}
    rotate <0,0,degrees( atan2( rad, cat2 ) )-90>
    }

but the arctan angle seems to be wrong and that's only a rotation around Z,
still need to rotate it again around either X or Y y guess...


Post a reply to this message

From: MadKairon
Subject: Re: Box pointing to target vector
Date: 28 Mar 2010 08:50:00
Message: <web.4baf5053cd7385dc5e975f010@news.povray.org>
A bit better...

box { <-.025,0,-.025>, <.025,VDist(<0,0,0>, vect),.025> pigment { rgb <.2,0,0>}
    rotate <0,0,degrees( atan2( vect.y, vect.x )) - 90>
    rotate <0,degrees(atan2(VDist(<vect.x,vect.y,0> , vect),vect.z)),0>
    }

First it rotates the box around Z axiz. That works right. But the second
rotation around Y axiz is wrong. Anybody knows how to fix that? thanks


Post a reply to this message

From: MadKairon
Subject: Re: Box pointing to target vector
Date: 28 Mar 2010 12:25:01
Message: <web.4baf8288cd7385dc5e975f010@news.povray.org>
well...  can't do the math for myself so I found an easy way out :P

#include "transforms.inc"
box { <-.025,0,-.025>, <.025,VDist(<0,0,0>, vect),.025> pigment { rgb <0,.2,0>}
     Point_At_Trans(vect)
    }

just in case somebody else needs it.


Post a reply to this message

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