POV-Ray : Newsgroups : povray.general : Surface from XYZ data Server Time
30 Jul 2024 20:21:52 EDT (-0400)
  Surface from XYZ data (Message 11 to 14 of 14)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Warp
Subject: Re: Surface from XYZ data
Date: 15 Oct 2008 12:12:43
Message: <48f6167b@news.povray.org>
Btw, it would be perfectly possible to create a POV-Ray macro which takes
a 2-dimensional array of 3D points (ie. basically a grid of points) and
which would then generate a smooth surface which goes through all these
points, by creating a bicubic patch for each group of four adjacent points
in the grid. The tangential control points can be easily calculated in such
a way that the resulting group of bicubic patches form a smooth surface
which goes through all the given points.

  I actually once started writing such a macro, but I never finished it.

-- 
                                                          - Warp


Post a reply to this message

From: Dan Connelly
Subject: Re: Surface from XYZ data
Date: 15 Oct 2008 12:25:02
Message: <48f6195e@news.povray.org>
I attempted a calculation of normal vectors for this mesh2 object.
--------------------------------------------
camera {location <0,0,-5> look_at 0}
light_source {<-10,20,-50>, rgb 1}

#declare GridSize = 7;
#declare PointCount = pow(GridSize,2);
#declare NumberOfFaces = 2*pow(GridSize-1,2);
#declare use_normal_vectors = 1;

#declare XCoord =
   array[PointCount] {
     -1.5, -1.0, -0.5, 0,  0.5,   1.0,  1.5,
     -1.5, -1.0, -0.5, 0,  0.5,   1.0,  1.5,
     -1.5, -1.0, -0.5, 0,  0.5,   1.0,  1.5,
     -1.5, -1.0, -0.5, 0,  0.5,   1.0,  1.5,
     -1.5, -1.0, -0.5, 0,  0.5,   1.0,  1.5,
     -1.5, -1.0, -0.5, 0,  0.5,   1.0,  1.5,
     -1.5, -1.0, -0.5, 0,  0.5,   1.0,  1.5
   }

#declare YCoord =
   array[PointCount] {
     -1.5, -1.5, -1.5, -1.5, -1.5,  -1.5, -1.5,
     -1.0, -1.0, -1.0, -1.0, -1.0,  -1.0, -1.0,
     -0.5, -0.5, -0.5, -0.5, -0.5,  -0.5, -0.5,
     0,   0,   0,   0,    0,    0 ,   0,
     0.5,  0.5,  0.5,  0.5,  0.5,   0.5,  0.5,
     1.0,  1.0,  1.0,  1.0,  1.0,   1.0,  1.0,
     1.5,  1.5,  1.5,  1.5,  1.5,   1.5,  1.5
   }

#declare ZCoord =
   array[PointCount] {
     0.7781,  0.9975,  0.6816, 0, -0.6816,  -0.9975, -0.7781,
     0.9975,  0.8415,  0.4794, 0, -0.4794,  -0.8415, -0.9975,
     0.6816,  0.4794,  0.2474, 0, -0.2474,  -0.4794, -0.6816,
     0,       0,       0,      0,       0,  0,       0,
     -0.6816, -0.4794, -0.2474, 0,  0.2474,   0.4794,  0.6816,
     -0.9975, -0.8415, -0.4794, 0,  0.4794,   0.8415,  0.9975,
     -0.7781, -0.9975, -0.6816, 0,  0.6816,   0.9975,   0.7781
   }

mesh2 {
   vertex_vectors {
     PointCount,
     #local I = 0;
     #while (I < PointCount)
       #if (I != PointCount-1)
	<XCoord[I],YCoord[I],ZCoord[I]>,
       #else
	<XCoord[I],YCoord[I],ZCoord[I]>
       #end
       #local I = I + 1;
     #end
   }
   #if (use_normal_vectors)
     normal_vectors {
       PointCount,
       #local I = 0;
       #while (I < GridSize)
	#local I1 = ((I = 0) ? 0 : I - 1);
	#local I2 = ((I = GridSize - 1) ? I : I + 1);

	#local J = 0;
	#while (J < GridSize)
	  #local J1  = ((J = 0) ? 0 : J - 1);
	  #local J2  = ((J = GridSize - 1) ? J : J + 1);

	  #local dx  = XCoord[I2 + J * GridSize] - XCoord[I1 + J * GridSize];
	  #local dy  = YCoord[I + J2 * GridSize] - YCoord[I + J1 * GridSize];
	  #local dzx = ZCoord[I2 + J * GridSize] - ZCoord[I1 + J * GridSize];
	  #local dzy = ZCoord[I + J2 * GridSize] - ZCoord[I + J1 * GridSize];
	  #local vnorm = vnormalize( vcross(<dx, 0, dzx>, <0, dy, dzy>) );
	  #if ((J < GridSize - 1) | (I < GridSize - 1))
	    vnorm,
	  #else
	    vnorm
	  #end
	  #local J = J + 1;
	#end
	#local I = I + 1;
       #end
     }
   #end
   face_indices {
     NumberOfFaces
     #local I = 0;
     #while (I<GridSize-1)
       #local J = 0;
       #while (J<GridSize-1)
	#local K = I*(GridSize)+J;
	<K,K+1,K+GridSize>,
	#if (K!=NumberOfFaces-1)
	  <K+1,K+GridSize+1,K+GridSize>,
	#else
	  <K+1,K+GridSize+1,K+GridSize>
	#end
	#local J = J + 1;
       #end
       #local I = I + 1;
     #end
   }
   pigment {rgb 1}
}


Post a reply to this message

From: Chris B
Subject: Re: Surface from XYZ data
Date: 15 Oct 2008 13:18:06
Message: <48f625ce$1@news.povray.org>
"Dan Connelly" <djc### [at] yahoocom> wrote in message 
news:48f6195e@news.povray.org...
>I attempted a calculation of normal vectors for this mesh2 object.

You just beat me to it :o)

We've both used very similar techniques. I was just investigating some dark 
lines that I get along the edges of the grid and light lines along the 
diagonals of the triangles (I notice you got them too), but I've concluded 
that it's just due to the fact that the z distances are relatively large.

Regards,
Chris B.


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Surface from XYZ data
Date: 15 Oct 2008 19:53:23
Message: <48f68273$1@news.povray.org>
Warp wrote:
>   Btw, it would be perfectly possible to create a POV-Ray macro which takes
> a 2-dimensional array of 3D points (ie. basically a grid of points) and
> which would then generate a smooth surface which goes through all these
> points, by creating a bicubic patch for each group of four adjacent points
> in the grid. The tangential control points can be easily calculated in such
> a way that the resulting group of bicubic patches form a smooth surface
> which goes through all the given points.
> 
>   I actually once started writing such a macro, but I never finished it.

I once made a set of macros that handles this.
Here are some images made with it:

http://home.online.no/~t-o-k/POV-Ray_Images/Bezier_Patches_Torus.jpg
http://home.online.no/~t-o-k/POV-Ray_Images/Bezier_Patches_UV-mapped.jpg
http://home.online.no/~t-o-k/POV-Ray_Images/Bezier_Patchwork.jpg
http://home.online.no/~t-o-k/POV-Ray_Images/Bezier_Patchwork_Ctrl_Grid.jpg
http://home.online.no/~t-o-k/POV-Ray_Images/Bezier_Patchwork_Top_View.jpg
http://home.online.no/~t-o-k/POV-Ray_Images/Bezier_Patches_Stitched.jpg
http://home.online.no/~t-o-k/POV-Ray_Images/Bezier_Patches_Stitched_.jpg

-- 
Tor Olav
http://subcube.com


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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