|
![](/i/fill.gif) |
Since the code is pretty short I thought it would be safe to post here
without starting a flame war.
I was looking at prism objects seriously for the first time yesterday
because this was the first time I thought it would be useful for what I
was trying to make. I realized that I could make a tetrahedron with
it. Not that tetrahedrons actually have anything to do with my current
project. I was just thinking that POV-Ray might handle prisms more
efficiently than plane intersections, because they are finite as opposed
to infinite objects. It takes 4 points anywhere in space, and creates a
tetrahedron there. I was only sidetracked by this idea for about 6
hours. Most of that time was fixing bugs. Anyone know if this approach
is actually faster than plane intersections?
#include "colors.inc"
#include "transforms.inc"
#include "textures.inc"
light_source {<3,4,-5>*100 rgb 2}
camera {location <0,0,-15> look_at 0}
#macro Proj (U,V) // projection of U onto V
((V)*(vdot((U),(V))/vdot((V),(V))))
#end
#macro H2tr(U1,U2,V1,V2) // Here to there rotation... two reference
points for initial and final positions
#local X1 = vnormalize(U1); // find basis vectors
of initial and
#local Z1 = vnormalize(vcross(X1,U2)); // final refrence
frames
#local Y1 = vcross(Z1,X1);
#local X2 = vnormalize(V1);
#local Z2 = vnormalize(vcross(X2,V2));
#local Y2 = vcross(Z2,X2);
#local Trans1 = transform{matrix
<X1.x,Y1.x,Z1.x,X1.y,Y1.y,Z1.y,X1.z,Y1.z,Z1.z,0,0,0>}
#local Trans2 = transform{matrix
<vdot(X2,X1),vdot(X2,Y1),vdot(X2,Z1),vdot(Y2,X1),vdot(Y2,Y1),vdot(Y2,Z1),vdot(Z2,X1),vdot(Z2,Y1),vdot(Z2,Z1),0,0,0>}
#local Trans3 = transform{Trans1 inverse}
#local Rotation = transform {Trans1 Trans2 Trans3}
Rotation
#end
#macro H2t (Oi,Ai,Ri,Of,Af,Rf) // Here to there
transform{
translate (- Oi) // center, and two reference
points on object
H2tr((Ai-Oi),(Ri-Oi),(Af-Of),(Rf-Of)) // New center, and
refrence point locations
translate Of}
#end // (Origin, Absolute vector, Relative vector) initial, and final
orientations
#macro Tet_prism(Vec1,Vec2,Vec3,Vec4)
#local Cross = vcross((Vec2)-(Vec1),(Vec3)-(Vec1));// Find
normal to plane three points are on
#local STP = vdot(Cross,((Vec4)-(Vec1)));// Scalar Triple
Product
#if (STP = 0) #error "degenerate tetrahedron volume = 0" #end
#local Normal = ((STP > 0 ? -1 : 1)*vnormalize(Cross));// sign
corrected normal
#local Basepoint = (Proj(Vec1,Normal));// point on base whose
normal points to Vec4
#local Height = vlength((Basepoint)-(Vec4));// distance between
point 4, and the plane the other three points are on
#local Transform = transform{H2t
(Basepoint,Vec4,Vec1,(Height*y),<0,0,0>,((Height*y)+x)) scale
(1/Height)}
#local V1 = vtransform(Vec1, Transform);
#local V2 = vtransform(Vec2, Transform);
#local V3 = vtransform(Vec3, Transform);
object {
prism {
conic_sweep
linear_spline
0, // sweep the following shape from here ...
1, // ... up through here
4, // the number of points making up the shape ...
<V1.x,V1.z>,<V2.x,V2.z>,<V3.x,V3.z>,<V1.x,V1.z>
transform {Transform inverse}
}//prism
}//object
#end//Tet_prism
object{Tet_prism(<1,1,1>,<-1,1,-1>,<1,-1,-1>,<-1,-1,1>) pigment{Green}}
object{Tet_prism(<1,1,1>,<-1,1,-1>,<-1,1,1>,<-1,6,1>) pigment{Orange}}
//object{Tet_prism(<1,0,0>,<0,0,1>,<-1,0,-1>,<0,5,0>)
pigment{Green}finish {ambient 1}}
--
Dan Johnson
http://www.geocities.com/zapob
Post a reply to this message
|
![](/i/fill.gif) |