How to transpose spatial coordinates into an array

Hello everyone,

I want to start off by apologizing if this is an improper use of the forums. At first glance, this didn't seem like a terrible place to ask this question.

I've been asked to code a script that will take data from a set of spatial coordinates (essentially a probe moving around inside of a body), and arrange it into an array so that it can be visualized digitally.

Is this a terribly difficult thing to do? Or could I start learning how to build this script from scrap right now? I have taken a few C++ classes that weren't very heavy coding intensive, but were very instructive and I learned a lot, so I think I'm in place to at least direct my learning how I see fit to accomplish what I need to do.

Thoughts?

How does the data look like?
How should the array look like?
What kind of visualization? Plots?
I have to ask my coordinator and get back to you, I'll reply within the next 24 hours. I appreciate your response.
So the data looks like this. I'm not sure how to make any sense of it, but they basically just want to plot it in 3d so they can look at in in 3d.


PHI =0:dPHI:num_of_turns*2*pi;
Z = Z0+c*(PHI)/2/pi;

X = R0.*cos(PHI)*scale;
Y = R0.*sin(PHI)*scale;
Z = (Z+Zstart)*scale;
hold on
plot3(X,Y,Z)
axis equal
coords_all = [X' Y' Z'];

%%%%%helix export in .csv format
csvwrite([filename,'.csv'],coords_all)



%%%%%%%%%%%%%%% G CODE MAKING %%%%%%%%%%

%%%%%%%% Calculation of linear displacement of pump plunger
dist=0;
for i=2:length(X)
dist=dist+sqrt((X(i)-X(i-1))^2+(Y(i)-Y(i-1))^2+(Z(i)-Z(i-1))^2);
end
pump_dist= dist/speed*flowrate/3600/dia;
pump_step=pump_dist/(length(X)-1);


A = [0:pump_step:((length(X)-1)*pump_step)];


fid=fopen([filename,'.job'],'wt'); % starts the .job file


gcode=['G21'];%chage the units to mm %%% use G20 in case of inches
count=fprintf(fid,'%s\n',gcode);

%set the first coordinate point to zero
gcode=['G92 X' ,num2str(X(1),'%6.3f') , ' Y' ,num2str(Y(1),'%6.3f') , ' Z' ,num2str(Z(1),'%6.3f') , ' A' ,num2str(A(1),'%6.5f')];
count=fprintf(fid,'%s\n',gcode);

%first coordinate point + speed
gcode=['G1 X' ,num2str(X(1),'%6.3f') ,' Y' ,num2str(Y(1),'%6.3f'),' Z' ,num2str(Z(1),'%6.3f') ,' A' ,num2str(A(1),'%6.5f') ,' F' , num2str(speed*60,'%2g') ];
count=fprintf(fid,'%s\n',gcode);

%rest of the code
for line=2:length(X)
gcode=['G1 X' ,num2str(X(line),'%6.3f') ,' Y' ,num2str(Y(line),'%6.3f') ,' Z' ,num2str(Z(line),'%6.3f') ,' A' ,num2str(A(line),'%6.5f')];
count=fprintf(fid,'%s\n',gcode);
end

fclose(fid);
You did say "a set of spatial coordinates". However, the "data" that you do show, does look like code that writes a CSV-like file.

Let me guess, the file looks like (if we omit the first two lines):
G1 X10.477 Y-0.832 Z23.565 A.01462
G1 X 9.940 Y-0.573 Z22.178 A.01288
G1 X10.558 Y 0.730 Z21.737 A.01212
G1 X11.407 Y 1.297 Z22.444 A.01159

With a minor edit that becomes a table that gnuplot can read:
http://lowrank.net/gnuplot/plot3d2-e.html


No C++ is required.
closed account (48T7M4Gy)
gnuplot or sagemath - gnuplot is way better - is the way to go once the data file has been prepared properly, perhaps using the code above.

If you want to write the code from the ground up then you'll need something like the functionality of opengl to do the graphics etc.

Qt might have something along these lines all ready to integrate c++ basic programming with a windows/graphics library. (gnuplot uses this)
So you're saying that if I put those lines of code into gnuplot, it will operate on the code and create a 3d spatial array and plot it for me?
closed account (48T7M4Gy)
You should checkout gnuplot (or sagemath)

a) If you have the data then provided it is readable by gnuplot then it will display that data in 3d.
e.g. http://lowrank.net/gnuplot/plot3d2-e.html
http://www.gnuplotting.org/plotting-data/

b) If you don't have 3d data and just the mathematical function for an object then you can program gnuplot to plot that.
http://lowrank.net/gnuplot/plot3d-e.html as above
http://www.gnuplotting.org/plotting-functions/

Whichever one you are attempting 2d and 3d capabilities are the same. You can check them out, they're easy to find.

There is a lot of reference material on the web if you want to interface gnuplot with c++ :)


Last edited on
kemort wrote:
If you have the data then provided it is readable by gnuplot

Adding to that: since it seems that you can modify the code that writes the data to a file, you can change the file format to make it readable by gnuplot.
Topic archived. No new replies allowed.