POV-Ray : Newsgroups : povray.general : How to ... Server Time
18 Apr 2024 10:10:12 EDT (-0400)
  How to ... (Message 14 to 23 of 23)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Bald Eagle
Subject: Re: How to ...
Date: 27 Nov 2021 14:20:00
Message: <web.61a28494d5fe89401f9dae3025979125@news.povray.org>
Cousin Ricky <ric### [at] yahoocom> wrote:

> You might consider turning off format=flowed in your Thunderbird
> settings.  It messes up your diagrams in the Web view.

Huh.
They display perfectly on my system.
Using Brave browser...


Post a reply to this message

From: Bald Eagle
Subject: Re: How to ...
Date: 27 Nov 2021 16:45:00
Message: <web.61a2a5e2d5fe89401f9dae3025979125@news.povray.org>
I edited my file to read an nxm set of vertices and colors from a file and make
a mesh2{} object with all the normals and textures.  This was as smooth as I
could get it on short notice.

Mixing triangles and arrays and POV-Ray's cranky insistence on proper syntax is
enough to drive me mad.   ;)


I hope you're making good progress.


Post a reply to this message


Attachments:
Download 'datasetsurface.png' (96 KB)

Preview of image 'datasetsurface.png'
datasetsurface.png


 

From: BayashiPascal
Subject: Re: How to ...
Date: 27 Nov 2021 22:10:00
Message: <web.61a2f0edd5fe8940c7449d78e0f8c582@news.povray.org>
kurtz le pirate <kur### [at] gmailcom> wrote:
> On 22/11/2021 17:23, kurtz le pirate wrote:
> > Hello,
> >
> > I have a surface defined by a set of points <x,y,z> and for each point,
> > its color.
> >
> > In your opinion, which object/method is the most appropriate to
> > represent such a surface?
>
>
> I'm moving slowly. I can now build my surface by generating a mesh from
> my set of points exactly as for a height_field.
> But I'm still struggling with the color story.
>
> I have this scheme on the <x,z> plane
>
> +--> z
> |
> V
> x
>
>      |     |     |
> --- * --- * --- * ---
>      |     |     |
> --- * --- * --- * ---
>      |     |     |
> --- * --- * --- * ---
>      |     |     |
> --- * --- * --- * ---
>      |     |     |
>
>
> Each "*" is my points. This points are on a "square grid".
> I convert this grid to triangle. I get :
>
>      |     |     |
> --- * --- * --- * ---
>      |   / |   / |
>      |  /  |  /  |  /
>      | /   | /   | /
> --- * --- * --- * ---
>    / |   / |   / |
>   /  |  /  |  /  |  /
> /   | /   | /   | /
> --- * --- * --- * ---
>    / |   / |   / |
>   /  |  /  |  /  |  /
> /   | /   | /   | /
> --- * --- * --- * ---
>      |     |     |
>
> I obtain a set of triangles schematized below.
> These triangles compose the mesh which is easy to display.
>
> But ... for the color, I still don't know how to do it :(
> The color is "at" a point "*". impossible to find out how to give the
> color to which triangle.
>
>
> One more time, any suggestion ?
>
>
>
>
>
> --
> Kurtz le pirate
> Compagnie de la Banquise

Hi Kurtz,

I've written the script below to show you how to create a mesh2 object from a
parametric expression of your surface and texture (I don't know how you have
defined your surface, I hope you'll figure out how to adapt the macro with
something else than parametric surfaces if needed).

Pascal

-----------------------------------------------------------------------
#version 3.8;

// Given that you have a parametric expression of the surface a follow:
// Inputs:
//   a, b: two floats, the two parameters of the parametric surface.
//         The range of values for a and b depends on the surface equation
//         but I think it's a good idea to impose it to be [0.0, 1.0] and
//         scale it as necessary here, as it avoid having to adapt the
//         CreateMesh macro below each time you change the FunShape macro
// Output:
//   Return a 3D vector, the coordinates of the surface for the given
//   parameters.
#macro FunShape(a, b)
  <a, cos(a * pi) * sin(b * pi), b>
#end

// In the exact same fashion as for the parametric shape, lets suppose you have
// a parametric expression of the texture components (here I consider only the
// rgb color, but it could be extended as needed to other texture components)
// Inputs:
//   a, b: two floats, the two parameters of the parametric surface (the same
//         as FunShape)
// Output:
//   Return a 3D vector, the rgb color of the surface for the given parameters
#macro FunColor(a, b)
  <a, 0.0, b>
#end

