POV-Ray : Newsgroups : povray.advanced-users : Getting data out of a mesh2 Server Time
24 Nov 2024 12:56:30 EST (-0500)
  Getting data out of a mesh2 (Message 1 to 5 of 5)  
From: David Wallace
Subject: Getting data out of a mesh2
Date: 31 Jan 2007 20:09:45
Message: <45c13dd9@news.povray.org>
I want to join Archimedian mesh2 objects precisely to one another (think 
  Magnetix).  Is there a way to fish normal and vertex data out of a 
declared mesh2 given a face index or will I have to create a separate 
vertex array?

Is there a variant of ReorientCenter that takes 6 points, 3 from one 
triangle and three from the other, that will line up the first triangle 
to exactly fit the other?

#macro ReorientTriangle(p1,p2,p3,p4,p5,p6)
   #local tr1 = transform { matrix <p1.x,p1.y,p1.z, p2.x,p2.y,p2.z, 
p3.x,p3.y,p3.z, 0,0,0> inverse }
   #local tr2 = transform { matrix <p4.x,p4.y,p4.z, p5.x,p5.y,p5.z, 
p6.x,p6.y,p6.z, 0,0,0> }
   transform tr1
   transform tr2
#end

// Tetrahedron (Tetrad)
#declare aTetrad = sqrt(2);

#declare Tetrad = mesh2 {
	vertex_vectors { 4,
		<-.5, -.5, -.5>,
		<0.5, -.5, 0.5>,
		<-.5, 0.5, 0.5>,
		<0.5, 0.5, -.5>
	}
	face_indices { 4,
		<0,1,2>,<0,2,3>,<0,3,1>,<3,2,1>
	}
	//Reorient(<-1,-1,-1>,y)
}

#declare vTetrad = array[4] {
	<-.5, -.5, -.5>,
	<0.5, -.5, 0.5>,
	<-.5, 0.5, 0.5>,
	<0.5, 0.5, -.5>
}

// Cuboctahedron (Cuboct)
#declare aCuboct = sqrt(0.5);

#declare Cuboct = mesh2 {
	vertex_vectors { 18,
		<0,-0.5,-0.5>,
		<0, 0.5,-0.5>,
		<0,-0.5, 0.5>,
		<0, 0.5, 0.5>,
		<-0.5, 0,-0.5>,
		< 0.5, 0,-0.5>,
		<-0.5, 0, 0.5>,
		< 0.5, 0, 0.5>,
		<-0.5,-0.5, 0>,
		< 0.5,-0.5, 0>,
		<-0.5, 0.5, 0>,
		< 0.5, 0.5, 0>,
		<-0.5, 0.0, 0.0>,
		< 0.5, 0.0, 0.0>,
		< 0.0,-0.5, 0.0>,
		< 0.0, 0.5, 0.0>,
		< 0.0, 0.0,-0.5>,
		< 0.0, 0.0, 0.5>
	}
	face_indices { 32,
		<8,4,0>,<1,4,10>,<11,5,1>,<0,5,9>,
		<2,6,8>,<9,7,2>,<3,7,11>,<10,6,3>,
		<4,8,12>,<8,6,12>,<6,10,12>,<10,4,12>,
		<9,5,13>,<7,9,13>,<11,7,13>,<5,11,13>,
		<0,8,14>,<8,2,14>,<2,9,14>,<9,0,14>,
		<10,1,15>,<3,10,15>,<11,3,15>,<1,11,15>,
		<0,4,16>,<4,1,16>,<1,5,16>,<5,0,16>,
		<6,2,17>,<3,6,17>,<7,3,17>,<2,7,17>,
	}
}

#declare vCuboct = array[18] {
	<0,-0.5,-0.5>,
	<0, 0.5,-0.5>,
	<0,-0.5, 0.5>,
	<0, 0.5, 0.5>,
	<-0.5, 0,-0.5>,
	< 0.5, 0,-0.5>,
	<-0.5, 0, 0.5>,
	< 0.5, 0, 0.5>,
	<-0.5,-0.5, 0>,
	< 0.5,-0.5, 0>,
	<-0.5, 0.5, 0>,
	< 0.5, 0.5, 0>,
	<-0.5, 0.0, 0.0>,
	< 0.5, 0.0, 0.0>,
	< 0.0,-0.5, 0.0>,
	< 0.0, 0.5, 0.0>,
	< 0.0, 0.0,-0.5>,
	< 0.0, 0.0, 0.5>
}

