POV-Ray : Newsgroups : povray.newusers : Import of measurement data (ASCII format) in animation Server Time
24 Oct 2026 21:56:30 EDT (-0400)
  Import of measurement data (ASCII format) in animation (Message 1 to 34 of 34)  
From: JorgeAE
Subject: Import of measurement data (ASCII format) in animation
Date: 25 Feb 2016 07:20:00
Message: <web.56cef0b1bc80f3839e6517f30@news.povray.org>
Hi!
My name is Jorge. I started using POV-Ray a couple of days ago, so I am actually
a not very experienced POV-Ray user

I have a question regarding an animation which is supposed to reproduce the
vibration of a metal plate, that was taken at six different points of the
plate. The measured values are available in ASCII format.

So far, I know how to define a simple geometry (scene) and start an animation
with the help of the "clock" command. However, my task is to design a metal
plate which vibrates according to the vibration values taken at the 6 different
points of the plate mentioned before. For this reason, I am actually supposed to
import the vibration data to my POV-Ray code and assign it to 6 points in my
geometry.

I don't know how this should be implemented and have not found any similar
example in the web, so I it would be great if someone could give some ideas or
tips on how to do it.

Thank you very much!
Jorge


Post a reply to this message

From: Stephen
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 25 Feb 2016 07:58:55
Message: <56cefa8f$1@news.povray.org>
On 2/25/2016 12:17 PM, JorgeAE wrote:
> Hi!
> My name is Jorge. I started using POV-Ray a couple of days ago, so I am actually
> a not very experienced POV-Ray user
>
> I have a question regarding an animation which is supposed to reproduce the
> vibration of a metal plate, that was taken at six different points of the
> plate. The measured values are available in ASCII format.
>
> So far, I know how to define a simple geometry (scene) and start an animation
> with the help of the "clock" command. However, my task is to design a metal
> plate which vibrates according to the vibration values taken at the 6 different
> points of the plate mentioned before. For this reason, I am actually supposed to
> import the vibration data to my POV-Ray code and assign it to 6 points in my
> geometry.
>
> I don't know how this should be implemented and have not found any similar
> example in the web, so I it would be great if someone could give some ideas or
> tips on how to do it.
>
> Thank you very much!
> Jorge
>
>
>

Hi Jorge and welcome.

You could use triangles to build your metal plate.
With only 6 data points you could do that manually. If you had more you 
could build a mesh.

You could define the data points as an array and read the values from a 
file.

Help sections.
3.3.1.10 Array

3.4.5.2.3 Mesh
3.4.5.2.6 Triangle

3.3.2.3 File I/O Directives


-- 

Regards
     Stephen


Post a reply to this message

From: Alain
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 25 Feb 2016 12:22:50
Message: <56cf386a$1@news.povray.org>
Le 16-02-25 07:58, Stephen a écrit :
> On 2/25/2016 12:17 PM, JorgeAE wrote:
>> Hi!
>> My name is Jorge. I started using POV-Ray a couple of days ago, so I
>> am actually
>> a not very experienced POV-Ray user
>>
>> I have a question regarding an animation which is supposed to
>> reproduce the
>> vibration of a metal plate, that was taken at six different points of the
>> plate. The measured values are available in ASCII format.
>>
>> So far, I know how to define a simple geometry (scene) and start an
>> animation
>> with the help of the "clock" command. However, my task is to design a
>> metal
>> plate which vibrates according to the vibration values taken at the 6
>> different
>> points of the plate mentioned before. For this reason, I am actually
>> supposed to
>> import the vibration data to my POV-Ray code and assign it to 6 points
>> in my
>> geometry.
>>
>> I don't know how this should be implemented and have not found any
>> similar
>> example in the web, so I it would be great if someone could give some
>> ideas or
>> tips on how to do it.
>>
>> Thank you very much!
>> Jorge
>>
>>
>>
>
> Hi Jorge and welcome.
>
> You could use triangles to build your metal plate.
> With only 6 data points you could do that manually. If you had more you
> could build a mesh.
>
> You could define the data points as an array and read the values from a
> file.
>
> Help sections.
> 3.3.1.10 Array
>
> 3.4.5.2.3 Mesh
> 3.4.5.2.6 Triangle
>
> 3.3.2.3 File I/O Directives
>
>


Once the triangles are defined, making them into a mesh is very easy. 
Just add "mesh{" before your triangles and a "}" after. That's all there 
is to do.

If you plan of having multiple views of your plate in a single scene, 
this is the way to go.
First define your plate as an object:
Use "#declare Plate = mesh{ Your_Triangles}

Next, place your plate at various locations and orientations:
object{Plate rotate <-5,0,0> translate <0,10,0>}
object{Plate rotate <0,60,0> translate <17,-3,0>}
object{Plate rotate <90,0,60> translate <-17,-3,0>}

This will gives you 3 different views of your plate.


Alain


Post a reply to this message

From: scott
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 26 Feb 2016 06:47:28
Message: <56d03b50$1@news.povray.org>
> I have a question regarding an animation which is supposed to reproduce the
> vibration of a metal plate, that was taken at six different points of the
> plate. The measured values are available in ASCII format.
>
> So far, I know how to define a simple geometry (scene) and start an animation
> with the help of the "clock" command. However, my task is to design a metal
> plate which vibrates according to the vibration values taken at the 6 different
> points of the plate mentioned before. For this reason, I am actually supposed to
> import the vibration data to my POV-Ray code and assign it to 6 points in my
> geometry.

I would read in all the points from the ASCII file to an array first. 
Look up "#read" and "array" in the help, you should be able to figure 
out how to do it.

Then, you can choose which value to use from the array based on the 
"clock" value.

Once you've got that working, you might then want to experiment with 
doing some kind of linear interpolation between frames to get a smoother 
animation.


Post a reply to this message

From: JorgeAE
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 26 Feb 2016 08:20:00
Message: <web.56d04f85a405651bb52369120@news.povray.org>
Alain <kua### [at] videotronca> wrote:
> Le 16-02-25 07:58, Stephen a écrit :
> > On 2/25/2016 12:17 PM, JorgeAE wrote:
> >> Hi!
> >> My name is Jorge. I started using POV-Ray a couple of days ago, so I
> >> am actually
> >> a not very experienced POV-Ray user
> >>
> >> I have a question regarding an animation which is supposed to
> >> reproduce the
> >> vibration of a metal plate, that was taken at six different points of the
> >> plate. The measured values are available in ASCII format.
> >>
> >> So far, I know how to define a simple geometry (scene) and start an
> >> animation
> >> with the help of the "clock" command. However, my task is to design a
> >> metal
> >> plate which vibrates according to the vibration values taken at the 6
> >> different
> >> points of the plate mentioned before. For this reason, I am actually
> >> supposed to
> >> import the vibration data to my POV-Ray code and assign it to 6 points
> >> in my
> >> geometry.
> >>
> >> I don't know how this should be implemented and have not found any
> >> similar
> >> example in the web, so I it would be great if someone could give some
> >> ideas or
> >> tips on how to do it.
> >>
> >> Thank you very much!
> >> Jorge
> >>
> >>
> >>
> >
> > Hi Jorge and welcome.
> >
> > You could use triangles to build your metal plate.
> > With only 6 data points you could do that manually. If you had more you
> > could build a mesh.
> >
> > You could define the data points as an array and read the values from a
> > file.
> >
> > Help sections.
> > 3.3.1.10 Array
> >
> > 3.4.5.2.3 Mesh
> > 3.4.5.2.6 Triangle
> >
> > 3.3.2.3 File I/O Directives
> >
> >
>
>
> Once the triangles are defined, making them into a mesh is very easy.
> Just add "mesh{" before your triangles and a "}" after. That's all there
> is to do.
>
> If you plan of having multiple views of your plate in a single scene,
> this is the way to go.
> First define your plate as an object:
> Use "#declare Plate = mesh{ Your_Triangles}
>
> Next, place your plate at various locations and orientations:
> object{Plate rotate <-5,0,0> translate <0,10,0>}
> object{Plate rotate <0,60,0> translate <17,-3,0>}
> object{Plate rotate <90,0,60> translate <-17,-3,0>}
>
> This will gives you 3 different views of your plate.
>
>
> Alain

