//macro Polynomial(P_string,Sturm,Debug) //P_string = polynomial string "x^6y^4z^2+ 2*y^2z+ 3z^2+ 4xy+ .... " //Strum= on/off sturm //Debug= 0,1,2 0=Debug-off 1=Debug-on 2=extra Debug Display //Poly_format=<4,4>; Display string format //tips: the elements of the polynomial string should // be in the form Nxyz Where N is a integer // and xyz are in that order. These variables can be // raised to almost any power using the hat(^). // (The absolute power limit for one variable is 15) // The times sign(*)and spaces can be use for clarity but is // removed when calculating the polynomial. //Working EXAMPLES: "x^2-y^2" "5*y+6z^2" "2*xyz+z^5" "x^2+y^2-1" "5*y+6y" //Wrong EXAMPLES: "yzx" "x^2*6" "z^2x^4" "3*y(x+1)" // Vers: 3.6 // Auth: Leroy Whetstone Email llrwii@joplin.com #ifndef (Poly_format) #declare Poly_format=<4,4>; #end #macro Polynomial(P_string,Sturm,Debug) #local L=strlen(P_string); #local P_string=strlwr(P_string); #if(Debug) #debug "\n*** Polynomial Equation ***\n\n" #debug concat(P_string,"=0\n") #end //get rid of spaces and '*'s #local Ts=""; #local Cnt = 0; #while (Cnt < L) #local T=substr(P_string,Cnt+1,1) //#if(strcmp(T," ")) #local Ts=concat(Ts,T); #end #if(strcmp(T," "))#if(strcmp(T,"*")) #local Ts=concat(Ts,T); #end #end #local Cnt = Cnt+1; #end #local Q_string=Ts; //#debug concat(Q_string,"\n") #local L=strlen(Q_string); #local Ar=array[L];// string sections array of equation parts #local Qv=array[L];// value for sections //#local Sc=array[L];// sections #local PL=array[L];// polynomial location //cut into separate strings #local S = 1; #local St = 0; #local Cnt = 1; #while (Cnt < L+1) #local j=0; #local T=substr(Q_string,Cnt,1) #if (strcmp(T,"+")=0) #local j=1; #end #if (strcmp(T,"-")=0) #local j=1; #end #if (j) #if(Cnt>1) #if(strcmp(substr(Q_string,S,1),"+")=0) #local S=S+1;#end #local Ar[St]=substr(Q_string,S,Cnt-S) #local S=Cnt; #local St=St+1; #end #end #local Cnt = Cnt+1; #end #if(strcmp(substr(Q_string,S,1),"+")=0) #local S=S+1;#end #local Ar[St]=substr(Q_string,S,Cnt-S) #local St=St+1;//sub strings todle // Show strings #if(Debug) #debug "\n*** Equation parts ***\n" #local Cnt = 0; #while (Cnt < St) #debug concat(str(Cnt,0,0)," ",Ar[Cnt],"\n") #local Cnt = Cnt+1; #end #debug "*********************\n" #end // find limit #local Plj = 0; #local Cnt = 0; #while (Cnt < St) //#debug concat(str(Cnt,0,0)," ",Ar[Cnt],"\n") #local K=strlen(Ar[Cnt]); #local j=0; #local Cnt2 = 1; #while (Cnt2 <= K) #local T=substr(Ar[Cnt],Cnt2,1) #if (strcmp(T,"x")=0) #local j=j+1; #end #if (strcmp(T,"y")=0) #local j=j+1; #end #if (strcmp(T,"z")=0) #local j=j+1; #end #if (strcmp(T,"^")=0) //#debug concat("******* ",substr(Ar[Cnt],Cnt2+1,1))//K-Cnt2-1 #local j=j+val(substr(Ar[Cnt],Cnt2+1,K-Cnt2))-1; #end //#debug concat("j =",str(j,3,3),"\n") #local Cnt2 = Cnt2+1; #end #if(j>Plj) #local Plj=j; #end #local Cnt = Cnt+1; #end #if(Plj<2) #local Plj=2;#end #if(Plj>15) #debug"\n\n******************************\n" #debug concat(" Polynomial Order(",str(Plj,3,3),") is grater than 15\n") #debug" Your formula is to complicated for POV\n" #debug"******************************\n\n" #error "Stopped" #end #if(Debug) #debug concat("\nPolynomial Order =",str(Plj,0,0),"\n") #end //figure out Polynomial order number // order number=On=Plj; #local Ton=(Plj+1)*(Plj+2)*(Plj+3)/6; #local PT=array[Ton];// table strings #local PV=array[Ton];// table values //____make Polynomial table values_____________ #local Cnt = 0; #while (Cnt < Ton) #local PV[Cnt]=0; #local Cnt = Cnt+1; #end //make Polynomial table strings #local X = 0; #local Y = 0; #local Z = 0; #local C1 = Plj;#local C2 = Plj; #local Cnt = 0; #while (Cnt < Ton) #local Ts=""; #if(X) #if(X>1) #local Ts=concat(Ts,"x^",str(X,0,0)); #else #local Ts=concat(Ts,"x"); #end #end #if(Y) #if(Y>1) #local Ts=concat(Ts,"y^",str(Y,0,0)); #else #local Ts=concat(Ts,"y"); #end #end #if(Z) #if(Z>1) #local Ts=concat(Ts,"z^",str(Z,0,0)); #else #local Ts=concat(Ts,"z"); #end #end #local PT[Ton-Cnt-1]=Ts; //#debug concat(str(Ton-Cnt-1,0,0)," ",Ts,"\n")//,str(C1,0,0),",",str(C2,0,0),"\n") #local Z=Z+1; #if(Z>C2) #local Z=0; #local C2=C2-1; #local Y=Y+1; #if(C2<0) #local C1=C1-1; #local C2=C1; #local Y=0; #local X=X+1; #end #end #local Cnt = Cnt+1; #end //#debug"-----\n" //#debug concat("St =",str(St,0,0),"\n") #if(Debug) #debug concat("\nPolynomial Elements =",str(Ton,0,0),"\n\n") #end //___________find Polynomial in eguation____________________ #local Cnt = 0; #while (Cnt < St) #if(Debug) #debug concat(Ar[Cnt]," ") #end //get value #local Ts=Ar[Cnt]; #local Tl=strlen(Ts); #if(Tl) //#debug"Hit\n" #local Sv=val(Ts); #local Sl=strlen(str(Sv,0,0));//interger value //calc Sl #local q=1; #local qv=0; #while(qv=0) #local Tz=substr(Ts,q,1); #if(strcmp(Tz,"x")=0)#local qv=q;#end #if(strcmp(Tz,"y")=0)#local qv=q;#end #if(strcmp(Tz,"z")=0)#local qv=q;#end #if(qv=0)#local q=q+1; #if(q>Tl) #local qv=99;#end #end #end //#local Sl=qv; #if(qv!=99) #local Sl=qv-1; #end #if((Sv=0)&(strcmp(substr(Ts,1,1),"-")=0)) #local Sv=-1; #end //#debug concat("Sv,Sl =",str(Sv,3,3),",",str(Sl,3,3),",") //#if(Sl=Tl) #local PV[Ton-1]=Sv; #if(Debug) #debug "Constant\n" #end #if(qv=99) #local PV[Ton-1]=PV[Ton-1]+Sv; #if(Debug) #debug "Constant\n" #end #else #if(Sv!=0) #local Ts= substr(Ts,Sl+1,Tl-Sl); #end //#debug concat(">"Ts,"<")//","str(Sl,0,0)","str(Tl,0,0) #local Cnt2 = 0; #while (Cnt2 < Ton) #if(strcmp(PT[Cnt2],Ts)=0) #if(Debug) #debug concat("Element ",str(Cnt2,0,0),"\n")#end #if(Sv=0) #local Sv=1; #end #local PV[Cnt2]=PV[Cnt2]+Sv; #local Cnt2=10000; #end #local Cnt2 = Cnt2+1; #end #if(Cnt2<10000) #debug concat("Error Eguation part =",str(Cnt,3,3),"\n") #end #end #end // #debug concat(Ts,"\n")//","str(Sl,0,0)","str(Tl,0,0) #local Cnt = Cnt+1; #end //show PV table #if(Debug>1) #debug"\n" #local Cnt = 0; #while (Cnt < Ton) #if(int(PV[Cnt])=PV[Cnt])#debug concat("PT["str(Cnt,0,0),"]= ",str(PV[Cnt],0,0)," ",PT[Cnt],"\n") #else #debug concat("PT["str(Cnt,0,0),"]= ",str(PV[Cnt],Poly_format.x,Poly_format.y)," ",PT[Cnt],"\n") #end #local Cnt = Cnt+1; #end #end //make Poly poly{Plj,< #local Cnt = 0; #while (Cnt < Ton-1) PV[Cnt], #local Cnt = Cnt+1; #end PV[Ton-1]> #if(Sturm)sturm #end } #if(Debug) #debug"\n****** Usable Poly ************* \n" #debug concat("\npoly{"str(Plj,0,0),",\n <") #local Cnt2 = 0; #local Cnt = 0; #while (Cnt < Ton-1) #if(PV[Cnt]=0)#local OUT= concat(str(PV[Cnt],0,0),",") #else #if(int(PV[Cnt])=PV[Cnt])#local OUT= concat(str(PV[Cnt],0,0),",") #else #local OUT= concat(str(PV[Cnt],Poly_format.x,Poly_format.y),",") #end #end #debug OUT #local Cnt2 = Cnt2+strlen(OUT); #if(Cnt2>=70) #local Cnt2 =0;#debug"\n " #end #local Cnt = Cnt+1; #end #if(int(PV[Cnt])=PV[Cnt]) #local OUT= concat(str(PV[Cnt],0,0),">\n") #else #local OUT= concat(str(PV[Cnt],Poly_format.x,Poly_format.y),">\n") #end #debug OUT #if(Sturm) #debug " sturm}\n\n\n" #else #debug " }\n\n\n" #end #end #end //--------------- testing---------------------------------------------------------- #ifndef(Get) //INI Width=600 Height =300 #include "colors.inc" camera{ location <0,0,-50> look_at <0,0,0> right x*image_width/image_height } light_source{<0,30,0> color White} light_source{<0,0,-30> color White} light_source{<0,0,30> color White} light_source{<-30,0,0> color White} light_source{<30,0,0> color White} #declare Poly_format=<0,3>; background{White} #declare Eq="x+y^2+.3z^3-9xy-20"; #declare Eq="x^2-3yz^2-5";//mushroom #declare Eq="X^2+Y^2-Z^2-25+x^2+y^2-1"; #declare Eq="X^2+Y^2-Z^2-25-5*x^2+3y^2+8"; #declare Poly=Polynomial(Eq,0,1) intersection{ object{Poly} sphere{0,8}//box{-8,8}}// pigment{gradient y scale.4} translate -x*17} object{Poly clipped_by{sphere{0,8}}//box{-8,8}}// bounded_by{clipped_by} pigment{Red} translate x*17} //object{Poly pigment{Red} translate -x*27} #end