#declare _aspect = image_width/image_height;

light_source { x*50, rgb <1,0,0> }
light_source { y*50, rgb <0,1,0> }
light_source { z*50, rgb <0,0,1> }

camera {
   location <-2.0, 2.0, 0.0>
   look_at <0.0, 0.0,  0.0>
   rotate  y*20
}

object { Cuboct scale 1 pigment { rgb 1 } }
object { Tetrad
   ReorientTriangle( 
vTetrad[0],vTetrad[2],vTetrad[1],vCuboct[1],vCuboct[4],vCuboct[10] )
   pigment { rgb 0.75 }
}

I tested this and got an unexpected result... the fourth point in the 
tetrahedron is way off course while the first three points are spot on. 
  I need a set of translations and rotations that have the normals 
facing each other, the face centers and first points matching.

Ideas are welcome.


Post a reply to this message

From: Tim Attwood
Subject: Re: Getting data out of a mesh2
Date: 31 Jan 2007 23:09:59
Message: <45c16817$1@news.povray.org>
This should put the center of two triangles
together by moving one to the origin,
rotating with Reorient_Trans, then moving
it to the other triangles center.

#include "transforms.inc"
#macro Normal_Of_Triangle(A, B, C)
  vnormalize(vcross(B-A,C-A))
#end
#macro Center_Of_Triangle(A, B, C)
  ((A+B+C)/3)
#end
#macro Align_By_Triangles(A,B,C,D,E,F)
   translate -Center_Of_Triangle(A, B, C)
   Reorient_Trans(Normal_Of_Triangle(A, B, C),
      Normal_Of_Triangle(D, E, F))
   translate Center_Of_Triangle(D, E, F)
#end


Post a reply to this message

From: Warp
Subject: Re: Getting data out of a mesh2
Date: 1 Feb 2007 04:47:09
Message: <45c1b71d@news.povray.org>
David Wallace <dar### [at] earthlinknet> wrote:
> Is there a way to fish normal and vertex data out of a 
> declared mesh2 given a face index or will I have to create a separate 
> vertex array?

  Currently no.

  You could, however, convert the mesh2 into another format which is
easy to parse from pov SDL.
  The current public version of my mesh compressor doesn't support mesh2,
but you can read about it here:
http://www.geocities.com/ccolefax/pcm.html

  A beta version supporting mesh2 exists, though:
http://warp.povusers.org/WinMeshcomp30_beta3.zip

  There are no macros to read the new formats, but the file format is
very simple and easily readable from your own SDL code.

-- 
                                                          - Warp


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Getting data out of a mesh2
Date: 21 Feb 2007 19:14:57
Message: <45dce081$1@news.povray.org>
David Wallace wrote:
...
> Is there a variant of ReorientCenter that takes 6 points, 3 from one 
> triangle and three from the other, that will line up the first triangle 
> to exactly fit the other?
> 
> #macro ReorientTriangle(p1,p2,p3,p4,p5,p6)
>   #local tr1 = transform { matrix <p1.x,p1.y,p1.z, p2.x,p2.y,p2.z, 
> p3.x,p3.y,p3.z, 0,0,0> inverse }
>   #local tr2 = transform { matrix <p4.x,p4.y,p4.z, p5.x,p5.y,p5.z, 
> p6.x,p6.y,p6.z, 0,0,0> }
>   transform tr1
>   transform tr2
> #end
...
> I tested this and got an unexpected result... the fourth point in the 
> tetrahedron is way off course while the first three points are spot on. 
>  I need a set of translations and rotations that have the normals facing 
> each other, the face centers and first points matching.
> 
> Ideas are welcome.

This thread might be relevant for you:

http://news.povray.org/povray.text.tutorials/thread/%3C3D9B843D.E5392CD0%40hotmail.com%3E/
http://tinyurl.com/2h3kge
"How to transform a triangle into another"
Posted by me 2nd October 2002 to povray.text.tutorials

IIRC the Triangle2Triangle_Trans() macro should preserve
normals to the triangle.

(If you try that macro, remember to apply the corrections
in my follow-up post 12 minutes later.)

You'll also find a macro there that will transform a
tetrahedron into another: Pyramid2Pyramid_Trans()