// You may also have an explicit expression of the normals of the surface, but
// if you don't you can get an approximation for free from the surface equation
// as follow:
// Inputs:
//   a, b: two floats, the two parameters of the parametric surface
// Output:
//   Return a 3D vector, the normal vector of the surface for the given
//   parameters.
#macro FunShapeNormal(a, b)
  // shapeEpsilon must be set to a small value in comparison to the range
  // of values for the parameters a and b. Here too, imposing a and b in
  // [0.0, 1.0] avoid having to update shapeEpsilon each time FunShape changes
  #local shapeEpsilon = 0.01;
  vcross(
    FunShape(a + shapeEpsilon, b) - FunShape(a, b),
    FunShape(a, b + shapeEpsilon) - FunShape(a, b))
#end

// The macro creating the textured mesh2 object from the parametric expression
// of your surface and texture
#macro CreateMesh()
  // Define the resolution of your grid, the higher the nicer the heavier
  #local nbStepU = 100;
  // You'd probably like to set the same resolution along the two parameters
  // but nothing forbid choose different ones
  #local nbStepV = nbStepU;
  // Starts the mesh2 object
  mesh2 {
    // Calculate the number of vertices
    #local nbVertex = (nbStepU + 1) * (nbStepV + 1);
    // Start the vertices definition
    vertex_vectors {
      nbVertex,
      // Loop on the steps along the parameters
      #local a = 0;
      #while (a <= nbStepU)
        #local b = 0;
        #while (b <= nbStepV)
          // Get the parameters in [0.0, 1.0] from the current steps and
          // calculate and add the coordinates of the vertex
          FunShape(a / nbStepU , b / nbStepV)
          #local b = b + 1;
        #end
        #local a = a + 1;
      #end
    // End the vertices definition
    }
    // Start the normals definition
    normal_vectors {
      // There is one normal per vertex, hence the reuse of nbVertex
      nbVertex,
      // Loop on the steps along the parameters
      #local a = 0;
      #while (a <= nbStepU)
        #local b = 0;
        #while (b <= nbStepV)
          // Get the parameters in [0.0, 1.0] from the current steps and
          // calculate and add the normal
          FunShapeNormal(a / nbStepU , b / nbStepV)
          #local b = b + 1;
        #end
        #local a = a + 1;
      #end
    // End the normal definition
    }
    // Start the textures definition
    texture_list {
      // There is one texture per vertex, hence the reuse of nbVertex
      nbVertex,
      // Loop on the steps along the parameters
      #local a = 0;
      #while (a <= nbStepU)
        #local b = 0;
        #while (b <= nbStepV)
          // Get the parameters in [0.0, 1.0] from the current steps and
          // calculate and add the texture. Here it could be extend with
          // other parametric functions for the finish{} parameters for
          // example
          texture { pigment { rgb FunColor(a / nbStepU , b / nbStepV) }}
          #local b = b + 1;
        #end
        #local a = a + 1;
      #end
    // End the textures definition
    }
    // Start the faces definition
    face_indices {
      // Get the number of faces, one step along the two parameters defines a
      // polyline of 4 vertices which can be split in two triangles
      #local nbFace = nbStepU * nbStepV * 2;
      nbFace ,
      // There are two ways to split the polyline in two triangles, alternating
      // regularly between them gives much better visual results. Set a flag
      // to manage that.
      #local flipEdge = 0;
      // Loop on the steps along the parameters
      #local a = 0;
      #while (a < nbStepU)
        #local b = 0;
        #while (b < nbStepV)
          // Calculate the indices of the four vertices of the polyline
          // corresponding to the current steps
          #local indexVertices = array {
            a * (nbStepV + 1) + b,
            a * (nbStepV + 1) + b + 1,
            (a + 1) * (nbStepV + 1) + b,
            (a + 1) * (nbStepV + 1) + b + 1,
            };
          // Switch between the two ways of splitting the polyline
          #if (flipEdge = 0)
            // Add the first face definition
            <indexVertices[0],indexVertices[1],indexVertices[3]>,
            // Add the texture indices, as we have conveniently defined the
            // texture in the same order as the vertices, their indices are
            // identical
            indexVertices[0],indexVertices[1],indexVertices[3]
            // Same for the second face definition
            <indexVertices[0],indexVertices[3],indexVertices[2]>,
            indexVertices[0],indexVertices[3],indexVertices[2]
          #else
            // Same as flipEdge=1 but with the other combination of indices
            <indexVertices[0],indexVertices[1],indexVertices[2]>,
            indexVertices[0],indexVertices[1],indexVertices[2]
            <indexVertices[1],indexVertices[3],indexVertices[2]>,
            indexVertices[1],indexVertices[3],indexVertices[2]
          #end
          // Flip the splitting
          #local flipEdge = 1 - flipEdge;
          #local b = b + 1;
        #end
        #local a = a + 1;
      #end
    // End the faces definition
    }
  // End the mesh2 object
  }
