POV-Ray : Newsgroups : povray.advanced-users : A macro I'm proud of I think (public Beta) : Re: A macro I'm proud of I think (public Beta) Server Time
30 Jul 2024 00:22:45 EDT (-0400)
  Re: A macro I'm proud of I think (public Beta)  
From: Dan Johnson
Date: 4 May 2001 04:58:10
Message: <3AF3C0C5.BCD4AEFE@hotmail.com>
Tor Olav Kristensen wrote:

> Dan Johnson wrote:
> >
> > A while ago I was working on a big complicated image, and I wanted
> > to make a precise plane intersection shape far away from the origin.
> > I quickly realized that although I knew exact locations, planes are
> > described around the origin.  It only takes three points to define
> > a plane, but for use in plane intersections there is an inside and
> > an outside, so I decided to use a fourth point to decide witch side
> > of the plane is inside.  I thought I could write a macro to do it in
> > 15 minutes, I was very wrong.  I think it finally works now, but I
> > thought that a few days ago before I found some huge bugs.  If you
> > find any bugs or have suggestions, please comment.
> >...
>
> I think that the macro below will do the same.
>
> #macro FourPointPlane(p1, p2, p3, pInside)
>
>   #local vA = p2 - p1;
>   #local vB = p3 - p1;
>   #local vC = pInside - p1;
>   #local vN = vcross(vA, vB);
>   #local STP = vdot(vN, vC); // Scalar Triple Product of vA, vB and vC
>   #if (STP = 0) // Check for coplanar vectors
>     #error "\nMacro FourPointPlane: All points lie in the same plane.\n"
>   #else
>     #local vN = (STP > 0 ? -1 : 1)*vnormalize(vN);
>     plane { vN, vdot(p1, vN) }
>   #end // if
>
> #end // macro FourPointPlane
>
> - But I haven't tested it much. Sorry.
>
> I also have some suggestions for some of
> your support macros if you are interested.
>
> --
> Best regards,
>
> Tor Olav
>
> mailto:tor### [at] hotmailcom
> http://hjem.sol.no/t-o-k/tokpicts.html
> http://www.crosswinds.net/~tok

You have the right idea, my beta program seems to be working lets optimize
it.  Your error catching test is simple, and clever.  I checked all the
math, and it should effectively catch all the bugs my functions do.  It
isn't very helpful to anyone using it, as to what specific thing, or things
they did wrong though.  I would like to use it as a condition for running
the other tests so that it only tries to find out what is wrong, after it
has found out that something is wrong.  I don't understand how the sign of
the triple scalar product is used to find out if the normal needs to be
corrected.  The line " plane { vN, vdot(p1, vN) } " is very similar to what
I get when I write out the formula I used and simplified.  An important
difference is that when I simplified I needed an abs around the result of
the vdot.

Having written my own version I have a fairly comprehensive test scene.  I
decided to replace my macro with your macro in the scene, and see what
happens.  Immediately it got a user error directive.  I commented out all
the function calls, but the first, and it still happened.  Now I knew that
the very first function call was getting an error.  I did the math by hand,
and found out that the value of STP should be -4 not 0.  I dug further, and
found out that the value of vN was <0,0,0>.  This shouldn't be, now I am
very confused.  Here is the test scene maybe you can make sense of it.

#include "colors.inc"
#include "polyhedra.inc"
#include "finish.inc"

#macro ThreePointPlane(P1,P2,P3)
        FourPointPlane(P1,P2,P2,<0,0,0>)
#end

/*
#declare Cube1 = <1,1,1>; // Cube vertexes
#declare Cube2 = <1,1,-1>;  // from polyhedra.inc
#declare Cube3 = <1,-1,1>;
#declare Cube4 = <1,-1,-1>;
#declare Cube5 = <-1,1,1>;
#declare Cube6 = <-1,1,-1>;
#declare Cube7 = <-1,-1,1>;
#declare Cube8 = <-1,-1,-1>;
*/

intersection {
                ThreePointPlane (Cube5,Cube3,Cube2)
                ThreePointPlane (Cube8,Cube3,Cube2)
                ThreePointPlane (Cube2,Cube5,Cube8)
                ThreePointPlane (Cube8,Cube5,Cube3)
                FourPointPlane (<0,1,1>,<0,0,0>,<0,-1,1>,<-1,0,0>)
                texture {pigment {rgbt <1,0,0,0>}} finish {
                ambient .1
                diffuse 1
                reflection .15
                specular 0
                roughness .6
}}
object{Cube_edges(1,.1) texture { finish {
                ambient .1
                diffuse .4
                reflection .25
                specular .6
                roughness .1
}pigment{Green}}}
//object {FourPointPlane (<2,2,1>,<3,3,1>,<4,7,1>,<0,0,20>) pigment
{CornflowerBlue}}
sphere{Cube1,.2 pigment{Blue}}

light_source {<100,30,-100> rgb 2}
camera {location <6,8,-12> look_at 0 angle 20}


--
Dan Johnson

http://www.geocities.com/zapob


Post a reply to this message

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