Moving Objects in POV-Ray

182 Views Asked by At

I´m looking for a way to move objects in POV-Ray. Let´s say, I got $n$ Points in 3D. They are all in one plane. Now I want to create a bodie with the shape of the points as its base and a given hight. At first I need to generate the shape in the origin, but I don´t know how to find the rotation and translation from there to move the object through my original points. Hope, someone can help.

Thanks in advance

Edit

For example: $A(1,1,1)$, $B(2,2,2)$ and $C(-1,-1,0)$ create a triangle. Now I want to create a prism by giving the triangle a height of $2$. In POV-Ray (as I understand) I need to generate the triangle in 2D, then give it a height, so its always "standing" on the $xy$-plane. And then I need to find a movement to bring the body back through its original points.

sketch

enter image description here

1

There are 1 best solutions below

2
On BEST ANSWER
  1. Given three non-collinear points $A,B,C$, make three orthogonal vectors: one is in the normal direction wrt the plane through $A,B,C$, and the other two must belong to that plane. Note that you need to take care of the sign of the normal.

  2. Prepare a transformation matrix, which would transform this orthogonal triple into $X,Y,Z$ at the origin.

  3. Transform vectors $A,B,C$ into $A_0,B_0,C_0$, which would then be located in $XZ$-plane.

  4. Use $x$ and $z$ coordinates of $A_0,B_0,C_0$ to construct the boundary of the prism object.

  5. Add the inverse transform at the end of the prism object to move it back.

Fortunately, POV-Ray already has convenient macros that make this procedure straightforward.

// -w800 -h600 +a0.3
#version 3.7;
global_settings { assumed_gamma 1.2 }
#include "colors.inc"
#include "transforms.inc"
background{White}
 
#local h=1;
#local A=<2,0,0>;
#local B=<0,3,0>; 
#local C=<0,0,4>;

#local O=(A+B+C)/3;
#local N=-vcross(B-O,C-O);

camera {
  orthographic                 
  location A+2*N
  look_at O
}
light_source { A+20*N color White }
light_source { B+20*N color White }

#local X1=vnormalize(A-O);
#local Y1=N;
#local Z1=vcross(vnormalize(A-O),N);

#local T=transform{Matrix_Trans(X1, Y1, Z1, O)};
#local invT=transform{T inverse};

#local A0=vtransform(A, invT);
#local B0=vtransform(B, invT);
#local C0=vtransform(C, invT);

prism {
  linear_sweep
  linear_spline
  0, // sweep the following shape from here ...
  h, // ... up through here
  4, // the number of points making up the shape ...
  <A0.x,A0.z>, <B0.x,B0.z>, <C0.x,C0.z>, <A0.x,A0.z>
  texture{pigment { color rgbt<0,1,0,0.1> } finish{diffuse 0.1}}
  transform{T}
}

sphere{A,0.1 pigment { color rgb<1,0,0> }}
sphere{B,0.1 pigment { color rgb<0,1,0> }}
sphere{C,0.1 pigment { color rgb<0,0,1> }}
sphere{O,0.2 pigment { color rgb<0,1,1> }}

sphere{A+h*N,0.1 pigment { color rgb<1,0,0> }}
sphere{B+h*N,0.1 pigment { color rgb<0,1,0> }}
sphere{C+h*N,0.1 pigment { color rgb<0,0,1> }}
sphere{O+h*N,0.2 pigment { color rgb<0,1,1> }}

enter image description here

This procedure can an easily adjusted to handle an arrays of $n$ points:

// -w800 -h600 +a0.3
#version 3.7;
global_settings { assumed_gamma 2.0 }
#include "colors.inc"
#include "metals.inc"
#include "transforms.inc"
background{White}
 
#local h=1;
#local A=<2,0,0>;
#local B=<0,3,0>; 
#local C=<0,0,4>;
#local D=<1/2.25,4/3,4/3>;

#local O=(A+B+C)/3;
#local N=-vcross(B-O,C-O);

camera {
  orthographic                 
  location A+2*N
  look_at O
}
light_source { A+20*N color White*0.3 }
light_source { B+20*N color White*0.2 }

#local X1=vnormalize(A-O);
#local Y1=N;
#local Z1=vcross(vnormalize(A-O),N);

#local T=transform{Matrix_Trans(X1, Y1, Z1, O)};
#local invT=transform{T inverse};

#local n=4;  
#local P=array[n]{A,B,C,D};
#local P0=array[n];

#local i=0;  
#while(i<n)
  #local P0[i]=vtransform(P[i], invT);
  #local i=i+1;  
#end

prism {
  linear_sweep
  linear_spline
  -h/2, // sweep the following shape from here ...
  h/2, // ... up through here
  n+1, // the number of points making up the shape ...
  #local i=0;  
  #while(i<n)
    <P0[i].x,P0[i].z>,
    #local i=i+1;  
  #end
  <P0[0].x,P0[0].z>
  texture{pigment { color rgb<0,1,0> } finish{F_MetalB}}
  transform{T}
}

  #local i=0;  
  #while(i<n)
    sphere{P[i]+h/2*N,0.1 pigment { color rgb vnormalize(P[i]) } finish{F_MetalB}}
    #local i=i+1;  
  #end

enter image description here