473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

plot a 3D sphere from C++ using gnuplot?

mlt
Anyone has an idea to generate points for a solid sphere in C++ that can be
plotted with gnuplot? I have tried to plot simple functions based on output
from a function written in C++ which worked fine, but am not sure how to
deal with solid object like a sphere from C++.
Sep 2 '08 #1
6 8025
On 2008-09-02 19:46, mlt wrote:
Anyone has an idea to generate points for a solid sphere in C++ that can be
plotted with gnuplot? I have tried to plot simple functions based on output
from a function written in C++ which worked fine, but am not sure how to
deal with solid object like a sphere from C++.
Just like you did with the function, you just have to add the third
dimension in the output, and figure out the correct gnuplot format.

--
Erik Wikström
Sep 2 '08 #2
mlt wrote:
Anyone has an idea to generate points for a solid sphere in C++ that can be
plotted with gnuplot? I have tried to plot simple functions based on output
from a function written in C++ which worked fine, but am not sure how to
deal with solid object like a sphere from C++.
Isn't this more of a gnuplot question than a C++ question?
Sep 2 '08 #3
On Sep 2, 2:18*pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2008-09-02 19:46, mlt wrote:
Anyone has an idea to generate points for a solid sphere in C++ that can *be
plotted with gnuplot? I have tried to plot simple functions based on output
from a function written in C++ which worked fine, but am not sure how to
deal with solid object like a sphere from C++.

Just like you did with the function, you just have to add the third
dimension in the output, and figure out the correct gnuplot format.

--
Erik Wikström
hi
Sep 2 '08 #4
In article <48***********************@news.sunsite.dk>, af*@asd.com
says...
Anyone has an idea to generate points for a solid sphere in C++ that can be
plotted with gnuplot? I have tried to plot simple functions based on output
from a function written in C++ which worked fine, but am not sure how to
deal with solid object like a sphere from C++.
Generating the points isn't very hard, but by themselves, those will be
pretty useless -- if you just plot the points, there won't be a visible
difference between a sphere and a flat circle.

If you want to generate something recognizably sphere-like in gnuplot,
it's probably easier (and faster) to let gnuplot generate the points
itself anyway, something like this:

set nokey
set parametric
set hidden3d
set view 60
set isosamples 40, 30
set xrange[-2 : 2]
set yrange[-2 : 2]
set zrange[-1 : 1]
splot [-pi:pi][-pi/2:pi/2] cos(u)*cos(v), sin(u)*cos(v), sin(v)

This will give a wireframe model. If you _really_ want something that
looks like a solid surface, you'll need to do define lights and the
characteristics of the surface being modeled, then calculate the color
for each point on the surface. My immediate guess is that gnuplot won't
be of much help for this job -- you'd be much better off using something
like OpenGL that supports such things directly.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Sep 3 '08 #5
mlt

"Jerry Coffin" <jc*****@taeus.comskrev i en meddelelse
news:MP************************@news.sunsite.dk...
In article <48***********************@news.sunsite.dk>, af*@asd.com
says...
>Anyone has an idea to generate points for a solid sphere in C++ that can
be
plotted with gnuplot? I have tried to plot simple functions based on
output
from a function written in C++ which worked fine, but am not sure how to
deal with solid object like a sphere from C++.

Generating the points isn't very hard, but by themselves, those will be
pretty useless -- if you just plot the points, there won't be a visible
difference between a sphere and a flat circle.

If you want to generate something recognizably sphere-like in gnuplot,
it's probably easier (and faster) to let gnuplot generate the points
itself anyway, something like this:

set nokey
set parametric
set hidden3d
set view 60
set isosamples 40, 30
set xrange[-2 : 2]
set yrange[-2 : 2]
set zrange[-1 : 1]
splot [-pi:pi][-pi/2:pi/2] cos(u)*cos(v), sin(u)*cos(v), sin(v)

This will give a wireframe model. If you _really_ want something that
looks like a solid surface, you'll need to do define lights and the
characteristics of the surface being modeled, then calculate the color
for each point on the surface. My immediate guess is that gnuplot won't
be of much help for this job -- you'd be much better off using something
like OpenGL that supports such things directly.
'
Ok but how would you generate the data for a wireframe model of a sphere
from C++?
Sep 3 '08 #6
In article <48***********************@news.sunsite.dk>, af*@asd.com
says...

[ ... ]
Ok but how would you generate the data for a wireframe model of a sphere
from C++?
It depends on the exact sort of wire-frame you want. Obvious choices are
latitude-like lines, longitude-like lines, or both. Here's a bit of code
to generate some points that approximate a wire-frame (i.e. the points
are close together, but not really connected).

double d2r(double degrees) {
const double conversion = 3.1416f/180.0f;
return degrees * conversion;
}

void Sphere(double radius) {
for (int latitude=-90; latitude<90; latitude++) {
double current_radius = cos(d2r(latitude)) * radius;
double z = sin(d2r(latitude)) * radius;

// Every 10 degrees of latitude, draw a longitude line.
// Otherwise, draw a point every 10 degrees of longitude.
int increment = latitude % 10 ? 10 : 1;

for (int longitude=0; longitude<360; longitude+=increment) {
double x = cos(d2r(longitude))*current_radius;
double y = sin(d2r(longitude))*current_radius;
// (x,y,z) is a point in the wireframe
}
}
}

--
Later,
Jerry.

The universe is a figment of its own imagination.
Sep 5 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ¶}¾Ç¤F¶Ü? | last post by:
I'm trying to write a script to pass a file of stock prices and volumes, and plot the results on a gnuplot graph which is non-overlapped graph. Fig. 1 ------------ Fig. 2 Figure 1 is a graph...
2
by: Evagelia Tsiligianni | last post by:
Hello! I am trying to find a tool that can plot and print (plotted) data. I need it supports plotting dates as well. I 've tried wxPlot and chaco but each of them applies one of my requests...
3
by: Sloan | last post by:
I want to use MFC to plot Sin Wave . How can I do ?
24
by: Stavros Christoforou | last post by:
Hello everyone, I was wondering if someone could help me with an issue I have in C++. I want to select random points within the volume of a sphere. I know how to get random numbers using srand()...
30
by: nephish | last post by:
Hey there, i have tried about every graphing package for python i can get to work on my system. gnuplot, pychart, biggles, gdchart, etc.. (cant get matplot to work) so far, they all are working...
8
by: questions? | last post by:
I want to make a 3d plot. x is a vector(discrete), y is also a vector(discrete), for each pairwise x,y I have a value z(x,y)(it is not a function, just discrete values for each pair of x,y) I...
2
by: Rodrigo Lopez-Negrete | last post by:
Hi all, I'm trying to write a python script using plotting form pylab. Unfortunatelly I've encountered a problem. When I run the script via 'python myscript.py' the plot windows open and close...
3
by: Frank | last post by:
Hi, does anyone know if there is a way to plot a dendrogram with python. Pylab or matplotlib do not provide such a function. Thanks! Frank
2
by: itdevries | last post by:
Hi, I've been looking for a basic c++ 2D plot library to use with windows (and visual studio). I was a bit overwhelmed by all the options I found. Can someone here recommend a basic 2D plot...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.