View Full Version : Vector plots and contour lines..????

rakesh_thp

12-03-2009, 04:33 AM

Hello there,

I have following four column data with me..

Latitude, Longitude, U (velocity along x) and V (velocity along y)

Now using these data, I got to display vector plots where the velocities u and v are shown using arrows..

I am able to get the magnitude to be displayed... Now the problem is that i am not able to show the direction.. ( direction in terms of arrow) In other words how do i display an arrow at the head part of that vector.??

Second thing is that i have another set of data

Latitude, Longitude, and Depth..

Using these data, i need to display line contours.. Any slight initiation to solve this problem will be grateful...

Thanks in advance

david_m

12-03-2009, 09:15 AM

Hello,

If what you are trying to make is a 2D map, then you are only one glRotatef away from creating your vectors!

First you should glTranslatef(long.,lat.,0.0);

your rotation angle is theta=atan2(v,u) (atan2 found in most math libraries)

Then glRotatef(theta*180/pi,0.0,0.0,1.0);

(atan2 gives you the angle in radians, theta*180/pi changes to degrees, which opengl uses for rotations.)

Now your new x axis is aligned with your vector direction.

A GL_QUAD and a GL_TRIANGLE should be sufficient for a decent arrow.

So your code would be something like...

for (length of column of info) {

glLoadIdentity(); // always start at origin with no rotation

gltranslatef(long.,lat.,0.0); //current lat and long

theta=atan2(v,u);

glRotatef(theta*180/pi,0.0,0.0,1.0); // rotate about z

mag=pow(v*v+u*u,0.5); //magnitude of velocity vector

draw_arrow(mag) // function you make to draw arrow

};

glLoadIdentity(); // reset view

remember that your draw_arrow function is very simple since it will always draw an arrow pointing in the (local) x direction with magnitude mag.

Line contours are easy to do with GL_LINES

You can make some simple function to change line color as a function of depth like:

glColor3f(f1(depth),f2(depth),f3(depth)) // r,g,b, values

There are probably other (better) ways to do this but this is simple enough.

Of course, you need some logic checking routine to make the contours:

if (2 points have approximately the same depth) {

if(their is no point 'between' them with a different depth) {

draw a line between them with the appropriate color

};

};

If you are unfamiliar with any gl functions mentioned here, just google opengl tutorials and many will pop up (I recommend NeHe)

Hope this is helpful,

David

rakesh_thp

12-04-2009, 12:15 AM

Hi david..

Thanks for the quick reply.. I'll try the vector part.. Coming to the line contour, i have data as

lat, long and depth

as i mentioned above.. By any chance, do you mean to say that, i need to take all the lat/longs with the same depth value, and draw lines...??? if that is the case then, the total number of contour lines will be the same as that of total number of unique depths... Am i right..??

rakesh_thp

12-05-2009, 02:51 AM

hey, how to draw an arrow, with the help of mag..???

is it like this..??

glBegin(GL_LINES);

glVertex3f( long, lat, 0 );

glVertex3f( long+mag, lat+mag, 0 );

glEnd();

or any other technique is there to display..?? am unable to get any output... :(

david_m

12-08-2009, 10:03 AM

to draw an arrow, try:

glBegin(GL_QUADS);

glVertexf(0.0,-1.0,0.0);

glVertexf(mag,-1.0,0.0);

glVertexf(mag,1.0,0.0);

glVertexf(0.0,1.0,0.0);

glEnd();

glBegin(GL_TRIANGLES);

glVertexf(mag,-2.0,0.0);

glVertexf(mag,0.0,2.0);

glVertexf(mag,2.0,0.0);

glEnd();

in your previous post, no, the number of contour lines is not (necessarily) equal to the number of unique depths, although you could certainly make it so.

In general, you might not want to draw a 50 and 51 depth line, so you need some code to distinguish.

David

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.