POV-Ray : Newsgroups : povray.general : translation / rotation query Server Time: 23 Oct 2019 03:15:22 GMT
 translation / rotation query (Message 1 to 5 of 5)
 From: Bob Frew Subject: translation / rotation query Date: 18 Sep 2019 18:51:14 Message: <5d827ca2@news.povray.org>
```Hi ,
does anyone knows a way to achieve the following.

For any line with p1 and p2 as the end points to translate/rotate as
necessary to put
p1 at <0,0,0> and p2 on the x axis
I need to then know necessary translate/rotate to be able to put them
back.

I can see how to do this by evaluating all possible orientations for p2
after moving p1 to <0,0,0>
This will end up very "heavy duty" so (as I know nothing of matrices
etc.) I thought I would ask you guys if there is a more elegant way

Hopeful     ... Bob

A pointer in the right direction would be good (no pun intended)
```
 From: Bald Eagle Subject: Re: translation / rotation query Date: 18 Sep 2019 19:55:01 Message:
```Bob Frew <bob### [at] ntlworldcom> wrote:
> Hi ,
> does anyone knows a way to achieve the following.
>
> For any line with p1 and p2 as the end points to translate/rotate as
> necessary to put
>          p1 at <0,0,0> and p2 on the x axis
> I need to then know necessary translate/rotate to be able to put them
> back.
>
> I can see how to do this by evaluating all possible orientations for p2
> after moving p1 to <0,0,0>
> This will end up very "heavy duty" so (as I know nothing of matrices
> etc.) I thought I would ask you guys if there is a more elegant way
> before going down that road.
>
> Hopeful     ... Bob
>
> A pointer in the right direction would be good (no pun intended)

You're going to first translate the line segment to the origin.

Then you can determine the angle of the p2 endpoint projected onto the x-z
plane.
an atan2 with that vector and <1,0,0> gives you a rotation around the y axis.

Then you do another atan2 with the resulting vector in the x-y plane to give the
rotation angle around the z axis necessary to place it coincident with the
x-axis.

You simply rotate around z by the negative angle, rotate around y by _that_
negative angle, and translate back to the original p1.

Just simple trig - no matrices.

Check out       http://f-lohmueller.de/pov_tut/a_geo/a_geo80e.htm
```
 From: Bill Pragnell Subject: Re: translation / rotation query Date: 18 Sep 2019 21:40:02 Message:
```Bob Frew <bob### [at] ntlworldcom> wrote:
> For any line with p1 and p2 as the end points to translate/rotate as
> necessary to put
>          p1 at <0,0,0> and p2 on the x axis
> I need to then know necessary translate/rotate to be able to put them
> back.

transforms.inc has some useful macros for this sort of thing (see
http://www.povray.org/documentation/3.7.0/r3_4.html#r3_4_9_1_29).

For example, you could do

translate -p1 Reorient_Trans(p2-p1, x)

then

Reorient_Trans(x, p2-p1) translate p1

It would be useful to know the wider context of what you're trying to do. There
might be a larger elegant solution that helps even more!

Bill
```
 From: Bob Frew Subject: Re: translation / rotation query Date: 19 Sep 2019 11:04:14 Message: <5d8360ae\$1@news.povray.org>
```On 18/09/2019 19:51, Bob Frew wrote:
> Hi ,
> does anyone knows a way to achieve the following.
>
> For any line with p1 and p2 as the end points to translate/rotate as
> necessary to put
>  Â Â Â Â Â Â Â  p1 at <0,0,0> and p2 on the x axis
> I need to then know necessary translate/rotate to be able to put them back.
>
> I can see how to do this by evaluating all possible orientations for p2
> after moving p1 to <0,0,0>
> This will end up very "heavy duty" so (as I know nothing of matrices
> etc.) I thought I would ask you guys if there is a more elegant way
> before going down that road.
>
> HopefulÂ Â Â Â  ... Bob
>
> A pointer in the right direction would be good (no pun intended)
>
Hi and thanks for those replies.

After I posted the query I remembered a piece of code from years ago I
had used. So I dug it out this morning. Someone else may need this

#macro placeObj(obj,V1,V2)
#local mp = <(V1.x + V2.x)/2,(V1.y + V2.y)/2,(V1.z + V2.z)/2>;  //
mid point
#local V2N = V2 - mp;
#local V3 = VPerp_To_Plane(V1, V2);

#declare newxdir = vnormalize(V2N);
#declare newydir = vnormalize(V3);
#declare newzdir = vcross(newxdir, newydir);
#declare transamnt = mp;

#declare placedObj = object {obj
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 >
}
#end

I may have tweaked this, but I did not write it (anyone know who did ?)
It seems to work well.

The problem is I don't understand it so I will probably write my own as
per Bald Eagle suggestion.
My subconscious must have known there was a matrix in there somewhere.

Thanks again    .... Bob
```

Attachments:

Preview of image 'smiley3.png'

 From: Bald Eagle Subject: Re: translation / rotation query Date: 19 Sep 2019 18:05:01 Message:
```Bob Frew <bob### [at] ntlworldcom> wrote:

> Hi and thanks for those replies.

> I may have tweaked this, but I did not write it (anyone know who did ?)
> It seems to work well.

Mike Williams?
http://news.povray.org/povray.newusers/message/%3C0B3%2BvIAR3W8BFwZQ%40econym.demon.co.uk%3E/#%3C0B3%2BvIAR3W8BFwZQ%40e
conym.demon.co.uk%3E

> The problem is I don't understand it so I will probably write my own as
> per Bald Eagle suggestion.

Well yeah, Mike's [IIRC] a mathematician, so he goes about things in a peculiar
way.  Highly effective, but often hard to decipher.

There's not a whole lot of mystery to the matrix transform.  You're going to
just composite the two rotations that you want and take the individual
components of that result and distribute it through the x, y, and z parts of the
matrix.   The translate part is along the bottom row.
I find that the more I play with parametrics, the easier it is to visualize how
the parts of the matrix "work".

It's the dot products and cross products and some of the other vector functions
that I usually have to work out in order to really see what's going on.

You could do it the trig way, the vector function way, and the matrix way, or
some other way, and just roll it all into 1 scene / include file with a
#switch - #case - #break - #end block to pick which method you want to use.

Then you have it all worked out and can follow the "long" trig method but see
how it gets condensed into the other shorter methods.
```