|
![](/i/fill.gif) |
I found macro to calculate radius and center of inner circle of 2d triangle. Any
idea for shorter version of it ? This works fine but I'm asking just for my
knowledge extending :-) Some vector optimizations ?
#local f_det=function(a11,a12,a21,a22){(a11*a22)-(a12*a21)};
// take two lines as pairs of points
// and calculate intersection
#macro Cross(x1,y1,x2,y2,x3,y3,x4,y4)
#local A1=y2-y1;
#local B1=x1-x2;
#local C1=f_det(x2,y2,x1,y1);
#local A2=y4-y3;
#local B2=x3-x4;
#local C2=f_det(x4,y4,x3,y3);
#local D=f_det(A1,A2,B1,B2);
(<f_det(B1,B2,C1,C2),f_det(C1,C2,A1,A2)>/D)
#end
// input A,B,C - vertices of 2d triangle
// output <center.x,center.y,radius>
#macro Inner_Circle(A,B,C)
#local a=vlength(B-A);
#local b=vlength(C-B);
#local c=vlength(A-C);
#local p=(a+b+c)/2;
#local R=sqrt((p-a)*(p-b)*(p-c)/p);
#local P0=R*vnormalize(vcross(vcross(B-A,C-A),C-B));
#local P1=B+P0;
#local P2=C+P0;
#local R0=R*vnormalize(vcross(vcross(C-B,A-B),A-C));
#local R1=C+R0;
#local R2=A+R0;
#local P=Cross(P1.x,P1.y,P2.x,P2.y,R1.x,R1.y,R2.x,R2.y);
<P.x,P.y,R>
#end
ABX
--
#declare _=function(a,b,x){((a^2)+(b^2))^.5-x}#default {pigment{color rgb 1}}
union{plane{y,-3}plane{-x,-3}finish{reflection 1 ambient 0}}isosurface{ //ABX
function{_(x-2,y,1)|_((x+y)*.7,z,.1)|_((x+y+2)*.7,z,.1)|_(x/2+y*.8+1.5,z,.1)}
contained_by{box{<0,-3,-.1>,<3,0,.1>}}translate z*15finish{ambient 1}}//POV35
Post a reply to this message
|
![](/i/fill.gif) |