benedek
Posts: 8
Joined: Sun Mar 03, 2013 10:24 pm

3D Parametric Function Plotting

Sun Mar 03, 2013 10:28 pm

EDIT: Be careful, apparently in at least one case null divisions in my program have caused reboots and filesystem corruption. Use this program at your own risk and backup important data first :^]

Hey there,
I just registered to show this program that I made. It uses OpenGL ES for drawing and SDL for user input to interactively render surfaces in 3D which you can define with parametric functions.
Here's the project link: https://bitbucket.org/benedek/rpi-simple-paramplot
And a video showing it off: http://www.youtube.com/watch?v=m-GseLka2NM
Last edited by benedek on Tue Mar 12, 2013 9:38 pm, edited 1 time in total.

User avatar
PeterO
Posts: 5073
Joined: Sun Jul 22, 2012 4:14 pm

Re: 3D Parametric Function Plotting

Mon Mar 04, 2013 8:36 pm

I just watched your video, and it is a very interesting application. I'll be having a play with it myself.... Is there a description of the command line syntax anywhere (I can't see it in the download files) ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

benedek
Posts: 8
Joined: Sun Mar 03, 2013 10:24 pm

Re: 3D Parametric Function Plotting

Tue Mar 05, 2013 5:21 am

The -h option gives the description you're looking for when running the program, but you're right, it's better to have it in the README, too, so I updated that on the project page.
I hope the program will work well for you!

User avatar
PeterO
Posts: 5073
Joined: Sun Jul 22, 2012 4:14 pm

Re: 3D Parametric Function Plotting

Sun Mar 10, 2013 4:49 pm

"The program depends on GL, GLM and SDL, so make sure you have those installed
on your system before proceeding."

Some indication of the actual packages need to be installed would be helpful...

sudo apt-get install sdl
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package sdl

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

benedek
Posts: 8
Joined: Sun Mar 03, 2013 10:24 pm

Re: 3D Parametric Function Plotting

Sun Mar 10, 2013 5:12 pm

You can search for packages with the "apt-cache search" command, like "apt-cache search sdl". Development versions of libraries (which are needed for compilation) will almost always have a "-dev" suffix.

The SDL package you need is called "libsdl1.2-dev".

I don't think you need to install anything GL-related; the GLM package is called "libglm-dev".

You're right, I should also add these package names to the README, since Raspbian is the most common RPi distro.

User avatar
PeterO
Posts: 5073
Joined: Sun Jul 22, 2012 4:14 pm

Re: 3D Parametric Function Plotting

Sun Mar 10, 2013 5:25 pm

I had tried apt-cache search sdl, but it wasn't obvious which one of the 157 results was the one needed :roll:
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
hanzelpeter
Posts: 72
Joined: Mon Jul 09, 2012 11:56 am

Re: 3D Parametric Function Plotting

Tue Mar 12, 2013 7:13 pm

Hello.

I have got it running. Great app.
Do you have some other examples of functions?

I am not good in math.

Thanks.

User avatar
diereinegier
Posts: 166
Joined: Sun Dec 30, 2012 5:45 pm
Location: Bonn, Germany
Contact: Website

Re: 3D Parametric Function Plotting

Tue Mar 12, 2013 8:05 pm

This works for a short while:

Code: Select all

./rpi-simple-paramplot -e"U=10*(u-0.5)" -e"V=10*(v-0.5)" -e"r=(U*U+V*V)^0.5" -x"U" -y"V" -z"1/sin(r)" 
This gives me an instant reboot:

Code: Select all

./rpi-simple-paramplot -e"U=10*(u-0.5)" -e"V=10*(v-0.5)" -e"r=(U*U+V*V)^0.5" -x"U" -y"V" -z"0.001*1/sin(r)" 
Some IF-Construct to put in the limit of 1 at (0,0) would maybe help. but maybe dividing by zero is not the only problem...

Ouch, even the file system is severly corrupted.
Backup restored. Changes since last backup redone. Phew!
Last edited by diereinegier on Tue Mar 12, 2013 9:07 pm, edited 3 times in total.
Download my repositories at https://github.com/GeorgBisseling

User avatar
diereinegier
Posts: 166
Joined: Sun Dec 30, 2012 5:45 pm
Location: Bonn, Germany
Contact: Website

Re: 3D Parametric Function Plotting

Tue Mar 12, 2013 8:07 pm