-- 
Tor Olav
http://subcube.com


Post a reply to this message

From: Stephen Klebs
Subject: Re: Getting data out of a mesh2
Date: 22 Feb 2007 12:20:01
Message: <web.45ddd03ce66b4216977978930@news.povray.org>
I wrote these macros ages ago as a kind of poor-man's uv-map. They basically
fit one triangle to another in 3D space. Hope they work for you.

/* -------------------- Fit Macro -------------------------------

   Macro takes 6 vectors: 3 points (P1, P2, P3) on object to move, P;
   3 points (Q1, Q2, Q3) for position to move it to.

  There are two versions of this macro. The rotation method is slower but
  more precise than the matrix formula derived from John van Sickle.
*/

/*------------- [1] Rotation Method ------------------*/
#macro Normal (V1, V2, V3) vcross(V2-V1, V3-V1); #end

#macro XAngle (X, Y)
 #local q = sqrt((X*X) + (Y*Y));
  #if (q = 0)
    #local aX = 0;
  #else
    #local aX = acos(X / q);
  #end
  #if (Y < 0)
    #local aX = (2*pi) - aX;
  #end
  aX
#end

#macro Fit1 (P1, P2, P3, Q1, Q2, Q3)
  #local deg = 180/pi;
  #local nP = Normal (P1, P2, P3)
  #local nQ = Normal (Q1, Q2, Q3)

  //----- Translate to Origin -------
  #local tP = -P1;
  #local tQ = -Q1;
  #local P2 = P2 + tP;
  #local Q2 = Q2 + tQ;

  //--------- Rotate Y------------
  #local aP = XAngle(nP.x, nP.z) * deg;
  #local aQ = XAngle(nQ.x, nQ.z) * deg;
  #local nP = vaxis_rotate(nP, y, aP);
  #local nQ = vaxis_rotate(nQ, y, aQ);
  #local P2 = vaxis_rotate(P2, y, aP);
  #local Q2 = vaxis_rotate(Q2, y, aQ);

  //---------- Rotate Z-----------
  #local bP = -XAngle(nP.x, nP.y) * deg;
  #local bQ = -XAngle(nQ.x, nQ.y) * deg;
  #local P2 = vaxis_rotate(P2, z, bP);
  #local Q2 = vaxis_rotate(Q2, z, bQ);

  //---------- Rotate X-----------
  #local XAngleP = XAngle(P2.z, P2.y) * deg;
  #local XAngleQ = XAngle(Q2.z, Q2.y) * deg;
  #local cQ = -(XAngleQ - XAngleP);

  translate  tP
  rotate     aP*y
  rotate     bP*z
  rotate     cQ*x
  rotate    -bQ*z
  rotate    -aQ*y
  translate -tQ
#end

/*------------- [2] Matrix Method ------------------*/
#macro Fit2 (pA, pB, pC, pD, pE, pF)
  #local vXa = (pB-(pA));
  #local vYa = (pC-(pA));
  #local vZa = vcross(vXa, vYa);

  #local vXb = (pE-(pD));
  #local vYb = (pF-(pD));
  #local vZb = vcross(vXb, vYb);

  #local sDET = vdot(vZa,vcross(vXa,vYa));

  //-- Values for the inverted matrix:
  #local vCX = vcross(vYa, vZa)/sDET;
  #local vCY = vcross(vZa, vXa)/sDET;
  #local vCZ = vcross(vXa, vYa)/sDET;

  // These two steps take the triangle at (A,B,C) and move it to
(<0,0,0>,x,y).
  translate -(pA)
  matrix < vCX.x, vCY.x, vCZ.x,
           vCX.y, vCY.y, vCZ.y,
           vCX.z, vCY.z, vCZ.z,
               0,     0,     0 >

  // This matrix takes the triangle at (<0,0,0>,x,y) and moves it to
(D,E,F).
  matrix < vXb.x, vXb.y, vXb.z,
           vYb.x, vYb.y, vYb.z,
           vZb.x, vZb.y, vZb.z,
            pD.x,  pD.y,  pD.z >
#end

/*---------------------------------------------------------------*/
#macro Fit (P1, P2, P3, Q1, Q2, Q3)
  Fit1 (P1, P2, P3, Q1, Q2, Q3)
#end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.