POV-Ray : Newsgroups : povray.advanced-users : How do you rotate an object to face the origin? Server Time
1 Nov 2024 03:15:11 EDT (-0400)
  How do you rotate an object to face the origin? (Message 1 to 9 of 9)  
From: Rich
Subject: How do you rotate an object to face the origin?
Date: 16 Dec 2003 10:35:46
Message: <Xns9453577279E6spammindspringcom@204.213.191.226>
Hi gang,
    	I've searched through the previous posts looking for an answer but 
haven't found one yet.  I need to rotate many objects on their local Y axis 
so that they face the origin.  The objects are placed randomly, so I don't 
know "where" they are until they are transformed (or just before the 
transform, I suppose).  I've looked at the reorient macro but I don't think 
that's what I'm looking for.  Can anyone help me with this?

Rich Allen


Post a reply to this message

From: Jim Charter
Subject: Re: How do you rotate an object to face the origin?
Date: 16 Dec 2003 10:49:48
Message: <3fdf299c$1@news.povray.org>
Rich wrote:

>   The objects are placed randomly, so I don't
> know "where" they are until they are transformed (or just before the 
> transform, I suppose).  I've looked at the reorient macro but I don't think 
> that's what I'm looking for.  

Why not?  If where they are is a point then it is also the vector that 
you want to reorient to, isn't it?

-Jim


Post a reply to this message

From: Chris B
Subject: Re: How do you rotate an object to face the origin?
Date: 16 Dec 2003 11:14:44
Message: <3fdf2f74@news.povray.org>
"Rich" <SrP### [at] ricoswebcom> wrote in message
news:Xns### [at] 204213191226...
> Hi gang,
>     I've searched through the previous posts looking for an answer but
> haven't found one yet.  I need to rotate many objects on their local Y
axis
> so that they face the origin.  The objects are placed randomly, so I don't
> know "where" they are until they are transformed (or just before the
> transform, I suppose).  I've looked at the reorient macro but I don't
think
> that's what I'm looking for.  Can anyone help me with this?
>
> Rich Allen

If you know the targetLocation before you translate the object and the
object is defined at the origin, then you can rotate it before moving it.
If you only need to rotate around the Y axis then the angle is the arctan in
degrees of z / x. So you can use atan2d():

#declare targetLocation = <3,4,5>;
#declare targetAngle = atan2d(targetLocation.z,targetLocation.x);

Hope I understood your question correctly.

Regards,
Chris.


Post a reply to this message

From: Rich
Subject: Re: How do you rotate an object to face the origin?
Date: 16 Dec 2003 13:09:14
Message: <Xns94537176EB3C0spammindspringcom@204.213.191.226>
"Chris B" <c_b### [at] btconnectcom> wrote in
news:3fdf2f74@news.povray.org: 

> If you know the targetLocation before you translate the object and the
> object is defined at the origin, then you can rotate it before moving
> it. If you only need to rotate around the Y axis then the angle is the
> arctan in degrees of z / x. So you can use atan2d():
> 
> #declare targetLocation = <3,4,5>;
> #declare targetAngle = atan2d(targetLocation.z,targetLocation.x);
> 
> Hope I understood your question correctly.

I think you do understand my question, but when I use your formula I 
don't get the expected results.  I've output the relevant variable values 
and copied them below.  Only one or two of these objects are actually 
pointing at or nearly at the origin...

#declare rotation = atan2d(z1,x1);    
#object {
  thing
  rotate <0,rotation,0> 
  translate <x1,y1,z1>
}


Z:  0.1,  X:  3.5,  Rotation:   1.0
Z:  1.4,  X:  3.0,  Rotation:  25.0
Z:  2.3,  X:  2.0,  Rotation:  49.0
Z:  2.7,  X:  0.8,  Rotation:  73.0
Z:  2.5,  X: -0.3,  Rotation:  97.0
Z:  2.0,  X: -1.2,  Rotation: 121.0
Z:  1.2,  X: -1.7,  Rotation: 145.0
Z:  0.4,  X: -1.8,  Rotation: 169.0
Z: -0.4,  X: -1.6,  Rotation:-167.0
Z: -0.8,  X: -1.1,  Rotation:-143.0
Z: -1.0,  X: -0.6,  Rotation:-119.0
Z: -0.9,  X: -0.1,  Rotation: -95.0
Z: -0.7,  X:  0.2,  Rotation: -71.0
Z: -0.3,  X:  0.3,  Rotation: -47.0
Z: -0.1,  X:  0.2,  Rotation: -23.0