BTW: linking with -lbcm_host made it work on the older raspian version.
I mentioned that already in the comments on the start page.
Download my repositories at https://github.com/GeorgBisseling

benedek
Posts: 8
Joined: Sun Mar 03, 2013 10:24 pm

Re: 3D Parametric Function Plotting

Tue Mar 12, 2013 8:45 pm

Hey diereiniger,
Thanks for the compilation info, I'll add that to the Makefile right away!
I'm sorry to hear that I ruined your system :-/
I tested those two invocations and neither of them rebooted my RPi. Are you really sure it's not a power supply issue or something else? I would have a hard time imagining that that program could do such damage, I mean, NaNs and Infs should cause no reboot :)
But then again, I had very weird floating-point errors occur while testing (that's why I have no optimization options on in the Makefile :P ).

User avatar
diereinegier
Posts: 166
Joined: Sun Dec 30, 2012 5:45 pm
Location: Bonn, Germany
Contact: Website

Re: 3D Parametric Function Plotting

Wed Mar 13, 2013 8:48 am

I am pretty sure that it is not a power issue, because the system runs stable.

After I saw that the file system was ruined beyond repair I used the possibility of fear free testing and could reproduce the reboot several times with 1/sin(r) and it ran stable with sin(r).

I will have a look at your program on a fresh SD image.
Chances are that floating point errors in the GPU have to be handled somehow.
Do you calculate all points in double and then convert to GLES structures holding single precision floats?
Maybe one could check for NaNs and Numbers that can not be presented as single and refuse to go to GLES altogether?
Maybe we found a bug in the OpenGL ES implementation?
Download my repositories at https://github.com/GeorgBisseling

benedek
Posts: 8
Joined: Sun Mar 03, 2013 10:24 pm

Re: 3D Parametric Function Plotting

Wed Mar 13, 2013 9:09 am

Before I give the numbers to GLES I put them in glm::vec3 arrays, so they're always single-precision I think.
But yeah, I also thought of simply checking for NaN and +-Inf and turning them into, say, 0, before putting them into the GLES buffer.
Maybe you could test that; one place to catch those bad number is in main.cpp after line 315, where the samples are evaluated. Possibly something like

Code: Select all

if(isnan(positions[pos_idx].x) || !isfinite(positions[pos_idx].x)) positions[pos_idx].x = 0;

User avatar
diereinegier
Posts: 166
Joined: Sun Dec 30, 2012 5:45 pm
Location: Bonn, Germany
Contact: Website

Re: 3D Parametric Function Plotting

Thu Mar 14, 2013 10:14 pm

Benedek,

I have to apologize. Tonight I tried to find out what went wrong. In fact I found that the backup I made before trying your program was already corrupted. I do not know what exactly went wrong with this RasPi. But I took back all overclocking on all RasPis that I own just to be on the safe side. The respective machine had a hickup when I connected an UART-to-USB cable to the GPIOs. Maybe that caused the trouble.

It is my plan to check out your program on a new image based on wheezy 2013-02-09 as soon as possible.

Tonight I copied so many sd card images back and forth and fsck'ed them that I really want to watch TV now ;-)
Download my repositories at https://github.com/GeorgBisseling

benedek
Posts: 8
Joined: Sun Mar 03, 2013 10:24 pm

Re: 3D Parametric Function Plotting

Fri Mar 15, 2013 5:16 am

diereiniger,

That's okay =)
Do you think it's safe to remove the warnings from everywhere around my project then, or did the program still have an effect on your RPi?

Thanks for all the feedback!

User avatar
diereinegier
Posts: 166
Joined: Sun Dec 30, 2012 5:45 pm
Location: Bonn, Germany
Contact: Website

Re: 3D Parametric Function Plotting

Fri Mar 15, 2013 3:57 pm

I did not have the time do check that. But I will.

Could you reproduce reboots when dividing by zero?
Download my repositories at https://github.com/GeorgBisseling

benedek
Posts: 8
Joined: Sun Mar 03, 2013 10:24 pm

Re: 3D Parametric Function Plotting

Fri Mar 15, 2013 4:53 pm

Nope, I didn't get reboots at all.

Are you getting reboots even under normal circumstances?

User avatar
diereinegier
Posts: 166
Joined: Sun Dec 30, 2012 5:45 pm
Location: Bonn, Germany
Contact: Website

Re: 3D Parametric Function Plotting

Fri Mar 15, 2013 6:38 pm

What a relief!

After installing, updating, backing up several times in a row I had a system where everything seems to be running as smooth as before.

Now I checked your program with a handful of formulas that divide by zero and render very big z coordinates. Everything was stable. No reboots. Not even the program crashing.

The next step will be of course to reenable overclocking and hope for the best.

By the way if you try these parameters:

Code: Select all

#!/bin/bash
./rpi-simple-paramplot -e"U=100*(0.5-u)" -e"V=100*(0.5-v)" -e"R=(U*U+V*V)^0.5" -x"U" -y"V" -z"sin(R)"
then you will see a ripple in the surface. When I did my 3D plotting experiments (without any acceleration) I fought the same effect. One way to soften this effect is to use more and smaller triangles. But this is wasteful. Another way is looking at the surface as being made of squares and then to decide which diagonal has to be chosen to cut the square into two triangles. This would prohibit the use of triangle strips, but if the device is fast enough, one could even afford to model all triangles separately.
Download my repositories at https://github.com/GeorgBisseling

benedek
Posts: 8
Joined: Sun Mar 03, 2013 10:24 pm

Re: 3D Parametric Function Plotting

Fri Mar 15, 2013 7:15 pm

Ah, good to hear that the reboots have stopped :)

