POV-Ray : Newsgroups : povray.general : Surface from XYZ data Server Time
5 Nov 2024 05:26:21 EST (-0500)
  Surface from XYZ data (Message 1 to 10 of 14)  
Goto Latest 10 Messages Next 4 Messages >>>
From: New2Povray
Subject: Surface from XYZ data
Date: 14 Oct 2008 14:25:00
Message: <web.48f4e301fc37f40429569840@news.povray.org>
Hi all

I am new to povray and have been trying to render a surface without much
success, the surface could not be mathematically represented (will at least not
in one piece) as a function, but I do have the x, y, and z data. How do I go
about rendering this in povray? Joining up bicubic patch objects should work
but I do have a large number of points, the mesh grid is a square one if that
helps. To give an example, say the following is a portion of the surface I want
to render (a saddle point of Z=sin(X*Y). Could anyone point to to the right
direction or give me some sample code to study?

With thanks

>> X

X =

   -1.5000   -1.0000   -0.5000         0    0.5000    1.0000    1.5000
   -1.5000   -1.0000   -0.5000         0    0.5000    1.0000    1.5000
   -1.5000   -1.0000   -0.5000         0    0.5000    1.0000    1.5000
   -1.5000   -1.0000   -0.5000         0    0.5000    1.0000    1.5000
   -1.5000   -1.0000   -0.5000         0    0.5000    1.0000    1.5000
   -1.5000   -1.0000   -0.5000         0    0.5000    1.0000    1.5000
   -1.5000   -1.0000   -0.5000         0    0.5000    1.0000    1.5000

>> Y

Y =

   -1.5000   -1.5000   -1.5000   -1.5000   -1.5000   -1.5000   -1.5000
   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -0.5000   -0.5000   -0.5000   -0.5000   -0.5000   -0.5000   -0.5000
         0         0         0         0         0         0         0
    0.5000    0.5000    0.5000    0.5000    0.5000    0.5000    0.5000
    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000
    1.5000    1.5000    1.5000    1.5000    1.5000    1.5000    1.5000

>> Z

Z =

    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


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Surface from XYZ data
Date: 14 Oct 2008 16:52:13
Message: <48f5067d$1@news.povray.org>
> success, the surface could not be mathematically represented 

> Z=sin(X*Y).

Looks like a mathematical representation to me. If your
surface is of the form z=f(x,y) it can be rendered as an
height_field object. Note that the function must be
scaled such that z is in the range from 0.0 to 1.0.

height_field
{
   function 512, 512 {0.5+0.5*sin(1.5*x*y)}
   pigment {color White}
   translate -0.5*x
}


Post a reply to this message

From: Tim Attwood
Subject: Re: Surface from XYZ data
Date: 14 Oct 2008 17:23:26
Message: <48f50dce$1@news.povray.org>
> I am new to povray and have been trying to render a surface without much
> success, the surface could not be mathematically represented (will at 
> least not
> in one piece) as a function, but I do have the x, y, and z data. How do I 
> go
> about rendering this in povray? Joining up bicubic patch objects should 
> work
> but I do have a large number of points, the mesh grid is a square one if 
> that
> helps. To give an example, say the following is a portion of the surface I 
> want
> to render (a saddle point of Z=sin(X*Y). Could anyone point to to the 
> right
> direction or give me some sample code to study?

#version 3.6;

#include "colors.inc"
#include "finish.inc"

global_settings {
  assumed_gamma 1.0
}

// --- camera, lights & 
background ------------------------------------------
camera {
   location  <0.0, 0.5, -4.0>
   direction 1.5*z
   right     x*image_width/image_height
   look_at   <0.0, 0.0,  0.0>
}
sky_sphere {
  pigment {
    gradient y
    color_map {
       [0.0 Red]
       [0.5 Red]
       [0.5 White]
       [1.0 White]
    }
    scale 0.05
  }
}
light_source {
  <-30, 30, -30>
  color rgb <1, 1, 1>
}

// ---  
macros ---------------------------------------------------------------
#declare XYZdata = array [49]
   {<-1.5,-1.5, 0.7781>,<-1,-1.5, 0.9975>,<-0.5,-1.5, 0.6816>,<0,-1.5, 0>,
    <0.5,-1.5, -0.6816>, <1.0,-1.5,-0.9975>,<1.5,-1.5, -0.7781>,
    <-1.5,-1.0, 0.9975>,<-1,-1.0, 0.8415>,<-0.5,-1.0, 0.4794>,<0,-1.0, 0>,
    <0.5,-1.0, -0.4794>, <1.0,-1.0,-0.8415>,<1.5,-1.0, -0.9975>,
    <-1.5,-0.5, 0.6816>,<-1,-0.5, 0.4794>,<-0.5,-0.5, 0.2474>,<0,-0.5, 0>,
    <0.5,-0.5, -0.2474>, <1.0,-0.5,-0.4794>,<1.5,-0.5, -0.6816>,
    <-1.5,0,0>,<-1,0,0>,<-0.5,0,0>,<0,0,0>,<0.5,0,0>, <1.0,0,0>,<1.5,0,0>,
    <-1.5,0.5,-0.6816>,<-1,0.5,-0.4794>,<-0.5,0.5,-0.2474>,<0,0.5, 0>,
    <0.5,0.5,0.2474>, <1.0,0.5,0.4794>,<1.5,0.5,0.6816>,
    <-1.5,1,-0.9975>,<-1,1,-0.8415>,<-0.5,1,-0.4794>,<0,1,0>,<0.5,1,0.4794>,
    <1.0,1, 0.8415>,<1.5,1,  0.9975>,
    <-1.5,1.5,-0.7781>,<-1,1.5,-0.9975>,<-0.5,1.5,-0.6816>,<0,1.5, 0>,
    <0.5,1.5,0.6816>, <1.0,1.5, 0.9975>,<1.5,1.5,0.7781>};

#macro point_cloud(A, r)
   #local _pce = dimension_size(A,1);
   #local c = 0;
   #while (c<_pce)
      sphere{A[c],r}
      #local c=c+1;
   #end
#end

// ---  
scene ----------------------------------------------------------------

union {
   point_cloud(XYZdata,0.05)
   texture {pigment {White} finish {Dull}}
   scale 0.5
}

parametric {
   function { u },        // x-axis
   function { v },        // y-axis
   function { sin(u*v) }  // z-axis
   <-1.5,-1.5>, <1.5,1.5> // <u1,v1>, <u2,v2> limits
   contained_by { box { -1.5, 1.5 } }
   accuracy 0.005
   precompute 15 x,y,z
   texture {pigment {Blue}}
   scale 0.5
}


Post a reply to this message

From: New2Povray
Subject: Re: Surface from XYZ data
Date: 14 Oct 2008 17:25:01
Message: <web.48f50dae825a59e12d75b4a20@news.povray.org>
Dear Christian

Thankyou for your help, the Z=sin(X*Y) is for illustrative purposes only. The
data is from an experiment and does not fit to any function because of the
noise, and has several discontinuous points, I could roughly fit each separate
patch as a bessel function of the second kind but I would like to plot the
origin data, not approximate ones.

Any other suggestions? Thanks in advance.


Post a reply to this message

From: Chris B
Subject: Re: Surface from XYZ data
Date: 14 Oct 2008 17:48:21
Message: <48f513a5$1@news.povray.org>
"New2Povray" <nomail@nomail> wrote in message 
news:web.48f4e301fc37f40429569840@news.povray.org...
> Hi all
>
> I am new to povray and have been trying to render a surface without much
> success,

Hi and Welcome.

> the surface could not be mathematically represented (will at least not
> in one piece) as a function,

I'll take your word for it :o)

The example pasted in below my signature illustrates one approach that you 
could quite easily use. I transformed your data into POV-Ray arrays, then 
used those arrays to build a POV-Ray mesh2 object. Transforming your data in 
this way is quite simple using an editor that supports columnar editing, 
such as the POV-Ray Windows editor. ie. to insert the commas you can click 
in the gap between two numbers in the top line, ctrl-shift-click in the 
corresponding position on the bottom line and type a comma. (repeat 7 times, 
once for each gap).

This example isn't smoothed and smoothing would require an extra chunk of 
code to calculate the mesh normals.

Alternatively you may wish to take a look at Mike Williams' excellent 
isosurface tutorial which provides a number of ways of combining functions 
(see http://www.econym.demon.co.uk/isotut/). You may find that you can 
programmatically 'chop' your different functions together.

If your full dataset follows a grid in the way this data does, you might 
want to consider writing the z values as a bitmap then using the image as a 
height field.

Regards,
Chris B.

// Example...

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 XCoord = array[PointCount] {

   -1.5000 , -1.0000 , -0.5000 ,       0  ,  0.5000 ,   1.0000  ,  1.5000 ,
   -1.5000 , -1.0000 , -0.5000 ,       0  ,  0.5000 ,   1.0000  ,  1.5000 ,
   -1.5000 , -1.0000 , -0.5000 ,       0  ,  0.5000 ,   1.0000  ,  1.5000 ,
   -1.5000 , -1.0000 , -0.5000 ,       0  ,  0.5000 ,   1.0000  ,  1.5000 ,
   -1.5000 , -1.0000 , -0.5000 ,       0  ,  0.5000 ,   1.0000  ,  1.5000 ,
   -1.5000 , -1.0000 , -0.5000 ,       0  ,  0.5000 ,   1.0000  ,  1.5000 ,
   -1.5000 , -1.0000 , -0.5000 ,       0  ,  0.5000 ,   1.0000  ,  1.5000 }

#declare YCoord = array[PointCount] {
   -1.5000 , -1.5000 , -1.5000 , -1.5000  , -1.5000 ,  -1.5000  , -1.5000 ,
   -1.0000 , -1.0000 , -1.0000 , -1.0000  , -1.0000 ,  -1.0000  , -1.0000 ,
   -0.5000 , -0.5000 , -0.5000 , -0.5000  , -0.5000 ,  -0.5000  , -0.5000 ,
         0 ,       0 ,       0 ,       0  ,       0 ,        0  ,       0 ,
    0.5000 ,  0.5000 ,  0.5000 ,  0.5000  ,  0.5000 ,   0.5000  ,  0.5000 ,
    1.0000 ,  1.0000 ,  1.0000 ,  1.0000  ,  1.0000 ,   1.0000  ,  1.0000 ,
    1.5000 ,  1.5000 ,  1.5000 ,  1.5000  ,  1.5000 ,   1.5000  ,  1.5000 }

#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
  }
  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: New2Povray
Subject: Re: Surface from XYZ data
Date: 14 Oct 2008 18:05:00
Message: <web.48f516cf825a59e12d75b4a20@news.povray.org>
Dear Christian

Thankyou for your help. The Z=sin(X*Y) function is for illustrative purposes
only and is not what I would like to plot. I can't fit a function to my
experimental data because of the noise - it can be approximated by a series of
Bessel functions of the second kind, but I would like to render the original
unaltered data only. I guess a way to do this as you hinted - is to output the
data as an image file from another program and use the pixel height to render
the surface. Though I would still like to know if there is another straight
forward way to render surfaces!

Cheers





Christian Froeschlin <chr### [at] chrfrde> wrote:
> > success, the surface could not be mathematically represented
>
> > Z=sin(X*Y).
>
> Looks like a mathematical representation to me. If your
> surface is of the form z=f(x,y) it can be rendered as an
> height_field object. Note that the function must be
> scaled such that z is in the range from 0.0 to 1.0.
>
> height_field
> {
>    function 512, 512 {0.5+0.5*sin(1.5*x*y)}
>    pigment {color White}
>    translate -0.5*x
> }


Post a reply to this message

From: New2Povray
Subject: Re: Surface from XYZ data
Date: 14 Oct 2008 19:00:00
Message: <web.48f52341825a59e16cefaa570@news.povray.org>
Hi Tim and Chris (and everyone else)

A massive thank you for everyone's help! I didn't notice there was a delay
between posting and messages appearing so I double posted, another true newbie
mistake. All solutions worked perfectly.

I have to admit, Povray is pretty addictive even after using it only for a day.


Post a reply to this message

From: Dan Connelly
Subject: Re: Surface from XYZ data
Date: 15 Oct 2008 09:19:45
Message: <48f5edf1@news.povray.org>
Chris B wrote:

> The example pasted in below my signature illustrates one approach that 
> you could quite easily use. I transformed your data into POV-Ray arrays, 
> then used those arrays to build a POV-Ray mesh2 object. Transforming 
> your data in this way is quite simple using an editor that supports 
> columnar editing, such as the POV-Ray Windows editor. ie. to insert the 
> commas you can click in the gap between two numbers in the top line, 
> ctrl-shift-click in the corresponding position on the bottom line and 
> type a comma. (repeat 7 times, once for each gap).
> 
> This example isn't smoothed and smoothing would require an extra chunk 
> of code to calculate the mesh normals.
> 

Very nice!

Couldn't one also use bicupic patches to attain smoothness?  I've not had luck with
them yet.  If I get time, I'll put together an example of where I have had trouble.

Dan


Post a reply to this message

From: Chris B
Subject: Re: Surface from XYZ data
Date: 15 Oct 2008 11:26:32
Message: <48f60ba8$1@news.povray.org>
"Dan Connelly" <djc### [at] yahoocom> wrote in message 
news:48f5edf1@news.povray.org...
> Chris B wrote:
>
>> The example pasted in below my signature illustrates one approach that 
>> you could quite easily use. I transformed your data into POV-Ray arrays, 
>> then used those arrays to build a POV-Ray mesh2 object.
>
> Couldn't one also use bicupic patches to attain smoothness?  I've not had 
> luck with them yet.  If I get time, I'll put together an example of where 
> I have had trouble.
>

I might be wrong (I've never used bicubic patches), but the documentation 
says that POV-Ray supports Bezier patches which, I think, means that you'd 
have to calculate a large number of Bezier control points that don't sit on 
the original curved surface. I'd guess that this would be quite tricky.

Regards,
Chris B.


Post a reply to this message

From: Warp
Subject: Re: Surface from XYZ data
Date: 15 Oct 2008 12:08:56
Message: <48f61598@news.povray.org>
Chris B <nom### [at] nomailcom> wrote:
> I might be wrong (I've never used bicubic patches), but the documentation 
> says that POV-Ray supports Bezier patches which, I think, means that you'd 
> have to calculate a large number of Bezier control points that don't sit on 
> the original curved surface. I'd guess that this would be quite tricky.

  Creating a bicubic patch which follows a given surface is not that hard.
The principle is rather simple:

- The four corner points sit on the original surface.

- Each corner point and an adjacent edge point of the bicubic patch define
  a line which is tangential to the surface at the location of the corner
  point.

- The four middle points work in the same way with their respective edge
  points, ie. they define the tangent vector of the surface at the edge point
  (although the generated surface doesn't necessarily go through this edge
  point).

- The only tricky thing is calculating the proper distance between corner
  points and their respective edge points, and the distance between the edge
  points and their respective center points. If I'm not mistaken, this
  distance is defined by the curvature of the surface at the corner point
  (or edge point in the latter case), ie. its second derivative.

  However, I think that in most cases it's enough to distribute all the
  points at (about) equal distances from each other. The possible error
  introduced by this probably isn't very large.

  This also gives the method for joining bicugic patches smoothly. Since
we know that the edge and center control points define the tangent of the
surface with their respective corner/edge points, adjacent bicubic patces
should have the same tangent direction at the shared control points.

-- 
                                                          - Warp


Post a reply to this message

Goto Latest 10 Messages Next 4 Messages >>>

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