|
|
"Luc H." <nomail@nomail> wrote:
> Hello
>
Luc,
This must be a solved problem, since it amounts to forming a tetrahedron given
the edge lengths, however...
What follows puts the initial triangle onto the x-y plane to make the geometry
easier. If it is something like what you want, I'll put it into vector form for
a general triangle orientation,
Jim
global_settings { ambient_light 4 }
//
#include "colors.inc"
//
#macro draw_axes (aT,aRad,xMin,xMax,yMin,yMax,zMin,zMax)
object{
union{
cylinder{ <xMin,0,0>, <xMax,0,0>, aRad }
cone { <xMax,0,0>, 3*aRad, <xMax+8*aRad,0,0>, 0 }
cylinder{ <0,yMin,0>, <0,yMax,0>, aRad }
cone { <0,yMax,0>, 3*aRad, <0,yMax+8*aRad,0>, 0 }
cylinder{ <0,0,zMin>, <0,0,zMax>, aRad }
cone { <0,0,zMax>, 3*aRad, <0,0,zMax+8*aRad>, 0 }
}
texture{ aT }
}
#end
//
//Draw the axes
//
#declare xMin = -5;
#declare xMax = 5;
#declare yMin = -5;
#declare yMax = 5;
#declare zMin = -5;
#declare zMax = 5;
#declare aT = texture{ pigment { Black } }
#declare aRad = 0.05;
//
draw_axes (aT,aRad,xMin,xMax,yMin,yMax,zMin,zMax)
//
#macro tetrahedron(cRad,srad,p1,p2,p3,p4,d1,d2,d3)
//
union{
// Find the side lengths of the initial triangle
#local d12 = vlength(p2-p1);
#local d23 = vlength(p3-p2);
#local d31 = vlength(p1-p3);
// Set the trial triangle on the x-y plane
#local pp1 = <0,0,0>;
#local pp2 = <d12,0,0>;
#local x3 = (d12*d12+d31*d31-d23*d23)/(2*d12);
#local y3 = sqrt(d31*d31-x3*x3);
#local pp3 = <x3,y3,0>;
// Trial triangle vertices
sphere{pp1 srad texture{pigment{Red}}}
sphere{pp2 srad texture{pigment{Red}}}
sphere{pp3 srad texture{pigment{Red}}}
// Joining trial triangle vertices
cylinder{pp1 pp2 cRad texture{pigment{Blue}}}
cylinder{pp2 pp3 cRad texture{pigment{Blue}}}
cylinder{pp3 pp1 cRad texture{pigment{Blue}}}
// Trial triangle
triangle{ pp1 pp2 pp3 texture{hT} }
// Calculating fourth vertex
// Start off working on the p1-p2-p4 triangle placed on the x-y plane
#local d = (d12*d12+d1*d1-d2*d2)/(2*d12);
#if(d>0)
sphere{<0,0,-5> 0.5 pigment{Green}}
#local h = d1*d1-d*d;
#if(h>0)
sphere{<0,0,-4> 0.5 pigment{Green}}
#local h = sqrt(h);
#local costh = (d3*d3 - (x3-d)*(x3-d) - y3*y3 - h*h)/(2*y3*h);
#local sinth = 1 - costh*costh;
#if(sinth > 0)
sphere{<0,0,-3> 0.5 pigment{Green}}
#local sinth = sqrt(sinth);
#local pp4 = <d,-h*costh,h*sinth>;
#else
sphere{<0,0,-3> 0.5 pigment{Red}}
#local pp4 = <0,0,0>;
#end
#else
sphere{<0,0,-4> 0.5 pigment{Red}}
#local pp4 = <0,0,0>;
#end
#else
sphere{<0,0,-5> 0.5 pigment{Red}}
#local pp4 = <0,0,0>;
#end
//
#if(abs(vlength(pp1-pp4)-d1)<(d1/10000000))
sphere{ pp4 srad texture{pigment{Red}}}
cylinder{pp1 pp4 cRad texture{pigment{Blue}}}
cylinder{pp2 pp4 cRad texture{pigment{Blue}}}
cylinder{pp3 pp4 cRad texture{pigment{Blue}}}
triangle{pp1 pp2 pp4 texture{hT}}
triangle{pp2 pp3 pp4 texture{hT}}
triangle{pp3 pp1 pp4 texture{hT}}
#end
// End of main union
}
//
#end
//
// Joining line and vertex radii
//
#declare cRad = 0.05;
#declare sRad = 0.08;
//
// Joining line, convex hull and spline textures.
//
#declare cT = texture{ pigment { rgb<0,0,1> } } //Blue
#declare hT = texture{ pigment { rgbf<1,1,0,0.9> } } //Transparent yellow
#declare sT = texture{ pigment { rgb<0,1,0> } } //Green
//
// Vertex definitions
//
#declare p1 = <0, 0 ,0>;
#declare p2 = <4, 0 ,0>;
#declare p3 = <2,3.46,0>;
#declare p4 = <0, 0 ,0>;
//
// Side lengths
//
#declare d1 = 4;
#declare d2 = 4;
#declare d3 = 4;
//
tetrahedron(cRad,sRad,p1,p2,p3,p4,d1,d2,d3)
//
background {color White}
light_source { <20,20,20> White shadowless}
camera{orthographic location <20,6,4> look_at <0,0,0> }
Post a reply to this message
|
|