Post a reply to this message

From: David Wallace
Subject: Re: How do you rotate an object to face the origin?
Date: 16 Dec 2003 14:06:00
Message: <3fdf5798@news.povray.org>
"Rich" <SrP### [at] ricoswebcom> wrote in message
news:Xns### [at] 204213191226...
> "Chris B" <c_b### [at] btconnectcom> wrote in
> news:3fdf2f74@news.povray.org:
>
> > If you know the targetLocation before you translate the object and the
> > object is defined at the origin, then you can rotate it before moving
> > it. If you only need to rotate around the Y axis then the angle is the
> > arctan in degrees of z / x. So you can use atan2d():
> >
> > #declare targetLocation = <3,4,5>;
> > #declare targetAngle = atan2d(targetLocation.z,targetLocation.x);
> >
> > Hope I understood your question correctly.
>
> I think you do understand my question, but when I use your formula I
> don't get the expected results.  I've output the relevant variable values
> and copied them below.  Only one or two of these objects are actually
> pointing at or nearly at the origin...
>
> #declare rotation = atan2d(z1,x1);
> #object {
>   thing
>   rotate <0,rotation,0>
>   translate <x1,y1,z1>
> }
>
>
> Z:  0.1,  X:  3.5,  Rotation:   1.0
> Z:  1.4,  X:  3.0,  Rotation:  25.0
> Z:  2.3,  X:  2.0,  Rotation:  49.0
> Z:  2.7,  X:  0.8,  Rotation:  73.0
> Z:  2.5,  X: -0.3,  Rotation:  97.0
> Z:  2.0,  X: -1.2,  Rotation: 121.0
> Z:  1.2,  X: -1.7,  Rotation: 145.0
> Z:  0.4,  X: -1.8,  Rotation: 169.0
> Z: -0.4,  X: -1.6,  Rotation:-167.0
> Z: -0.8,  X: -1.1,  Rotation:-143.0
> Z: -1.0,  X: -0.6,  Rotation:-119.0
> Z: -0.9,  X: -0.1,  Rotation: -95.0
> Z: -0.7,  X:  0.2,  Rotation: -71.0
> Z: -0.3,  X:  0.3,  Rotation: -47.0
> Z: -0.1,  X:  0.2,  Rotation: -23.0

The initial axis in the Reorient macro is the initial direction your object
is pointing.  Assuming that your object is created to point in the +z
direction, this should work:

#object {
    thing
    Reorient( z, <-x1, -y1, -z1> )
    translate <x1, y1, z1>
}

I hope this was helpful.


Post a reply to this message

From: Chris B
Subject: Re: How do you rotate an object to face the origin?
Date: 16 Dec 2003 16:02:34
Message: <3fdf72ea$1@news.povray.org>
"Rich" <SrP### [at] ricoswebcom> wrote in message
news:Xns### [at] 204213191226...
> "Chris B" <c_b### [at] btconnectcom> wrote in
> news:3fdf2f74@news.povray.org:
>
> > If you know the targetLocation before you translate the object and the
> > object is defined at the origin, then you can rotate it before moving
> > it. If you only need to rotate around the Y axis then the angle is the
> > arctan in degrees of z / x. So you can use atan2d():
> >
> > #declare targetLocation = <3,4,5>;
> > #declare targetAngle = atan2d(targetLocation.z,targetLocation.x);
> >
> ... snip ...
> when I use your formula I
> don't get the expected results.  I've output the relevant variable values
> and copied them below.  Only one or two of these objects are actually
> pointing at or nearly at the origin...
>
> #declare rotation = atan2d(z1,x1);
> #object {
>   thing
>   rotate <0,rotation,0>
>   translate <x1,y1,z1>
> }

Hi Rich,

