POV-Ray : Newsgroups : povray.advanced-users : A macro I'm proud of I think (public Beta) : Beta 2 Server Time
30 Jul 2024 00:20:46 EDT (-0400)
  Beta 2  
From: Dan Johnson
Date: 7 May 2001 21:16:06
Message: <3AF89A84.AE68E4FF@hotmail.com>
Ok Tor Olav now that I understand the math I am certain your code works perfectly I
simplified it enough to remove 3 local variables.  I then added descriptive error
messages without halting rendering.  There aren't any support functions now.  Unless
someone thinks of a way to make it better this is the final version.

////////////////////////////////////////////////////////////////
// Four_point_plane  Beta 2  May 7 2001
//
// Original Idea Dan Johnson
// Code Dan Johnson, and Tor Olav Kristensen
//
// In povray everything on one side of the plane is considered inside the plane
object
// P1, P2, and P3 are points on the plane, none of these points can be the same as
any other,
// and they can't be in a strait line.  Inside point is a control point to determine
witch side of the plane
// is considered inside. Tor Olav posted much simpler code to do the same job a few
days after me.
// I believe that I can prove it always works.  The plane generating code is based on
Tor Olav's with a
// few minor simplifications, and the error trapping is mostly mine.
// Dan Johnson


#macro Four_point_plane(P1, P2, P3, I)// P1-3 = points on plane I = inside point

  #local Cross = vcross(P2 - P1, P3 - P1);
  #local STP = vdot(Cross, I - P1); // Scalar Triple Product
  #if (STP = 0) // Check for invalid data
    //determine specific error, or errors.
    #local Errors = "\nFour_point_plane did not create a plane because of the
following bad imput\n"
    #local S1 = (vdot((P1 = P2),<1,1,1>) = 3);  // same checks
    #local S2 = (vdot((P2 = P3),<1,1,1>) = 3);
    #local S3 = (vdot((P3 = P1),<1,1,1>) = 3);
    #if (S1 + S2 + S3 > 0)
     #if (S1) #local Errors = concat (Errors,"Point1 = Point2\n")#end
     #if (S2) #local Errors = concat (Errors,"Point2 = Point3\n")#end
     #if (S3) #local Errors = concat (Errors,"Point3 = Point1\n")#end
    #else
     #if (abs(vdot(vnormalize(P2-P1),vnormalize(P3-P2))) = 1)
      #local Errors = concat (Errors,"All points on same line\n")
     #else
      #local Errors = concat (Errors,"Inside point is on plane\n")
     #end
    #end
    #warning Errors
    sphere {<0,0,0>,0}  //Whatever called Four_point_plane is expecting an object.
  #else
    #local N = (STP > 0 ? -1 : 1)*vnormalize(Cross);// normal vector
    plane { N, vdot(P1, N) }
  #end // if

#end // macro Four_point_plane

//  Three_point_plane assumes that the origin is in the object.
#macro Three_point_plane(P1,P2,P3)
        Four_point_plane(P1,P2,P3,<0,0,0>)
#end


--
Dan Johnson

http://www.geocities.com/zapob


Post a reply to this message

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