1

I want to plot a 3D plot with discrete points which are derived by some math-expressions and values in the columns of a data file. My current gnuplot file looks like this:

set encoding utf8
set terminal postscript enhanced color
set output "3D.eps
set nokey
set parametric

set xlabel "X"
set ylabel "Y"
set zlabel "Z"

set title "So cool 3D plot"

fx = ($3) * (1 - ($4) * cos(u)) *(cos(($7)*pi/180)*cos(($6)*pi/180) - sin(($7)*pi/180)*sin(($6))*cos(($5)*pi/180))
fy = ($3) * (1 - ($4) * cos(u)) *(cos(($7)*pi/180)*sin(($6)*pi/180) + sin(($7)*pi/180)*cos(($6)*pi/180)*cos(($5)*pi/180))
fz = ($3) * (1 - ($4) * cos(u)) *(sin(($7)*pi/180) * sin(($5)*pi/180))

plot [u=0:2*pi] "file.txt" u fx:fy:fz t "yey"

Basically the information flow is like this:

1.) Load the file.txt and extract the values which are in the different coloumns

2.) Derive x-coordinate using the already read-in values. The x-coordinate is then dependent on the "time" variable 'u'

3.) Derive y-coordinate using the already read-in values. The y-coordinate is then also dependent on the "time" variable 'u'

4.) Derive z-coordinate using the already read-in values. The z-coordinate is then also dependent on the "time" variable 'u'

5.) plot for each line in "file.txt" the x,y,z-points for u=0...2pi

It's like a combination of parametric and datafile plot. However, my plotfile doesnt seem to work... can someone help me?

cheers,

Andre

1 Answer 1

2

Four problems: 1/ in using, you need parentheses around any expression which is not a cloumn number. 2/ When definining a function, it needs to depend explicitly at least on one parameter. 3/ The $ reference to columns can't be used in a function, either pass it as an argument or use the column routine. 4/ a for loop needs an integer variable

One option to correct all this is:

fx(u) = (column(3)) * (1 - (column(4)) * cos(u)) *(cos((column(7))*pi/180)*cos((column(6))*pi/180) - sin((column(7))*pi/180)*sin((column(6)))*cos((column(5))*pi/180))
fy(u) = (column(3)) * (1 - (column(4)) * cos(u)) *(cos((column(7))*pi/180)*sin((column(6))*pi/180) + sin((column(7))*pi/180)*cos((column(6))*pi/180)*cos((column(5))*pi/180))
fz(u) = (column(3)) * (1 - (column(4)) * cos(u)) *(sin((column(7))*pi/180) * sin((column(5))*pi/180))

plot [u=0:20] "file.txt" u (fx(pi*u/10.)):(fy(pi*u/10.)):(fz(pi*u/10.)) t "yey"

But you'll not be able to connect points with a line between different values of u, as the for loop is "exterior" of looping points in the datafile.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.