|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Wlodzimierz ABX Skiba" wrote:
>
> 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 ?
Yes Wlodzimierz, vector math would be my answer... ;)
Maybe what I wrote in this post will interest you:
news://news.povray.org/3B82F267.36412849%40hotmail.com
(My reply 1. Aug. 2001 to Mark M. Wilson's thread;
"general geometry question" )
Here's some of my further comments:
news://news.povray.org/3B82FDB9.45E83FA%40hotmail.com
And here's a link to the start of that thread:
http://news.povray.org/povray.general/17701
Tor Olav
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Tor Olav Kristensen wrote:
>
> "Wlodzimierz ABX Skiba" wrote:
> >
> > 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 ?
>
> Yes Wlodzimierz, vector math would be my answer... ;)
>
> Maybe what I wrote in this post will interest you:
> news://news.povray.org/3B82F267.36412849%40hotmail.com
> (My reply 1. Aug. 2001 to Mark M. Wilson's thread;
> "general geometry question" )
>
> Here's some of my further comments:
> news://news.povray.org/3B82FDB9.45E83FA%40hotmail.com
>
> And here's a link to the start of that thread:
> http://news.povray.org/povray.general/17701
It seems like I misunderstood your problem.
But now I have made a new vector math macro that
solves the correct problem.
I think I'll post it when I have had some sleep.
Tor Olav
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
This code seems to work with all my tests. It uses the law of sines.
#macro Project(a,b)
#local tmp = (vdot(a,b)/pow(vlength(a),2))*a;
tmp
#end
#macro Angle(v1,v2)
degrees(acos(vdot(v1,v2)/(vlength(v1)*vlength(v2))))
#end
#declare p0 = <-1,0,0>;
#declare p1 = <1,0,0>;
#declare p2 = <-1,-1,0>;
#declare p3 = (p0+vnormalize(p1-p0)+p0+vnormalize(p2-p0))/2;
#declare a1 = Angle(p1-p0,p3-p0);
#declare a2 = Angle(p2-p1,p0-p1)/2;
#declare a3 = 180-a1-a2;
#declare lc = sin(radians(a2))*vlength(p1-p0)/sin(radians(a3));
#declare C = p0 + vnormalize(p3-p0)*lc;
sphere { C 0.06 pigment { rgb <1,1,0> } }
#declare D = p0 +Project(p2-p0,C-p0)
sphere { D 0.06 pigment { rgb <1,1,0> } }
disc{ C, vcross(p1-p0,p2-p0), vlength(D-C) pigment { rgb <1,1,0> } }
Josh English
eng### [at] spiritonecom
"W3odzimierz ABX Skiba" wrote:
>
> 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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Tor Olav Kristensen wrote:
>
> Tor Olav Kristensen wrote:
> >
> > "Wlodzimierz ABX Skiba" wrote:
> > >
> > > 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 ?
> >
> > Yes Wlodzimierz, vector math would be my answer... ;)
> >
> > Maybe what I wrote in this post will interest you:
> > news://news.povray.org/3B82F267.36412849%40hotmail.com
> > (My reply 1. Aug. 2001 to Mark M. Wilson's thread;
> > "general geometry question" )
> >
> > Here's some of my further comments:
> > news://news.povray.org/3B82FDB9.45E83FA%40hotmail.com
> >
> > And here's a link to the start of that thread:
> > http://news.povray.org/povray.general/17701
>
> It seems like I misunderstood your problem.
>
> But now I have made a new vector math macro that
> solves the correct problem.
>
> I think I'll post it when I have had some sleep.
Sorry, have not had time before now to post my code.
The CircleInscribedInTriangle() macro below seems
to do the trick.
Tor Olav
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2001 by Tor Olav Kristensen
// Email: tor### [at] hotmailcom
// http://www.crosswinds.net/~tok
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#version 3.1;
#include "colors.inc"
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Main macro
#macro CircleInscribedInTriangle(pA, pB, pC, pCenter, Radius, vPlane)
#local vAB = pB - pA;
#local vBC = pC - pB;
#local vCA = pA - pC;
#local ab = vlength(vAB);
#local bc = vlength(vBC);
#local ca = vlength(vCA);
#local vUp = vcross(vAB, vCA);
#local S = vlength(vUp);
#local abc = ab + bc + ca;
#declare Radius = S/abc;
#declare pCenter = pA + (ca*vAB - ab*vCA)/abc;
#declare vPlane = vUp/S;
#end // macro CircleInscribedInTriangle
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macros for visualizations
#macro vProject(v1, v2)
(v2*vdot(v1, v2)/vdot(v2, v2))
#end // macro vProject
#macro pt2ln(pP, pL, vL)
(pL + vProject(pP - pL, vL))
#end // macro pt2ln
#macro OrientedTorus(Rmaj, Rmin, vAxis)
#local vY = vnormalize(vAxis);
torus {
Rmaj, Rmin
#if (abs(vY.y) != 1)
#local vX = vcross(y, vY);
#local vZ = vcross(vX, vY);
matrix <
vX.x, vX.y, vX.z,
vY.x, vY.y, vY.z,
vZ.x, vZ.y, vZ.z,
0, 0, 0
>
#end // if
}
#end // macro OrientedTorus
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Corners of triangle
#declare pA = <1, 8, 2>;
#declare pB = <-2, -3, 1>;
#declare pC = <-4, 5, -2>;
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Draw triangle
#declare sr = 0.02;
union {
sphere { pA, sr*4 }
sphere { pB, sr*4 }
sphere { pC, sr*4 }
pigment { color Red }
}
union {
cylinder { pA, pB, sr }
cylinder { pB, pC, sr }
cylinder { pC, pA, sr }
pigment { color White }
}
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Calculate data for inscribed circle
#declare pCtr = <0, 0, 0>;
#declare Rad = 0;
#declare vPl = <0, 0, 0>;
CircleInscribedInTriangle(pA, pB, pC, pCtr, Rad, vPl)
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Show circle and the points where it touches the triangle sides
union {
OrientedTorus(Rad, sr, vPl)
sphere { <0, 0, 0>, sr*3 }
translate pCtr
pigment { color White*2 }
}
union {
sphere { pt2ln(pCtr, pA, pB - pA), sr*3 }
sphere { pt2ln(pCtr, pB, pC - pB), sr*3 }
sphere { pt2ln(pCtr, pC, pA - pC), sr*3 }
pigment { color Cyan*2 }
}
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// The photo gear
background { color Blue/2 }
light_source { 100*<-6, -1, 7> color White }
camera {
location 15*vPl
look_at <0, 0, 0>
translate pCtr
}
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Tor Olav Kristensen wrote:
>...
> #macro OrientedTorus(Rmaj, Rmin, vAxis)
>
> #local vY = vnormalize(vAxis);
>
> torus {
> Rmaj, Rmin
> #if (abs(vY.y) != 1)
> #local vX = vcross(y, vY);
> #local vZ = vcross(vX, vY);
> matrix <
> vX.x, vX.y, vX.z,
> vY.x, vY.y, vY.z,
> vZ.x, vZ.y, vZ.z,
> 0, 0, 0
> >
> #end // if
> }
>
> #end // macro OrientedTorus
>...
Ooops !
This line:
#local vX = vcross(y, vY);
should have been:
#local vX = vnormalize(vcross(y, vY));
Sorry about that.
Tor Olav
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|