POV-Ray : Newsgroups : povray.advanced-users : Reorient_Trans macro details : Re: Reorient_Trans macro details Server Time18 Sep 2024 23:09:55 EDT (-0400)
 Re: Reorient_Trans macro details
 From: Tor Olav Kristensen Date: 8 Feb 2024 19:35:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.65c5727c7ecd0aae9c3f02789db30a9%40news.povray.org",
"dateCreated": "2024-02-09T00:35:00+00:00",
"datePublished": "2024-02-09T00:35:00+00:00",
"author": {
"@type": "Person",
"name": "Tor Olav Kristensen"
}
}
"Bald Eagle" <cre### [at] netscapenet> wrote:
>...
>   // This makes no sense to me, since Vec_1 and Vec_2 are both normalized
> vectors,
>   // so the length of one unit vector minus another unit vector will ALWAYS be
> zero
>   #if (vlength (Vec_1-Vec_2) = 0)
>    transform {}
>   #else
>    // Which means that this part NEVER gets executed
>    #local vZ = VPerp_To_Vector (Vec_2);
>    transform {Axis_Rotate_Trans (vZ, 180)}
>...

IIRC it was me that added those two if-then-else parts to John VanSickle's
reorient macro.

Note that we are subtracting the normalized vectors, not their lengths.
And then we check if the resulting vector has zero length.

So no, one unit vector minus another unit vector will NOT ALWAYS be zero, only
if they are pointing the same direction, in which case no transformation is
necessary.

After the last else statement we can be sure that the two vectors are pointing
in opposite directions. In this case the math for calculating the components of
the reorient matrix breaks down.

In this case we can not know what the user actually want to achieve. (And
perhaps she/he does not know this her/him-selves.)

We can (and perhaps we should) now give up and use the #error statement.

But in some cases we can choose one of infinitely many possible solutions and
the result will be the same (e.g. if the reoriented object is symmetric around a
line in the same direction as the the "reorient from" vector, like a cylinder.)

Now note that the reorient transform is very similar to the axis rotate
transform. If we take the cross product between the vector to reorient from and
the vector to reorient to, we get a rotation axis for the axis rotate transform.
And if we find the angle between those two vectors, (e.g. by acos of their dot
product, or arcsin of the length of their cross product, or both combined with
atan2, or a more numerical stable formula), we have the rotation angle for the
axis transform.

I choose one vector (from infinitely many vectors), that is perpendicular to
both the "rotate from" vector and the "rotate to" vector, to use for the axis in
the axis rotate transform. The rotation angle is 180 degrees.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k
```