Hello Stephen and Alain,

thank you very much for your answers, both of them were very helpfull!! I now
created my plate and defined and array with six elements, in which each array's
element is a data point (measurement point).

Unfortunately I was still not able to solve the problem completely. I am not
sure how the animation should be implemented:
Since the ASCII files, I want to get the data from, contain the measurement data
registered in seven columns (a sort of timestamp and the six measured vibration
signals), I thought of using a linear spline curve (the plate vibrates only in
the z-direction). I would then assign the values in each of the six columns to
each data point in my mesh. In this way, the vibration values would describe the
path of the spline curve. Could this actually work? How would the syntax look
like?
By assigning a spline curve to each data point I will be trying to animate the
movement of a point and not an object, is this actually possible?

Thank you in advance for your help!

Regards
Jorge


Post a reply to this message

From: Stephen
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 26 Feb 2016 09:07:14
Message: <56d05c12@news.povray.org>
On 2/26/2016 1:15 PM, JorgeAE wrote:
> Alain <kua### [at] videotronca> wrote:
>> Le 16-02-25 07:58, Stephen a écrit :
>>> On 2/25/2016 12:17 PM, JorgeAE wrote:
>>>> Hi!
>>>> My name is Jorge. I started using POV-Ray a couple of days ago, so I
>>>> am actually
>>>> a not very experienced POV-Ray user
>>>>
>>>> I have a question regarding an animation which is supposed to
>>>> reproduce the
>>>> vibration of a metal plate, that was taken at six different points of the
>>>> plate. The measured values are available in ASCII format.
>>>>
>>>> So far, I know how to define a simple geometry (scene) and start an
>>>> animation
>>>> with the help of the "clock" command. However, my task is to design a
>>>> metal
>>>> plate which vibrates according to the vibration values taken at the 6
>>>> different
>>>> points of the plate mentioned before. For this reason, I am actually
>>>> supposed to
>>>> import the vibration data to my POV-Ray code and assign it to 6 points
>>>> in my
>>>> geometry.
>>>>
>>>> I don't know how this should be implemented and have not found any
>>>> similar
>>>> example in the web, so I it would be great if someone could give some
>>>> ideas or
>>>> tips on how to do it.
>>>>
>>>> Thank you very much!
>>>> Jorge
>>>>
>>>>
>>>>
>>>
>>> Hi Jorge and welcome.
>>>
>>> You could use triangles to build your metal plate.
>>> With only 6 data points you could do that manually. If you had more you
>>> could build a mesh.
>>>
>>> You could define the data points as an array and read the values from a
>>> file.
>>>
>>> Help sections.
>>> 3.3.1.10 Array
>>>
>>> 3.4.5.2.3 Mesh
>>> 3.4.5.2.6 Triangle
>>>
>>> 3.3.2.3 File I/O Directives
>>>
>>>
>>
>>
>> Once the triangles are defined, making them into a mesh is very easy.
>> Just add "mesh{" before your triangles and a "}" after. That's all there
>> is to do.
>>
>> If you plan of having multiple views of your plate in a single scene,
>> this is the way to go.
>> First define your plate as an object:
>> Use "#declare Plate = mesh{ Your_Triangles}
>>
>> Next, place your plate at various locations and orientations:
>> object{Plate rotate <-5,0,0> translate <0,10,0>}
>> object{Plate rotate <0,60,0> translate <17,-3,0>}
>> object{Plate rotate <90,0,60> translate <-17,-3,0>}
>>
>> This will gives you 3 different views of your plate.
>>
>>
>> Alain
>
> Hello Stephen and Alain,
>
> thank you very much for your answers, both of them were very helpfull!! I now
> created my plate and defined and array with six elements, in which each array's
> element is a data point (measurement point).
>
> Unfortunately I was still not able to solve the problem completely. I am not
> sure how the animation should be implemented:
> Since the ASCII files, I want to get the data from, contain the measurement data
> registered in seven columns (a sort of timestamp and the six measured vibration
> signals), I thought of using a linear spline curve (the plate vibrates only in
> the z-direction). I would then assign the values in each of the six columns to
> each data point in my mesh. In this way, the vibration values would describe the
> path of the spline curve. Could this actually work? How would the syntax look
> like?

I won't attempt to write any code as I use a modeller.
You might not be aware that you can use frame_number instead of the 
clock variable.
If the timestamps are are linearly spaced you can use one per frame. 
That might simplify things.



> By assigning a spline curve to each data point I will be trying to animate the
> movement of a point and not an object, is this actually possible?
>

Yes, that is right but it might be a good idea to experiment. Remember 
to create things at the origin then translate them to where you want 
them. You can lose object if you don't and rotate them.




-- 

Regards
     Stephen


Post a reply to this message

From: Alain
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 26 Feb 2016 11:25:15
Message: <56d07c6b@news.povray.org>
Le 16-02-26 08:15, JorgeAE a écrit :

>
> Hello Stephen and Alain,
>
> thank you very much for your answers, both of them were very helpfull!! I now
> created my plate and defined and array with six elements, in which each array's
> element is a data point (measurement point).
>
> Unfortunately I was still not able to solve the problem completely. I am not
> sure how the animation should be implemented:
> Since the ASCII files, I want to get the data from, contain the measurement data
> registered in seven columns (a sort of timestamp and the six measured vibration
> signals), I thought of using a linear spline curve (the plate vibrates only in
> the z-direction). I would then assign the values in each of the six columns to
> each data point in my mesh. In this way, the vibration values would describe the
> path of the spline curve. Could this actually work? How would the syntax look
> like?
> By assigning a spline curve to each data point I will be trying to animate the
> movement of a point and not an object, is this actually possible?
>
> Thank you in advance for your help!
>
> Regards
> Jorge
>
>
If you want to get one frame per data set, you can read them into an 
array, then use "frame_number" to get the specefic ones for the current 
frame.

If you use splines, then you use the "time stamp" as indices to define 
the controle points of the splines. You'll need 6 one dimentional 
splines. It looks like this within a given spline:
[Time	Point]

I recomend that you use the natural spline. It gives smooth curves 
between your points.

