|
|
I've come up with something which maybe faster.
The main idea behind this is that you only change the points you have to.
Here it is:
// Vers: 3.7
// Auth: Leroy Whetstone
// Email whe### [at] gmailcom
// Translate polygon,normal data to POV polygon
//====================================================================
#version 3.7;
#include "colors.inc"
#include "math.inc"
global_settings {assumed_gamma 1 max_trace_level 20}
camera{ location <-3,3,-3>
look_at <0,0,0>
right x*image_width/image_height
}
light_source{<0,10,0> color White}
light_source{<0,0,-10> color White}
//---------- Test Data --------------------
#declare
Data=array[11]{<-0.32,0.32,0>,<-0.12,0.386667,0>,<0.0933333,0.28,0>,<0.16,-0.0266667,0>,
<0.266667,-0.213333,0>,<0.2,-0.32,0>,<0.0666667,-0.266667,0>,
<-0.0133333,-0.346667,0>,<-0.16,-0.12,0>,<-0.32,0.0666667,0>,
<-0.32,0.32,0>}
#declare Norm=-z;
#declare TestR=<95,30,10>; // test rotate
// --------- move test points --------------------
#for(a,0,10)
#declare Data[a]=vrotate(Data[a],TestR)-2*x+y;
#end
#declare Norm=vrotate(Norm,TestR);
#declare Data[5]=Data[5]+x*.0001;
// ----------------get plane----------------
#macro SetPlane()
#local V=Norm;
#declare Cp= (Data[0]+Data[1]+Data[2])/3;// center point of triangle data 0,1,2
#local V1=vnormalize(Cp);
#if((V1.x=V.x)&(V1.x=V.y)&(V1.x=V.y))
#local D= vlength(Cp);
#else
#local Ag=VAngle(Cp,V);
#local D= vlength(Cp)*cos(Ag);
#end
#declare K=D*sqrt(V.x*V.x + V.y*V.y + V.z*V.z);//keep part of plane equation
#end
#macro Test(T)
#local O=Norm.x*T.x + Norm.y*T.y + Norm.z*T.z -K ;//test on plane ?
O
#end
//Test and Fix Data
SetPlane();
#for(a,0,10)
#declare B=Test(Data[a]);//if B=0 point is on plane
#if(B) #debug concat("A =",str(a,0,0)," B=",str(B,9,9),"\n")
#declare Data[a]=VProject_Plane(Data[a]-Cp, Norm)+Cp; // fix broken data
#end
#end
// origonal polygon rotate and move to veiw
polygon{
11
<-0.32,0.32>
<-0.12,0.386667>
<0.0933333,0.28>
<0.16,-0.0266667>
<0.266667,-0.213333>
<0.2,-0.32>
<0.0666667,-0.266667>
<-0.0133333,-0.346667>
<-0.16,-0.12>
<-0.32,0.0666667>
<-0.32,0.32>
rotate TestR
pigment{Red}
translate x*2
}
// test polygon
polygon{
11
#for(a,0,10)
Data[a]
#end
pigment{Red}
}
#for(a,0,10)
#debug concat("Data[",str(a,0,0),"] = <",vstr(3,Data[a] ,",",3,3),">\n")
#end
Have Fun!
Post a reply to this message
|
|