

Thomas de Groot <tho### [at] degrootorg> wrote:
> > I currently have my nose to the ground, trying to find an algorithm to generate
> > the inverse of a 9x9 rigid body transform matrix  if I can puzzle that out,
> > then any object specified with 4 points can be mapped to any other instance with
> > a transform {matrix{}} statement.
> > Then I can take one base, look over where it sits somewhere else in the helix,
> > and calculate exactly how to get it from one place to another.
> >
> That could be very useful. Also in a universal sense, applied to all
> sort of transformations/mutations.
OK, So I haven't ferreted out all the details of the purely matrix approach, but
while closing one of the 100 browser tabs I have open, I stumbled across a guy
using Reorient_Trans, and figured that would be a viable approach.
I had a few false starts due to not really being able to visualize what was
going on, but after making an IRL model and turning it around a few times, the
part I was missing / improperly implementing became obvious, and I was able to
package it all up into a single macro.
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 (AA, FirstTransform)+A;
#local B1 = vtransform (BA, FirstTransform)+A;
#local C1 = vtransform (CA, FirstTransform)+A;
// Find the vector to C1 that is perpendicular to Vector2
#local T1 = vdot (B1A1, C1A1) / vdot (B1A1, B1A1);
#local D = A1 + T1 * (B1A1);
#local Vector3 = C1  D;
// Find the vector to C2 that is perpendicular to Vector2
#local T2 = vdot (B2A2, C2A2) / vdot (B2A2, B2A2);
#local D2 = A2 + T2 * (B2A2);
#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
Post a reply to this message