Next, you multiply the clock variable by the largest time stamp value 
and use that to "travel" in the splines. The syntax is the same as for 
an array, except that you now can use floats instead of only integers.

This allow you to have an animation with a number of frames that may 
differ from the number of mesurements.



Alain


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 26 Feb 2016 17:45:01
Message: <web.56d0d487a405651b664116940@news.povray.org>
I'd say that if you have six points on a solid plate, then you may want to
"build" your plate with splines as well, so that you get a smooth curvature from
the edges of the plate to the measured points, as well as the spaces in between.

Bear in mind that you'll need "extra" points as control points for your splines.

I would suggest creating something simple, like a sphere sweep, that uses only
one of the columns of vibration data, as a means to write some SDL code, get a
good looking scene, and produce a working animation.

After you've accomplished something concrete, then you can begin to expand and
add more complicated features to your file (make a copy so that you have the
original saved as a reference) and it won't be so difficult to try to "do it all
at once"

You can always post your WIPs (Works in Progress) and SDL in the appropriate
sections as attachments so that we can see exactly what you're trying to do and
see where any difficult spots and hard-to-spot errors may be.

Welcome to the POV-Ray forums, and good luck    :)


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 26 Feb 2016 18:10:01
Message: <web.56d0da3aa405651b664116940@news.povray.org>
Just a few things I found that might help you out / interest you.
(cymatics / chladni plates)

http://news.povray.org/povray.binaries.images/thread/%3C3e85f01f%40news.povray.org%3E/

http://manfredkraft.blogspot.com/2016/01/biorhythm-cymatics-23.html

https://www.youtube.com/watch?v=ATErEWDajvw

http://paulbourke.net/geometry/chladni/


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 27 Feb 2016 17:57:59
Message: <56d229f7@news.povray.org>
On 26.02.2016 23:41, Bald Eagle wrote:
>
> I'd say that if you have six points on a solid plate, then you may want to
> "build" your plate with splines as well

Objects of interest here might be "prism" (for 1d profile of vibration)
or "bicubic_patch" (for 2d plate animation)


Post a reply to this message

From: JorgeAE
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 2 Mar 2016 07:15:00
Message: <web.56d6d817a405651babd853180@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

>
> You can always post your WIPs (Works in Progress) and SDL in the appropriate
> sections as attachments so that we can see exactly what you're trying to do and
> see where any difficult spots and hard-to-spot errors may be.
>
> Welcome to the POV-Ray forums, and good luck    :)


Thank you all for your extremely useful advice!

I have been trying out some of the ideas suggested and I am now starting with
the simplest model and will expand it to a more complex and better looking one
after gaining some more experience. I just need to get to that point, where the
basic model works :).

The "prism" function seemed to me a good way of modelling the plate, due to the
given conditions in my case (1D vibration). For the animation I chose the linear
spline curve, since I managed to make it work in other animations I tried
before.

Given this, my approach consists of assigning each of the 6 points the plate is
built up of one linear spline curve generated by the vibration data. Since I
have not yet figured out how to work properly with the array definition and
reading in, I just copied a fraction of the data points from the .txt file into
my spline curve definition. Then I defined a translating vector transformation
"vtransform" along the spline curve and assigned it to a separately declared
point of the prism. Now, this sounds so simple and yet it is not working. I am
afraid, I am committing a huge mistake or omitting a "vital" aspect regarding
the sintax :/ .

It would be awesome, if you guys take a look at my (very simple) code and give
me a hint where the error is. I can't attach anything, so I have to copy my code
in here. Thank you very much in advance!


  background{White}
  camera {
    angle 20
    location <2, 10, -30>
    look_at <0, 0, -1>
    rotate <0,40,0>
  }
  light_source { <20, 20, -20> color White }




#declare P1 = <0, -3.7 >;
#declare P2 = <0, -4.3 >;
#declare P3 = <0, -3.8 >;
#declare P4 = <0, -4.1 >;
#declare P5 = <0, -3.7 >;
#declare P6 = <0, -4.1 > ;
#declare P7 = <0, -4 >  ;
#declare P8 = <0, -3.7 > ;
#declare P9 = <0, -3.8 > ;
#declare P10 = <0, -3.9 >;
#declare P11 = <0, -3.8 >;
#declare P12 = <0, -3.8 >;
#declare P13 = <0, -3.8 >;
#declare P14 = <0, -3.7 >;
#declare P15 = <0, -4.2 >;
#declare P16 = <0, -3.6 >;
#declare P17 = <0, -3.6 >;
#declare P18 = <0, -3.9 >;
#declare P19 = <0, -4.2 >;
#declare P20 = <0, -3.7 >;
#declare P21 = <0, -3.8 >;



#declare Spline_1 =
  spline {
    linear_spline

0.00,P1,
0.05,P2,
0.10,P3,
0.15,P4,
0.20,P5,
0.25,P6,
0.30,P7,
0.35,P8,
0.40,P9,
0.45,P10,
0.50,P11,
0.55,P12,
0.60,P13,
0.65,P14,
0.70,P15,
0.75,P16,
0.80,P17,
0.85,P18,
0.90,P19,
0.95,P20,
1.00,P21,

  }// end of spline ---------------
//---------------------------------------------


   prism {
    linear_sweep
    linear_spline
    0,
    0,
    7,
    <-2,-3>,<2,-3>, <2,0>, <2,3>, <-2, 3>, <-2,0>, <-2,-3>
    pigment { Blue }
  }

  #declare A = <-2,-3,0>;
  #declare Trans1 = transform{
            translate Spline_1(clock)};
  #declare B = vtransform(A,Trans1);


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 2 Mar 2016 10:25:00
Message: <web.56d704f6a405651b5e7df57c0@news.povray.org>
You can always post your scene files as attachments in:

http://news.povray.org/povray.binaries.scene-files/

I tend to post atttachments in the appropriate sections first, wait until it
shows up on the message digest, and then post a link in the main discussion
thread, to make it convenient to find.

Like this:
http://news.povray.org/povray.binaries.scene-files/message/%3Cweb.56d702f78f8162b55e7df57c0%40news.povray.org%3E/#%3Cwe
b.56d702f78f8162b55e7df57c0%40news.povray.org%3E


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 2 Mar 2016 10:35:00
Message: <web.56d7073ca405651b5e7df57c0@news.povray.org>
Also,
An invaluable resource:

http://www.f-lohmueller.de/pov_tut/animate/pov_anie.htm
 and be aware that if you click on "Insert" in POV-Ray's menu, you can insert
huge chunks of useful pre-written code, and even add your own.


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 2 Mar 2016 11:10:00
Message: <web.56d70f6ea405651b5e7df57c0@news.povray.org>
Add these lines to the top of your file:

#version 3.7;
global_settings { assumed_gamma 1.0 }
#include "colors.inc"


For your prism, if you are only making a square, then you only need 5 points
instead of 7.   Your last 2 points are redundant.
 prism {
    linear_sweep
    linear_spline
    0,
    0,
    7,
    <-2,-3>,<2,-3>, <2,0>, <2,3>, <-2, 3>, <-2,0>, <-2,-3>
    pigment { Blue }
  }

