POV-Ray : Newsgroups : povray.advanced-users : Request: transform from a rectangle. : Re: Request: transform from a rectangle. Server Time
29 Jul 2024 08:17:36 EDT (-0400)
  Re: Request: transform from a rectangle.  
From: Charles Fusner
Date: 29 Sep 2002 12:05:38
Message: <3D972536.7000400@enter.net>
Slime wrote:
> OK. This should, in theory, do the trick, but it's untested code.
> 
> I'm going to take the box
> box {<0,0,0>,<L,H,W>}
> and make it fit your four points. The point <0,0,0> on the box will
> correspond to the point pBb (the back right of the train car).
> 
> (pAf,  pBf,  pAb,  pBb must be predefined)
> 
> #declare newx = vnormalize(pBf-pBb);
> #declare newz = vnormalize(pAb-pBb);
> #declare newy = vcross(newz,newx);
> matrix <
> newx.x,newx.y,newx.z,
> newy.x,newy.y,newy.z,
> newz.x,newz.y,newz.z,
> pBb.x,pBb.y,pBb.z
> 

Additionally, it should be added that this is, of course,
highly dependant on how you define your corner points for
the rectangle. The algorithm that generates them must be
consistant in their definition, which I gather it is,
based on the naming convention being used for the
variables.

Since this is a train track segment, I take it that "pAf"
stands for "point A, forward", "pBf" is "point B forward",
etc. I'm guessing the lower case "b" means the "back" edge
of the rectangle relative to the track direction.

Now, it would be helpful for visualization if instead of
"A" and "B" we were saying "L" and "R" so we'd know for
sure what way we're looking at the points, but I'll presume
"A" is left edge and "B" is right as if you were looking down
from above, which seems reasonable to me, since otherwise
you'd need a glass bottom track under your train to look up
at it going over your head <g>. In other words,

    pAf +------------------+ pBf                ^
        |                  |                    |
    pAb +------------------+ pBb   Train moves that way.


So, if you have your points named as per above, then pAb
should be the local origin of the new location for the
local coordinate axis. IF these presumptions are correct,
the macro above would work better, just slightly modified
as...

#macro AlignToRect(pAb, pAf, pBf, pBb)
     #local newx = vnormalize(pAf-pAb);
     #local newz = vnormalize(pBb-pAb);
     #local newy = vcross(newx,newz);

     matrix <
         newx.x,newx.y,newx.z,
         newy.x,newy.y,newy.z,
         newz.x,newz.y,newz.z,
         pAb.x, pAb.y, pAb.z
     >
#end


Note, this uses the left rear of the box as the point
of translation, which makes sense, since if, before you
transformed it, it was running <0,0,0> to <L,H,W> then
the transformed box's local origin will be at the new left
rear lower-most point. Also, accordingly, we've used that
local origin in the vector subtraction that yields the
direction vectors to vcross in order to get the new "up"
orientation, so that the pivot point will also be around
this local origin. Keeping these two points in mind will
help you visualize the position and orientation of your
transformed object when the matrix gets through working
its, er... "wonders" on it. :)

Now of course perfect alignment depends on your source points
being "truly" coplanar, but as you noted that part is already
handled by an algorithm that generates it automatically, so
this shouldn't cause any difficulty as long as you're satisfied
that algorithm is working as it should.


-- 
@C[$F];
The Silver Tome ::  http://www.silvertome.com
"You may sing to my cat if you like..."


Post a reply to this message

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