Yeah, I haven't spent any time optimizing the triangulation algorithm... think of it more as a graphics demo than a useful math application (it doesn't even have many functions yet) :D

You can set the grid resolution with the -u and -v options, although they're limited to 256 each because I use indexed drawing with unsigned short indices (actually the product of the resolutions should be maximally 256*256, but I was too lazy to even check it that way).
I could switch to plain array drawing, which would use more memory but have no index restrictions (it might be even faster, but I haven't tried it).

To increase the accuracy of rough functions, I also thought of normal mapping; maybe that would make it look a bit better without losing too much performance. Similarly, I originally wanted to apply the colors as a texture, but then got too lazy, again.

User avatar
meltwater
Posts: 1014
Joined: Tue Oct 18, 2011 11:38 am

Re: 3D Parametric Function Plotting

Thu Mar 28, 2013 3:19 pm

I finally had chance to try this.

Now, for those of us who have no idea about 3d graphics/have maths degrees, is there a good source of information available on how to construct things using the maths you are using in the program.
Would be great to see more!

(the examples above seem to work fine on my overclocked Rpi)
Last edited by meltwater on Tue Jun 25, 2013 12:16 pm, edited 1 time in total.
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam

()blivion
Posts: 4
Joined: Tue Jun 18, 2013 7:41 am

Re: 3D Parametric Function Plotting

Tue Jun 25, 2013 12:11 pm

I have already sent an email to the author benedek, but I want to post it publicly as well.

Enabling screen overscan settings in "/boot/configure.txt" causes a black screen when the program in question is invoked. Restarting, disabling overscan settings, then running the program again with the same exact parameters (stored in a bash script) works perfectly fine.

This could possibly be an issue with the Pi, or just MY Pi. So it would be good if some people would attempt to reproduce this.

Ben314
Posts: 1
Joined: Fri Oct 18, 2013 7:02 am

Re: 3D Parametric Function Plotting

Fri Oct 18, 2013 7:06 am

Now, for those of us who have no idea about 3d graphics/have maths degrees, is there a good source of information available on how to construct things using the maths you are using in the program.
I agree. Messing around I've been able to make a cone, a bundt cake pan, and a few random shapes, but I'm not really getting how it's working.

User avatar
meltwater
Posts: 1014
Joined: Tue Oct 18, 2011 11:38 am

Re: 3D Parametric Function Plotting

Fri Oct 18, 2013 12:19 pm

Ben314 wrote:
Now, for those of us who have no idea about 3d graphics/have maths degrees, is there a good source of information available on how to construct things using the maths you are using in the program.
I agree. Messing around I've been able to make a cone, a bundt cake pan, and a few random shapes, but I'm not really getting how it's working.
I recently had a go with pi3d (http://pi3d.github.io/html/ReadMe.html), and it is amazing. There are several example python scripts and with the help of the authors of it, it was possible to pick it up rather quickly.

I enjoyed it so much, I have a whole chapter in my book about it (http://goo.gl/dmVtsc), and how to use it. It is quite a decent 3D engine (and yes plenty of maths still if you want for calculating viewpoints etc).

I even used it on the MagPi demo table: http://pihw.wordpress.com/2013/10/03/ma ... -showcase/

The parametric plotter is still excellent for trying out the maths functions.
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam

Return to “OpenGLES”