If you could attach a copy of your data set, and maybe a diagram of the location
of the points on the plate, it would be easier understand the full scope, and to
head off anything that would need to be rewritten.

I'd build the "plate" as a wire mesh, using spheres as the data points, and then
maybe cylinders or sphere sweeps to connect them in a grid.
Then you could fill in the surface with triangles or smooth_triangles.

This sounds very Paul Bourke -y
Amazing stuff
http://paulbourke.net/miscellaneous/povexamples/


If you're going to make use of the clock variable, then you need to initiate
your renders with an ini file, set up for your animation.
I would suggest copying your files to a special subdirectory, since this will
generate a large collection of separate renders.

Then you need to collect all of your images into a video file so you can animate
it (or you could just use a viewer and "step" through the images one after the
other.
I use VideoMach  ( http://gromada.com/videomach/ ) for most of my work.
Other people have their preferences, based on OS, etc.
Format Factory is useful for converting to other video formats.


Post a reply to this message

From: Stephen
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 2 Mar 2016 11:32:26
Message: <56d7159a$1@news.povray.org>
On 3/2/2016 4:06 PM, Bald Eagle wrote:
> If you could attach a copy of your data set, and maybe a diagram of the location
> of the points on the plate, it would be easier understand the full scope, and to
> head off anything that would need to be rewritten.

Yes, only six points. Driving me mad trying to imagine it. Are the edges 
fixed or free etc. :-)

-- 

Regards
     Stephen


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 2 Mar 2016 12:35:00
Message: <web.56d72336a405651b5e7df57c0@news.povray.org>
Stephen <mca### [at] aolcom> wrote:

> Yes, only six points. Driving me mad trying to imagine it. Are the edges
> fixed or free etc. :-)

That would affect things, and produce a different visual effect, yes.
I'm currently wondering if the vibrations are purely (co)sine waves and their
harmonics, or if there's some catenary in there...

Getting something smoothly interpolated might require functions and
isosurfaces...   the ball-and-stick/string grid would be pretty cumbersome,
although if you had a lot of splines that were defined using arrays... still
pretty ugly.  I haven't had that much coffee yet, and I'm not sure how much free
time I'd have to work all of that out...   :O

We're almost getting into Finite Element Method territory here.   {shivers}


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 2 Mar 2016 13:00:01
Message: <web.56d72995a405651b5e7df57c0@news.povray.org>
Scratch all that.
Christian Froeschlin obviously has the winning idea with the bicubic_patch.

[high five!]


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 2 Mar 2016 21:45:01
Message: <web.56d7a4b7a405651b5e7df57c0@news.povray.org>
Christian,

I just got done editing a lot of code to smoothly stitch together four bicubic
patches, and what I noticed is that the surface of the patches do not coincide
with the control points - which is likely how the data set would applied -
setting the control points from the values in the file.

http://news.povray.org/povray.binaries.images/attachment/%3Cweb.56d7a3881f57d665e7df57c0%40news.povray.org%3E/4smoothbi
cubicpatches%20%5Bnumgrid%20-%20side%5D.png

Is there a way to calculate where the control point needs to be given the
surface coordinate?   I seem to recall some sort of A-Frame looking diagram,
though I'll have to go dig that up and see if there's a way to back-calculate.


Post a reply to this message

From: Stephen
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 3 Mar 2016 05:54:41
Message: <56d817f1$1@news.povray.org>
On 3/2/2016 5:30 PM, Bald Eagle wrote:
> Stephen <mca### [at] aolcom> wrote:
>
>> Yes, only six points. Driving me mad trying to imagine it. Are the edges
>> fixed or free etc. :-)
>
> That would affect things, and produce a different visual effect, yes.
> I'm currently wondering if the vibrations are purely (co)sine waves and their
> harmonics, or if there's some catenary in there...
>
> Getting something smoothly interpolated might require functions and
> isosurfaces...   the ball-and-stick/string grid would be pretty cumbersome,
> although if you had a lot of splines that were defined using arrays... still
> pretty ugly.  I haven't had that much coffee yet, and I'm not sure how much free
> time I'd have to work all of that out...   :O
>
> We're almost getting into Finite Element Method territory here.   {shivers}
>
>

Damn you Moriarty! I an not going down that route. :-)

-- 

Regards
     Stephen


Post a reply to this message

From: Stephen
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 3 Mar 2016 06:00:26
Message: <56d8194a$1@news.povray.org>
On 3/2/2016 5:57 PM, Bald Eagle wrote:
> Scratch all that.
> Christian Froeschlin obviously has the winning idea with the bicubic_patch.
>
> [high five!]
>
>
I don't know. I've tried it before making a water surface. As you found 
out the movement is not linear. There is also the problem with joining 
the patches together and only having six data points. Too much for my 
calcified brain. :-)

-- 

Regards
     Stephen


Post a reply to this message

From: JorgeAE
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 3 Mar 2016 07:50:01
Message: <web.56d83245a405651b7f2c2ccf0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> Add these lines to the top of your file:
>
> #version 3.7;
> global_settings { assumed_gamma 1.0 }
> #include "colors.inc"


My code includes these lines, of course. I just had forgotten to copy them here
:)



>
>
> For your prism, if you are only making a square, then you only need 5 points
> instead of 7.   Your last 2 points are redundant.
>  prism {
>     linear_sweep
>     linear_spline
>     0,
>     0,
>     7,
>     <-2,-3>,<2,-3>, <2,0>, <2,3>, <-2, 3>, <-2,0>, <-2,-3>
>     pigment { Blue }
>   }

I am aware of the fact that only four different points are neccessary to define
the rectangle. The reason why I used six Points and not only four is that I
wanted to assign a spline line to each one of the six points. In that way, the
corners of the rectangle plus 2 points in the middle of both long sides would be
translated according to the (position) data I take from the Vibration file.



> If you could attach a copy of your data set, and maybe a diagram of the location
> of the points on the plate, it would be easier understand the full scope, and to
> head off anything that would need to be rewritten.
>

