POV-Ray : Newsgroups : povray.binaries.images : B-DNA : Re: B-DNA Server Time
5 Nov 2024 18:22:00 EST (-0500)
  Re: B-DNA  
From: Tor Olav Kristensen
Date: 11 Feb 2024 16:15:00
Message: <web.65c937f741c066f0e9c3f02789db30a9@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
>...
> Identify any three points on your original object (A, B, C), and where those
> three points end up (A2, B2, C2)
>
> Apply the macro like so:
> #declare MyTransform = Reorient_Triangle (A, B, C, A2, B2, C2)
> object {MyObject transform {MyTransform}}
>
> Please try this out with a large assortment of objects in various orientations
> to see if I missed anything.   The only thing not included is a sanity check for
> plugging in a second set of coordinates that are identical to the first.
>
> #macro Reorient_Triangle (A, B, C, A2, B2, C2)
>  // Bill Walker "Bald Eagle" February 2024
>  #ifndef(TRANSFORMS_INC_TEMP)
>   #include "transforms.inc"
>  #end
>  #local Translate1 = transform {translate -A}
>  #local Vector1 = B - A;
>  #local Vector2 = B2 - A2;
>  // Align Vector1 to Vector2
>  #local FirstTransform = transform {Reorient_Trans (Vector1, Vector2)};
>  #local A1 = vtransform (A-A, FirstTransform)+A;
>  #local B1 = vtransform (B-A, FirstTransform)+A;
>  #local C1 = vtransform (C-A, FirstTransform)+A;
>  // Find the vector to C1 that is perpendicular to Vector2
>  #local T1 = vdot (B1-A1, C1-A1) / vdot (B1-A1, B1-A1);
>  #local D = A1 + T1 * (B1-A1);
>  #local Vector3 = C1 - D;
>  // Find the vector to C2 that is perpendicular to Vector2
>  #local T2 = vdot (B2-A2, C2-A2) / vdot (B2-A2, B2-A2);
>  #local D2 = A2 + T2 * (B2-A2);
>  #local Vector4 = C2 - D2;
>  // Rotate everything around Vector2 so that the perpendicular vectors match
>  #local SecondTransform = transform {Reorient_Trans (Vector3, Vector4)};
>  // Now everything is similarly aligned with 3 sequential transforms
>  // and translating a final time puts the object at the destination
>  #local Translate2 = transform {translate A2}
>  #local T = transform { transform {Translate1} transform {FirstTransform}
> transform {SecondTransform} transform {Translate2} }
>
>  T
>
> #end
>...


Hi Bill

To simplify your macro, you could first simplify the problem, like this:

You can start with two triangles A, B, C and A2, B2, C2, which have their A and
A2 points at origo.

This means the translate -A and translate A2 transformations will not lead to
any changes, so they can be removed.

Your A1 point will now also end up at origo, since the reorient transformation
does not result in any translations, only a rotation.

So now you can remove A, A1 and A2 from all expressions in your macro.

You will then get some variables whose values are only copies of other
variables' values. You can eliminate these by using those other variables
instead.

Parts of your expressions for T1/D and T2/D2 can be replaced with a call to the
VProject_Plane() macro from math.inc or VectorProject() from my vectors.inc.

To "unsimplify" the problem again, in order to deal with triangles which does
not have their A and A2 points at origo, you can just reintroduce the translate
-A and translate A2 transformations in the resulting composite transform
expression.

P.S.: You don't have to wrap the Reorient_Trans macro calls into transform { }
statements, because this is already done by the Reorient_Trans macro itself.

P.P.S. That also goes for the transformations within the final transform { }
statement. You can write it like this: transform { Translate1 FirstTransform
SecondTransform Translate2 } - and you don't have to put it into a variable (T)
before you return it.

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


Post a reply to this message

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