#end

// Instantiate the mesh
object {
  CreateMesh()
  translate -0.5*x-0.5*z
}

// Dummy settings for test rendering
global_settings {assumed_gamma 1.0}
background { color rgb 0 }
camera { location 1.5 look_at 0 }
light_source { 1.5 color rgb 1 }
-----------------------------------------------------------------------


Post a reply to this message


Attachments:
Download 'surface2mesh.jpg' (21 KB)

Preview of image 'surface2mesh.jpg'
surface2mesh.jpg


 

From: kurtz le pirate
Subject: Re: How to ...
Date: 28 Nov 2021 10:46:21
Message: <61a3a44d$1@news.povray.org>
On 28/11/2021 04:01, BayashiPascal wrote:

> Hi Kurtz,
> 
> I've written the script below to show you how to create a mesh2 object from a
> parametric expression of your surface and texture (I don't know how you have
> defined your surface, I hope you'll figure out how to adapt the macro with
> something else than parametric surfaces if needed).
> 
> ...
> 
Waouh... big job ! I will study it closely.

My problem is not the geometry but its coloring.

My script generates a mesh (that I can save to use later). I get for 
example this surface. it is a "3d" representation of the function
f(z) = (-z^3 + iz^2 + 1) / (z - 1 + i)^2

Without going into details and according with "Domain coloring", the 
color of each point of f(z) is defined by its argument which is an angle 
... and which corresponds to the hue.



-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message


Attachments:
Download 'sample_low_res.jpg' (50 KB)

Preview of image 'sample_low_res.jpg'
sample_low_res.jpg


 

From: kurtz le pirate
Subject: Re: How to ...
Date: 28 Nov 2021 10:59:40
Message: <61a3a76c$1@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

 > You're doing exactly the right things for your geometry.
 > Make sure you get the normals set correctly for the smooth_triangles,
 > so you get a nice smooth surface.
 >
 > Let me know if you're struggling there - I got it right a while back
 > after struggling with that myself - for the Bezier patch paper, IIRC.
 >

I just generate mesh with triangles.
No mesh2 and smooth_triangles. I don't know how to calculate the normals.


 > What I was trying to suggest in my first post was:
 >
 > "By using the texture_list it is possible to specify a texture per
 > triangle or even per vertex in the mesh. In the latter case the three
 > textures per triangle will be interpolated. To let POV-Ray know what
 > texture to apply to a triangle, the index of a texture is added to the
 > face_indices list, after the face index it belongs to.

Yes this feature seems to fit my needs.
The road is still long ...


Thanks Bill


Post a reply to this message

From: Bald Eagle
Subject: Re: How to ...
Date: 29 Nov 2021 21:55:00
Message: <web.61a591c5d5fe89401f9dae3025979125@news.povray.org>
kurtz le pirate <kur### [at] gmailcom> wrote:

> My problem is not the geometry but its coloring.
>
> My script generates a mesh (that I can save to use later). I get for
> example this surface. it is a "3d" representation of the function
> f(z) = (-z^3 + iz^2 + 1) / (z - 1 + i)^2
>
> Without going into details and according with "Domain coloring", the
> color of each point of f(z) is defined by its argument which is an angle
> ... and which corresponds to the hue.


My problem seems to be less the coloring and more the geometry  :D

If I understand this correctly, you input a real, scalar angle, and get a
complex result out.  Then you plot the real part of f over the complex plane
described by z and the imaginary part of f?

Or is z actually x + iz, and your "3D" surface just a 3D slice of the 4D result
of your function - plotting the real or the imaginary part of f(z) over the x-z
plane?

And then you want to convert z to the H part of HSV and color <z, Re (f(z)), Im
(f(z))> according to that hue.

You are a masochist, a sadist, and a psychopath.
Much respect.  :D

I sent you an email - wondering if it arrived in inbox or spam.


Post a reply to this message

From: kurtz le pirate
Subject: Re: How to ...
Date: 30 Nov 2021 12:03:17
Message: <61a65955$1@news.povray.org>
On 30/11/2021 03:51, Bald Eagle wrote:

> 
> You are a masochist, a sadist, and a psychopath.
> Much respect.  :D
> 
> I sent you an email - wondering if it arrived in inbox or spam.
> 

In Inbox !


-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: How to ...
Date: 30 Nov 2021 20:35:00
Message: <web.61a6d0ccd5fe894031059d5689db30a9@news.povray.org>
kurtz le pirate <kur### [at] gmailcom> wrote:
>
>...
> My problem is not the geometry but its coloring.
>
> My script generates a mesh (that I can save to use later). I get for
> example this surface. it is a "3d" representation of the function
> f(z) = (-z^3 + iz^2 + 1) / (z - 1 + i)^2
>
> Without going into details and according with "Domain coloring", the
> color of each point of f(z) is defined by its argument which is an angle
> ... and which corresponds to the hue.