I should have been a bit more verbose with my response.
The targetAngle gives you the horizontal angle between the positive x-axis
and the target position.
Looking at what you want to do you will need to work with 90-targetAngle,
which you actually get if you take the arctan of x / z.
You will then need to compensate for the direction that your object is
pointing in when you defined it, so if it points at -z to start with you
don't need to compensate at all and you can use rotation = atan2d(x1,z1);
If your object points out along +z you will need to add or subtract 180.
e.g. rotation = 180 + atan2d(x1,z1);
If it's +x then add 90, for -x subtract 90 (I think!!).

This is all from memory, so you may need to adjust stuff or if you still
have trouble post a small, but working example so someone can check it out
and correct any errors.

Regards,
Chris.

>
>
> Z:  0.1,  X:  3.5,  Rotation:   1.0
> Z:  1.4,  X:  3.0,  Rotation:  25.0
> ... snip...


Post a reply to this message

From: Rich
Subject: Re: How do you rotate an object to face the origin?
Date: 16 Dec 2003 16:16:50
Message: <Xns9453914531EC4spammindspringcom@204.213.191.226>
"Chris B" <c_b### [at] btconnectcom> wrote in
news:3fdf72ea$1@news.povray.org: 
> Looking at what you want to do you will need to work with
> 90-targetAngle, which you actually get if you take the arctan of x /
> z. You will then need to compensate for the direction that your object
> is pointing in when you defined it, so if it points at -z to start
> with you don't need to compensate at all and you can use rotation =
> atan2d(x1,z1); If your object points out along +z you will need to add
> or subtract 180. e.g. rotation = 180 + atan2d(x1,z1);
> If it's +x then add 90, for -x subtract 90 (I think!!).

Swapping the x and z values in the atan2d formula did the trick.  Thank you 
very much!

Rich


Post a reply to this message

From: Rich
Subject: Re: How do you rotate an object to face the origin?
Date: 16 Dec 2003 16:21:43
Message: <Xns94539218C9F8spammindspringcom@204.213.191.226>
"David Wallace" <dar### [at] earthlinknet> wrote in
news:3fdf5798@news.povray.org: 

> The initial axis in the Reorient macro is the initial direction your
> object is pointing.  Assuming that your object is created to point in
> the +z direction, this should work:
> 
> #object {
>     thing
>     Reorient( z, <-x1, -y1, -z1> )
>     translate <x1, y1, z1>
> }


Hmm.  I guess what I didn't understand about the Reorient macro was how to 
determine the values it wanted.  I never would have thought to put negative 
versions of the object's position, for example.  ChrisB's help solved the 
problem, and I actually understand a bit of why it worked!  Thanks for your 
help, now that I have the problem solved I can look into the reorient macro 
code more  closely to see if I can figure out what it does and needs.

Rich


Post a reply to this message

From: David Wallace
Subject: Re: How do you rotate an object to face the origin?
Date: 30 Dec 2003 17:27:34
Message: <3ff1fbd6$1@news.povray.org>
"Rich" <SrP### [at] ricoswebcom> wrote in message
news:Xns### [at] 204213191226...
> "David Wallace" <dar### [at] earthlinknet> wrote in
> news:3fdf5798@news.povray.org:
>
> > The initial axis in the Reorient macro is the initial direction your
> > object is pointing.  Assuming that your object is created to point in
> > the +z direction, this should work:
> >
> > #object {
> >     thing
> >     Reorient( z, <-x1, -y1, -z1> )
> >     translate <x1, y1, z1>
> > }
>
>
> Hmm.  I guess what I didn't understand about the Reorient macro was how to
> determine the values it wanted.  I never would have thought to put
negative
> versions of the object's position, for example.  ChrisB's help solved the
> problem, and I actually understand a bit of why it worked!  Thanks for
your
> help, now that I have the problem solved I can look into the reorient
macro
> code more  closely to see if I can figure out what it does and needs.
>
> Rich

Your object is meant to be placed at <x1,y1,z1>.  For the object to point
back at the origin you need the direction vector <-x1, -y1, -z1>.  If you
use <x1, y1, z1> then your object would point away from the origin.  Try
both and see.  Also try Reorient(-z, <x1, y1, z1>), which points the rear of
the object away from the origin, hence the front at it.
-- 
David Wallace
TenArbor Consulting
"Just in Time Cash"
http://www.tenarbor.com


Post a reply to this message

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