POV-Ray : Newsgroups : povray.binaries.images : B-DNA : Re: B-DNA Server Time
25 May 2024 10:36:18 EDT (-0400)
  Re: B-DNA  
From: Tor Olav Kristensen
Date: 13 Feb 2024 19:55:00
Message: <web.65cc0ef741c066f0f673154389db30a9@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>...
> - and this version also works when that is not the case. I.e. It also works when
> there are translations within the transformation.
>
> #macro Reorient_Triangle(p0A, p0B, p0C, p2A, p2B, p2C)
>
>     #local v0A0B = p0B - p0A;
>     #local v0A0C = p0C - p0A;
>     #local v2A2B = p2B - p2A;
>     #local v2A2C = p2C - p2A;
>     #local FirstTransform = Reorient_Trans(v0A0B, v2A2B)
>     #local v0A1B = vtransform(v0A0B, FirstTransform);
>     #local v0A1C = vtransform(v0A0C, FirstTransform);
>     #local v1D1C = v0A1C - vdot(v0A1C, v0A1B)/vdot(v0A1B, v0A1B)*v0A1B;
>     #local v2D2C = v2A2C - vdot(v2A2C, v2A2B)/vdot(v2A2B, v2A2B)*v2A2B;
>     #local SecondTransform = Reorient_Trans(v1D1C, v2D2C)
>
>     transform {
>         transform { translate -p0A }
>         transform { FirstTransform }
>         transform { SecondTransform }
>         transform { translate +p2A }
>     }
>
> #end // macro Reorient_Triangle

In the macro above v1D1C is perpendicular to v0A1B and v2D2C is perpendicular to
v2A2B. I.e vdot(v1D1C, v0A1B) = 0 and vdot(v2D2C, v2A2B) = 0.

It is also possible to find another vector; v1 that is perpendicular to v0A1B0
and another vector; v2 that is perpendicular to v2A2B by calculating two cross
products, like this:

v1 = vcross(v0A1B, v0A1C)
v2 = vcross(v2A2B, v2A2C)

Then the macro can be rewritten like this:

#macro Reorient_Triangle(p0A, p0B, p0C, p2A, p2B, p2C)

    #local v0A0B = p0B - p0A;
    #local v0A0C = p0C - p0A;
    #local v2A2B = p2B - p2A;
    #local v2A2C = p2C - p2A;
    #local FirstTransform = Reorient_Trans(v0A0B, v2A2B)
    #local v0A1B = vtransform(v0A0B, FirstTransform);
    #local v0A1C = vtransform(v0A0C, FirstTransform);
    #local v1 = vcross(v0A1B, v0A1C);
    #local v2 = vcross(v2A2B, v2A2C);
    #local SecondTransform = Reorient_Trans(v1, v2)

    transform {
        translate -p0A
        FirstTransform
        SecondTransform
        translate +p2A
    }

#end // macro Reorient_Triangle


- which can be simplified a little bit, like e.g. this:

#macro Reorient_Triangle(p0A, p0B, p0C, p2A, p2B, p2C)

    #local v0A0B = p0B - p0A;
    #local v0A0C = p0C - p0A;
    #local v2A2B = p2B - p2A;
    #local v2A2C = p2C - p2A;
    #local Transform = Reorient_Trans(v0A0B, v2A2B)
    transform {
        translate -p0A
        Transform
        Reorient_Trans(
            vtransform(
                vcross(v0A0B, v0A0C),
                Transform
            ),
            vcross(v2A2B, v2A2C)
        )
        translate +p2A
    }

#end // macro Reorient_Triangle


- but imho it does now look a bit ugly.

--
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.