Hi Kurtz

Assuming your z is a complex variable with a real and imaginary part,
and that you plot the magnitude of your function as the height (along
POV-Ray's y-axis) over a complex plane with the real part along POV-
Ray's x-axis and the imaginary part along POV-Ray's z-axis then you
can use the argument (0 to 2*pi) of your function to choose a color
from a color map, like this:

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.7;

#declare Tau = 2*pi;

#declare YourMesh = mesh2 { ... }

#declare YourArgFn = function { ... };

#declare ColorWheel =
    color_map {
        [ 0/6 color rgb <1, 0, 0> ]
        [ 1/6 color rgb <1, 1, 0> ]
        [ 2/6 color rgb <0, 1, 0> ]
        [ 3/6 color rgb <0, 1, 1> ]
        [ 4/6 color rgb <0, 0, 1> ]
        [ 5/6 color rgb <1, 0, 1> ]
        [ 6/6 color rgb <1, 0, 0> ]
    }

object {
    YourMesh
    pigment {
        function { YourArgFn(x, 0, z)/Tau }
        color_map { ColorWheel }
    }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: How to ...
Date: 30 Nov 2021 20:45:00
Message: <web.61a6d354d5fe894031059d5689db30a9@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> kurtz le pirate <kur### [at] gmailcom> wrote:
> >
> >...
> > My problem is not the geometry but its coloring.
> >
> > My script generates a mesh (that I can save to use later). I get for
> > example this surface. it is a "3d" representation of the function
> > f(z) = (-z^3 + iz^2 + 1) / (z - 1 + i)^2
> >
> > Without going into details and according with "Domain coloring", the
> > color of each point of f(z) is defined by its argument which is an angle
> > ... and which corresponds to the hue.
>
> Hi Kurtz
>
> Assuming your z is a complex variable with a real and imaginary part,
> and that you plot the magnitude of your function as the height (along
> POV-Ray's y-axis) over a complex plane with the real part along POV-
> Ray's x-axis and the imaginary part along POV-Ray's z-axis then you
> can use the argument (0 to 2*pi) of your function to choose a color
> from a color map, like this:
>...

Btw.:
I recommend this video for those of you that are interested in such problems:

"The 5 ways to visualize complex functions | Essence of complex analysis #3"
https://www.youtube.com/watch?v=NtoIXhUgqSk

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: kurtz le pirate
Subject: Re: How to ...
Date: 12 Dec 2021 07:15:58
Message: <61b5e7fe$1@news.povray.org>
On 27/11/2021 18:00, Bald Eagle wrote:
> You're doing exactly the right things for your geometry.   Make sure
you get the
> normals set correctly for the smooth_triangles, so you get a nice smooth
> surface.
> Let me know if you're struggling there - I got it right a while back after
> struggling with that myself - for the Bezier patch paper, IIRC.

Yes, I would like to have information on the calculation of the normals.


> "By using the texture_list it is possible to specify a texture per
triangle or
> even per vertex in the mesh. In the latter case the three textures per
triangle
> will be interpolated. To let POV-Ray know what texture to apply to a
triangle,
> the index of a texture is added to the face_indices list, after the
face index
> it belongs to.
>
> http://www.povray.org/documentation/view/3.7.1/68/
>
> scroll down to:
>
> 1.3.2.2.3 A separate texture per triangle

Yes, separate texture per triangle with texture_list.
Seems perfect but not easy to do (for me at least).

But, looking at the previous page of the documentation i found a mesh
object with texture by triangle.
http://www.povray.org/documentation/view/3.7.1/67/

This solution seems to me easier to use


On 01/12/2021 02:34, Tor Olav Kristensen wrote:
> Assuming your z is a complex variable with a real and imaginary part,
> and that you plot the magnitude of your function as the height (along
> POV-Ray's y-axis) over a complex plane with the real part along POV-
> Ray's x-axis and the imaginary part along POV-Ray's z-axis then you
> can use the argument (0 to 2*pi) of your function to choose a color
> from a color map, like this:
>
> // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
>
> #version 3.7;
>
> #declare Tau = 2*pi;
>
> #declare YourMesh = mesh2 { ... }
>
> #declare YourArgFn = function { ... };
>

Yes of corse. Is an elegant solution to this problem.
It's the same thing that bugman123 use.
YourArgFn() ... I can't define and use this function correctly.

I will start with the solution found in doc 1.3.2.1 Mesh Object.
I'll keep you informed.


Thanks you for your help and suggestions.





-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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