I uploaded three files: the vibration data as txt file, a diagram of the plate
with the real location of the measurement points and a diagram of the plate with
the measurement points located at the Corners, which corresponds to the code I
included here, where I intended to animate a "starting scenario".
(see
http://news.povray.org/povray.binaries.scene-files/thread/%3Cweb.56d82b80a405651b7f2c2ccf0%40news.povray.org%3E/)


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 3 Mar 2016 18:15:27
Message: <56d8c58f$1@news.povray.org>
On 03.03.2016 3:43, Bald Eagle wrote:

> Is there a way to calculate where the control point needs to be given the
> surface coordinate?   I seem to recall some sort of A-Frame looking diagram,
> though I'll have to go dig that up and see if there's a way to back-calculate.

I think there is not enough degrees of freedom in single patch
to do meaningful interpolation. But you might connect the reference
points in such a way that they are at corners of patches (these should
touch) and calculate inner control points for smooth transitions.

See e.g. http://www.joshuarenglish.com/cyclopedia/patches.html


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 3 Mar 2016 18:59:51
Message: <56d8cff7@news.povray.org>
> The "prism" function seemed to me a good way of modelling the plate, due to the
> given conditions in my case (1D vibration). For the animation I chose the linear
> spline curve, since I managed to make it work in other animations I tried
> before.

All you transformation does is calculate a point B from point A. It
will not affect any geometry. For that you must actually use the value
B inside the geometry instead of the literal <-2,-3> (and of course
reverse the order, calculate B before the prism).

Note using splines for that only makes sense if you need to
interpolate between measurements. If you want to render one frame
per measurement just use data point n for frame n.

Also I think you may be misinterpreting the prism. It extrudes
a 1d spline in a second dimension. It will not work if what you
have are corners + edge midpoints of a flat rectangle like this

X------X------X
|      |      |
|      |      |
X------X------X

As most simple linear geometry you could model this
with 4 triangles (or preferable a mesh2 object), as I
think you already did earlier. For a curved representation
use 2 bicubic patches that share the "middle" control points
at their corners but that is a bit more involved:

http://www.joshuarenglish.com/cyclopedia/patches.html


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 3 Mar 2016 19:00:00
Message: <web.56d8cfb7a405651b5e7df57c0@news.povray.org>
Christian Froeschlin <chr### [at] chrfrde> wrote:
> See e.g. http://www.joshuarenglish.com/cyclopedia/patches.html

I saw that, along with some of Mr. English's posts here on the forum, but I
haven't been able to do anything meaningful with it.

I might be able to get somewhere with:
https://web.archive.org/web/20131225210855/http://people.sc.fsu.edu/~jburkardt/html/bezier_interpolation.html

Got some good looking stuff coded up.   Just need to be able to have the data
points be coincident with the actual patch, and then I can put together
something that draws it all together.


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 4 Mar 2016 12:25:00
Message: <web.56d9c427a405651b5e7df57c0@news.povray.org>
OK, so due to the extreme difficulty of employing bicubic_patch objects for
this,

{issues I've run into are
- the sometimes extreme disparity between control points and patch surface
coordinates,
- Somehow trace does not hit the edge of the patch when a ray is shot straight
down at the patch in the y direction from far above a control point
- inability to get accurate min and max extent
- extremely difficult to determine control points from data points on the curve
}

I've reimagined this whole thing, and of course the first stumbling block I got
to was:

If I read all the data in from the file, then render the first frame,
what will happen is that upon rendering the 2nd frame, the data gets read in
AGAIN, over and over and over.

Any ideas for fixes for this?
This looks like the ole' Persistence of Data across frames problem.
"POV needs POD!"


Post a reply to this message

From: clipka
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 4 Mar 2016 13:09:51
Message: <56d9cf6f$1@news.povray.org>
Am 04.03.2016 um 18:21 schrieb Bald Eagle:

> If I read all the data in from the file, then render the first frame,
> what will happen is that upon rendering the 2nd frame, the data gets read in
> AGAIN, over and over and over.
> 
> Any ideas for fixes for this?
> This looks like the ole' Persistence of Data across frames problem.
> "POV needs POD!"

UberPOV has an experimental feature to carry over data from one frame to
the next (or, actually more to the point, from one render to the next,
regardless of whether those are two frames in an animation or entirely
independent renders), using "#persistent" instead of "#declare".


Post a reply to this message

From: Stephen
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 4 Mar 2016 13:44:51
Message: <56d9d7a3$1@news.povray.org>
On 3/4/2016 5:21 PM, Bald Eagle wrote:
> OK, so due to the extreme difficulty of employing bicubic_patch objects for
> this,
>
> {issues I've run into are
> - the sometimes extreme disparity between control points and patch surface
> coordinates,
> - Somehow trace does not hit the edge of the patch when a ray is shot straight
> down at the patch in the y direction from far above a control point
> - inability to get accurate min and max extent
> - extremely difficult to determine control points from data points on the curve
> }
>

One of the problems might be that we do not have calibration data for 
the sensors.
I rendered it as triangles in a mesh. The points are not planer. You 
could use a statistical formula to make them sit on a plane.



> I've reimagined this whole thing, and of course the first stumbling block I got
> to was:
>
> If I read all the data in from the file, then render the first frame,
> what will happen is that upon rendering the 2nd frame, the data gets read in
> AGAIN, over and over and over.
>
> Any ideas for fixes for this?
> This looks like the ole' Persistence of Data across frames problem.
> "POV needs POD!"
>
>

You step through the data using the clock or frame_number variables.

Talking about the data. I don't understand the time stamp. Five second 
intervals, that's quite slow, is it not? And what are the units of the 
sensors?

The long time interval makes me think that using splines is not the way 
to go.



-- 

Regards
     Stephen


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 4 Mar 2016 16:25:00
Message: <web.56d9fc6ba405651b5e7df57c0@news.povray.org>
Stephen <mca### [at] aolcom> wrote:

> One of the problems might be that we do not have calibration data for
> the sensors.

I think it's just a matter of displaying the data that's available.

> I rendered it as triangles in a mesh. The points are not planer. You
> could use a statistical formula to make them sit on a plane.

I think it's all Y data - the X and z coordinates I derived from the diagram
that was provided.  I just connected the perimeter points to get a few
triangles, and it looks _OK_ - it would be better with smooth triangles, but I'm
unsure exactly how to calculate the corner normals.

> You step through the data using the clock or frame_number variables.

I used frame number - worked fine
http://news.povray.org/povray.binaries.animations/thread/%3Cweb.56d9fbdd155fef445e7df57c0%40news.povray.org%3E/

> Talking about the data. I don't understand the time stamp. Five second
> intervals, that's quite slow, is it not? And what are the units of the
> sensors?

Maybe it's a geologic plate ...  ;)
Could be they meant milliseconds or something.

> The long time interval makes me think that using splines is not the way
> to go.

Just normalize the time stamp to the interval 0-1 by dividing them all by 490,
although I don't think the spline is limited by the numbers.


Post a reply to this message

From: Alain
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 4 Mar 2016 18:32:48
Message: <56da1b20@news.povray.org>
Le 16-03-04 16:21, Bald Eagle a écrit :
> Stephen <mca### [at] aolcom> wrote:
>
>> One of the problems might be that we do not have calibration data for
>> the sensors.
>
> I think it's just a matter of displaying the data that's available.
>
>> I rendered it as triangles in a mesh. The points are not planer. You
>> could use a statistical formula to make them sit on a plane.
>
> I think it's all Y data - the X and z coordinates I derived from the diagram
> that was provided.  I just connected the perimeter points to get a few
> triangles, and it looks _OK_ - it would be better with smooth triangles, but I'm
> unsure exactly how to calculate the corner normals.
>
>> You step through the data using the clock or frame_number variables.
>
> I used frame number - worked fine
>
http://news.povray.org/povray.binaries.animations/thread/%3Cweb.56d9fbdd155fef445e7df57c0%40news.povray.org%3E/
>
>> Talking about the data. I don't understand the time stamp. Five second
>> intervals, that's quite slow, is it not? And what are the units of the
>> sensors?

The units used can be totaly arbitrary. They can be in thousanth of an 
inch, micrometer, dust grains, mili-picas,... They only need to be self 
concistent. All we meed to have, is the possibility to assume that the 
data are linear.

>
> Maybe it's a geologic plate ...  ;)
> Could be they meant milliseconds or something.

That would be my guess also. Mili- or microsecond.

>
>> The long time interval makes me think that using splines is not the way
>> to go.
>
> Just normalize the time stamp to the interval 0-1 by dividing them all by 490,
> although I don't think the spline is limited by the numbers.
>
>
>

Splines are not limited to any range of values. Those can be negative or 
positive and range in the millions if wanted or needed.

In this case, you can multiply clock by 490, or whatever, to get the 
same result.


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 4 Mar 2016 20:45:01
Message: <web.56da38fca405651b5e7df57c0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

> Is there a way to calculate where the control point needs to be given the
> surface coordinate?


Not sure if this gets us anywhere...

https://etd.ohiolink.edu/rws_etd/document/get/wright1190032099/inline
From Page 67:

% determine the size scalar fo
u2size = size(u2,1);
v2size = size(v2,1);
% generate the matrices U and V for the ps
U2 = [u2.^3 u2.^2 u2
V2 = [v2.^3 v2.^2 v2
% control point matrix indices
cmri = j1*4;
cmci = i1*4;
%%%%%%% psuedo-inverse transform
%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
Pxc(cmri-3:cmri,cmci-3
((inv(B)*pinv(U))*Px*(pinv(V)'*inv(B)
Pyc(cmri-3:cmri,cmci-3:cmci) =
((inv(B)*pinv(U))*Py*(pinv(V)'*inv(B)'));
Pzc(cmri-3:cmr
((inv(B)*pinv(U))*Pz*(pinv(V)'*i
%%%%%


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 6 Mar 2016 01:20:04
Message: <web.56db1a00a405651b5e7df57c0@news.povray.org>
I just spent a lot of time getting all the array loops to work without error,
and now POV complains
Parse Error: Expected 'RValue to declare', End of File found instead
or if I comment out the #end where it chokes, then I get "end of file reached,
but #end expected.

As far as I can see, all my #locals have a ; and all my #fors have an #end

Hoping someone can help me spot where in the chain it's all going wrong.
I'll keep hunting backward

(This is fourth time I'm posting this - seems to be a problem getting it to
"take" via the web interface in p.b.scene files)

===============================================================


#version 3.7;
global_settings { assumed_gamma 1.0 }

//------------------------------------------
// SDL for making a Bezier spline - given 4 data points, compute control points
p1 and p2
// Bill Walker - 2016
// Adapted code to POV-Ray from :
// https://www.particleincell.com/2012/bezier-splines/
// https://www.particleincell.com/wp-content/uploads/2012/06/circles.svg
// replace var with #declare or #local, function with #macro, edit #for() #end
syntax, array[] syntax
//------------------------------------------

#include "colors.inc"
#include "debug.inc"
 Set_Debug (true)
#include "math.inc"

light_source { <0, 50, -50>  color rgb <1, 1, 1>}


#declare Camera_Front =
camera {
location  <0, 90, -1>
 //right    x*image_width/image_height
look_at   <0, 0, 0>}


camera {Camera_Front}

// bezier-spline.js

// computes cubic bezier coefficients to generate a smooth
// line through specified points. couples with SVG graphics
// for interactive processing.

// For more info see:
// http://www.particleincell.com/2012/bezier-splines/

// Lubos Brieda, Particle In Cell Consulting LLC, 2012
// you may freely use this algorithm in your codes however where feasible
// please include a link/reference to the source article


//#declare svg=document.documentElement //svg object
#declare S = array[4];     //splines
#declare V = array[4];     //vertices
//#declare C       //current object
//#declare x0,y0     //svg offset
#declare K = array[4];


#macro init()
//##################################################################################
//saves elements as global variables
 //create splines
 //#declare S[0] = createPath("blue");
 //#declare S[1] = createPath("red");
 //#declare S[2] = createPath("green");
 //#declare S[3] = createPath("brown");

 //create control points
 #declare V[0] = <60,60,0>;
 createKnot(V[0])
 #declare V[1] = <220,300,0>;
 createKnot(V[1])
 #declare V[2] = <420,300,0>;
 createKnot(V[2])
 #declare V[3] = <700,240,0>;
 createKnot(V[3])

 updateSplines()
#end // end macro init
//##################################################################################


#macro createPath(Color, Width)
//##################################################################################
//creates and adds an SVG path without defining the nodes
 //width = (typeof width == 'undefined' ? "8" : width);
 //#declare P=document.createElementNS("http://www.w3.org/2000/svg","path")
 //P.setAttributeNS(null,"fill","none")
 //P.setAttributeNS(null,"stroke",color)
 //P.setAttributeNS(null,"stroke-width",width)
 //svg.appendChild(P)
 //return P

#end
//##################################################################################


#macro createKnot(V)
//##################################################################################
//creates and adds an SVG circle to represent knots
sphere { V 22 pigment {Yellow}}

  //#declare C=document.createElementNS("http://www.w3.org/2000/svg","circle")
  //C.setAttributeNS(null,"r",22)
  //C.setAttributeNS(null,"cx",x)
  //C.setAttributeNS(null,"cy",y)
  //C.setAttributeNS(null,"fill","gold")
  //C.setAttributeNS(null,"stroke","black")
  //C.setAttributeNS(null,"stroke-width","6")
  //C.setAttributeNS(null,"onmousedown","startMove(evt)")
  //svg.appendChild(C)
  //return C

#end // end macro createKnot
//##################################################################################






// Maybe set up java mouse movement as clock-linked animation
//from http://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html
/* #macro startMove(evt)

  SVG positions are relative to the element but mouse positions are relative to
the window, get offset
  x0 = getOffset(svg).left;
  y0 = getOffset(svg).top;

  C=evt.target
  svg.setAttribute("onmousemove","move(evt)")
  svg.setAttribute("onmouseup","drop()")
 #end // end macro startMove

 //called on mouse move, updates dragged circle and recomputes splines
 #macro move(evt)

  x = evt.clientX-x0;
  y = evt.clientY-y0;

  move the current handle
  C.setAttributeNS(null,"cx",x)
  C.setAttributeNS(null,"cy",y)
  updateSplines();
 #end // end macro move

 //called on mouse up event
 #macro drop()

  svg  = document.getElementsByTagName('svg')[0];
  svg.setAttributeNS(null, "onmousemove",null)
 #end // end macro drop
*/



#macro updateSplines()
//##################################################################################
//computes spline control points
 //grab (x,y) coordinates of the control points
 #local X = array[4];
 #local Y = array[4];
 #for (i, 0, 3)     //for (i=0;i<4;i++)
  //use parseInt to convert string to int
  #local X[i] = V[i];   //parseInt(V[i].getAttributeNS(null,"cx"))
  #local Y[i] = V[i];   //parseInt(V[i].getAttributeNS(null,"cy"))
 #end
 //computes control points p1 and p2 for x and y direction
 #local px = computeControlPoints(X);
 #local py = computeControlPoints(Y);

 //updates path settings, the browser will draw the new spline
 #for (i, 0, 2)     //for (i=0;i<3;i++)
  //S[i].setAttributeNS(null,"d",
path(x[i],y[i],px.p1[i],py.p1[i],px.p2[i],py.p2[i],x[i+1],y[i+1]));
  //#debug concat( "(Draw SVG path subroutine)   i = ", str(i, 3, 1), "\n")
 #end
#end // end macro updateSplines           ^^^^ call path macro
//##################################################################################



#macro path(x1,y1,px1,py1,px2,py2,x2,y2)
//##################################################################################
//creates formated path string for SVG cubic path element

 //return "M "+x1+" "+y1+" C "+px1+" "+py1+" "+px2+" "+py2+" "+x2+" "+y2;
#end // end macro paths
//##################################################################################



#macro computeControlPoints(K)
//##################################################################################
//computes control points given knots K, this is the brain of the operation
 #local p1 = array[4];
 #local p2 = array[4];
 #local n = dimension_size (K, 1) - 1;  //K.length-1;

  //rhs vector
  #local a = array[n];
  #local b = array[n];
  #local c = array[n];
  #local r = array[n];

  //left most segment
  #local a[0] = 0;
  #local b[0] = 2;
  #local c[0] = 1;
  #local r[0] = K[0] + 2 * K[1];

  //internal segments
  #for (i, 0, n-2)     //(i = 1; i < n - 1; i++)
   #local a[i] = 1;
   #local b[i] = 4;
   #local c[i] = 1;
   #local r[i] = 4 * K[i] + 2 * K[i+1];
  #end

  //right segment
  #local a[n-1] = 2;
  #local b[n-1] = 7;
  #local c[n-1] = 0;
  #local r[n-1] = 8 * K[n-1] + K[n];

  //solves Ax=b with the Thomas algorithm (from Wikipedia)
  #for (i, 1, n-1)     //#for (i = 1; i < n; i++)
   #local m = a[i]/b[i-1];
   #local b[i] = b[i] - m * c[i - 1];
   #local r[i] = r[i] - m*r[i-1];
  #end

  #local p1[n-1] = r[n-1]/b[n-1]; //#local p1[n-1] = r[n-1]/b[n-1];
  // {Be sure to include debug.inc file!}
  //#debug concat( "Defining p1.   n-1 = ", str((n-1), 3, 1), "\n")


  #for (i, n-2, 0, -1)     //#for (i = n - 2; i >= 0; --i)
   #local p1[i] = (r[i] - c[i] * p1[i+1]) / b[i];
   //#debug concat( "Defining p1.   i = ", str(i, 3, 1), "  Defining p1.   i+1 =
", str((i+1), 3, 1),"\n")
  #end

  //we have p1, now compute p2
  #for (i, 0, n-2)     //#for (i=0;i<n-1;i++)
   //#debug concat( "Defining p2   i = ", str(i, 3, 1), "  i+1 = ", str((i+1),
3, 1),"\n")
   #local p2[i] = 2 * K[i+1] - p1[i+1];
  #end

  #local p2[n-1] = 0.5 * (K[n] + p1[n-1]);

  //return {p1:p1, p2:p2};
#end // end macro computeControlPoints
//##################################################################################

//code from
http://stackoverflow.com/questions/442404/dynamically-retrieve-html-element-x-y-position-with-javascript
//#macro getOffset( el )

//    #declare _x = 0;
//   #declare _y = 0;
//    while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
//        _x += el.offsetLeft - el.scrollLeft;
//        _y += el.offsetTop - el.scrollTop;
//        el = el.offsetParent;
//
//    return { top: _y, left: _x };

//call macros
init ()


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 6 Mar 2016 01:20:04
Message: <web.56db1fb6a405651b5e7df57c0@news.povray.org>
I just spent a lot of time getting all the array loops to work without error,
and now POV complains
Parse Error: Expected 'RValue to declare', End of File found instead
or if I comment out the #end where it chokes, then I get "end of file reached,
but #end expected.

As far as I can see, all my #locals have a ; and all my #fors have an #end

Hoping someone can help me spot where in the chain it's all going wrong.
I'll keep hunting backward

(This is fifth time I'm posting this - seems to be a problem getting it to
"take" via the web interface in p.b.scene files, and here as well)

I reworked the file into a "linear" scene description, and it works fine as long
as the macro is not called by saying
#local px = computeControlPoints(X);

If I just call the macro with computeControlPoints(X), the SDL renders 4 spheres
and doesn't choke.   I'm mystified.

===============================================================


#version 3.7;
global_settings { assumed_gamma 1.0 }

//------------------------------------------
// SDL for making a Bezier spline - given 4 data points, compute control points
p1 and p2
// Bill Walker - 2016
// Adapted code to POV-Ray from :
// https://www.particleincell.com/2012/bezier-splines/
// https://www.particleincell.com/wp-content/uploads/2012/06/circles.svg
// replace var with #declare or #local, function with #macro, edit #for() #end
syntax, array[] syntax
//------------------------------------------

#include "colors.inc"
#include "debug.inc"
 Set_Debug (true)
#include "math.inc"

light_source { <0, 50, -50>  color rgb <1, 1, 1>}


#declare Camera_Front =
camera {
location  <0, 90, -1>
 //right    x*image_width/image_height
look_at   <0, 0, 0>}


camera {Camera_Front}

// bezier-spline.js

// computes cubic bezier coefficients to generate a smooth
// line through specified points. couples with SVG graphics
// for interactive processing.

// For more info see:
// http://www.particleincell.com/2012/bezier-splines/

// Lubos Brieda, Particle In Cell Consulting LLC, 2012
// you may freely use this algorithm in your codes however where feasible
// please include a link/reference to the source article


//#declare svg=document.documentElement //svg object
#declare S = array[4];     //splines
#declare V = array[4];     //vertices
//#declare C       //current object
//#declare x0,y0     //svg offset
#declare K = array[4];


#macro init()
//##################################################################################
//saves elements as global variables
 //create splines
 //#declare S[0] = createPath("blue");
 //#declare S[1] = createPath("red");
 //#declare S[2] = createPath("green");
 //#declare S[3] = createPath("brown");

 //create control points
 #declare V[0] = <60,60,0>;
 createKnot(V[0])
 #declare V[1] = <220,300,0>;
 createKnot(V[1])
 #declare V[2] = <420,300,0>;
 createKnot(V[2])
 #declare V[3] = <700,240,0>;
 createKnot(V[3])

 updateSplines()
#end // end macro init
//##################################################################################


#macro createPath(Color, Width)
//##################################################################################
//creates and adds an SVG path without defining the nodes
 //width = (typeof width == 'undefined' ? "8" : width);
 //#declare P=document.createElementNS("http://www.w3.org/2000/svg","path")
 //P.setAttributeNS(null,"fill","none")
 //P.setAttributeNS(null,"stroke",color)
 //P.setAttributeNS(null,"stroke-width",width)
 //svg.appendChild(P)
 //return P

#end
//##################################################################################


#macro createKnot(V)
//##################################################################################
//creates and adds an SVG circle to represent knots
sphere { V 22 pigment {Yellow}}

  //#declare C=document.createElementNS("http://www.w3.org/2000/svg","circle")
  //C.setAttributeNS(null,"r",22)
  //C.setAttributeNS(null,"cx",x)
  //C.setAttributeNS(null,"cy",y)
  //C.setAttributeNS(null,"fill","gold")
  //C.setAttributeNS(null,"stroke","black")
  //C.setAttributeNS(null,"stroke-width","6")
  //C.setAttributeNS(null,"onmousedown","startMove(evt)")
  //svg.appendChild(C)
  //return C

#end // end macro createKnot
//##################################################################################






// Maybe set up java mouse movement as clock-linked animation
//from http://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html
/* #macro startMove(evt)

  SVG positions are relative to the element but mouse positions are relative to
the window, get offset
  x0 = getOffset(svg).left;
  y0 = getOffset(svg).top;

  C=evt.target
  svg.setAttribute("onmousemove","move(evt)")
  svg.setAttribute("onmouseup","drop()")
 #end // end macro startMove

 //called on mouse move, updates dragged circle and recomputes splines
 #macro move(evt)

  x = evt.clientX-x0;
  y = evt.clientY-y0;

  move the current handle
  C.setAttributeNS(null,"cx",x)
  C.setAttributeNS(null,"cy",y)
  updateSplines();
 #end // end macro move

 //called on mouse up event
 #macro drop()

  svg  = document.getElementsByTagName('svg')[0];
  svg.setAttributeNS(null, "onmousemove",null)
 #end // end macro drop
*/



#macro updateSplines()
//##################################################################################
//computes spline control points
 //grab (x,y) coordinates of the control points
 #local X = array[4];
 #local Y = array[4];
 #for (i, 0, 3)     //for (i=0;i<4;i++)
  //use parseInt to convert string to int
  #local X[i] = V[i];   //parseInt(V[i].getAttributeNS(null,"cx"))
  #local Y[i] = V[i];   //parseInt(V[i].getAttributeNS(null,"cy"))
 #end
 //computes control points p1 and p2 for x and y direction
 #local px = computeControlPoints(X);
 #local py = computeControlPoints(Y);

 //updates path settings, the browser will draw the new spline
 #for (i, 0, 2)     //for (i=0;i<3;i++)
  //S[i].setAttributeNS(null,"d",
path(x[i],y[i],px.p1[i],py.p1[i],px.p2[i],py.p2[i],x[i+1],y[i+1]));
  //#debug concat( "(Draw SVG path subroutine)   i = ", str(i, 3, 1), "\n")
 #end
#end // end macro updateSplines           ^^^^ call path macro
//##################################################################################



#macro path(x1,y1,px1,py1,px2,py2,x2,y2)
//##################################################################################
//creates formated path string for SVG cubic path element

 //return "M "+x1+" "+y1+" C "+px1+" "+py1+" "+px2+" "+py2+" "+x2+" "+y2;
#end // end macro paths
//##################################################################################



#macro computeControlPoints(K)
//##################################################################################
//computes control points given knots K, this is the brain of the operation
 #local p1 = array[4];
 #local p2 = array[4];
 #local n = dimension_size (K, 1) - 1;  //K.length-1;

  //rhs vector
  #local a = array[n];
  #local b = array[n];
  #local c = array[n];
  #local r = array[n];

  //left most segment
  #local a[0] = 0;
  #local b[0] = 2;
  #local c[0] = 1;
  #local r[0] = K[0] + 2 * K[1];

  //internal segments
  #for (i, 0, n-2)     //(i = 1; i < n - 1; i++)
   #local a[i] = 1;
   #local b[i] = 4;
   #local c[i] = 1;
   #local r[i] = 4 * K[i] + 2 * K[i+1];
  #end

  //right segment
  #local a[n-1] = 2;
  #local b[n-1] = 7;
  #local c[n-1] = 0;
  #local r[n-1] = 8 * K[n-1] + K[n];

  //solves Ax=b with the Thomas algorithm (from Wikipedia)
  #for (i, 1, n-1)     //#for (i = 1; i < n; i++)
   #local m = a[i]/b[i-1];
   #local b[i] = b[i] - m * c[i - 1];
   #local r[i] = r[i] - m*r[i-1];
  #end

  #local p1[n-1] = r[n-1]/b[n-1]; //#local p1[n-1] = r[n-1]/b[n-1];
  // {Be sure to include debug.inc file!}
  //#debug concat( "Defining p1.   n-1 = ", str((n-1), 3, 1), "\n")


  #for (i, n-2, 0, -1)     //#for (i = n - 2; i >= 0; --i)
   #local p1[i] = (r[i] - c[i] * p1[i+1]) / b[i];
   //#debug concat( "Defining p1.   i = ", str(i, 3, 1), "  Defining p1.   i+1 =
", str((i+1), 3, 1),"\n")
  #end

  //we have p1, now compute p2
  #for (i, 0, n-2)     //#for (i=0;i<n-1;i++)
   //#debug concat( "Defining p2   i = ", str(i, 3, 1), "  i+1 = ", str((i+1),
3, 1),"\n")
   #local p2[i] = 2 * K[i+1] - p1[i+1];
  #end

  #local p2[n-1] = 0.5 * (K[n] + p1[n-1]);

  //return {p1:p1, p2:p2};
#end // end macro computeControlPoints
//##################################################################################

//code from
http://stackoverflow.com/questions/442404/dynamically-retrieve-html-element-x-y-position-with-javascript
//#macro getOffset( el )

//    #declare _x = 0;
//   #declare _y = 0;
//    while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
//        _x += el.offsetLeft - el.scrollLeft;
//        _y += el.offsetTop - el.scrollTop;
//        el = el.offsetParent;
//
//    return { top: _y, left: _x };

//call macros
init ()


Post a reply to this message

From: clipka
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 6 Mar 2016 03:12:49
Message: <56dbe681$1@news.povray.org>
Am 05.03.2016 um 19:04 schrieb Bald Eagle:
> I just spent a lot of time getting all the array loops to work without error,
> and now POV complains
> Parse Error: Expected 'RValue to declare', End of File found instead
> or if I comment out the #end where it chokes, then I get "end of file reached,
> but #end expected.

Just for info, and before anyone complains:
The newsgroup server had some hiccups, and failed to show new postings.
Not really surprising that someone would double-post (or in this case
fivefold-post).


Post a reply to this message

From: Bald Eagle
Subject: Re: Import of measurement data (ASCII format) in animation
Date: 6 Mar 2016 11:10:01
Message: <web.56dc552ea405651b5e7df57c0@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

> Just for info, and before anyone complains:
> The newsgroup server had some hiccups, and failed to show new postings.
> Not really surprising that someone would double-post (or in this case
> fivefold-post).

Yes, I realized that, after nothing went through, and I didn't see any posts for
13+ hours.
That's OK - I worked through the code again and again and came to the same
conclusion.  I guess it's just seems so foreign to have an array name just
sitting there all alone on an empty, otherwise blank line.
No #declare, no "return", no =, no ;

It was hard to see what WASN'T in the macro, but then past experience, and
seeing what folks have done with self-recursive macros made a neuron fire.

I also figures out the rest of the output of the algorithm, what it ACTUALLY
does (not what I thought it did / wanted it to do), and basically, it was a
long, tiring, but educational and productive night that gave me a both a
headache and sense of accomplishment.

Sorry for the quintuple-post  :O


Post a reply to this message

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