Results 1 to 5 of 5

Thread: Vector plots and contour lines..????

  1. #1
    Member Contributor
    Join Date
    Jun 2009
    Posts
    60

    Vector plots and contour lines..????

    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

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    9

    Re: Vector plots and contour lines..????

    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

  3. #3
    Member Contributor
    Join Date
    Jun 2009
    Posts
    60

    Re: Vector plots and contour lines..????

    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..??

  4. #4
    Member Contributor
    Join Date
    Jun 2009
    Posts
    60

    Re: Vector plots and contour lines..????

    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...

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    9

    Re: Vector plots and contour lines..????

    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

Similar Threads

  1. How to get contour lines on 3D volume
    By billywen88 in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 02-20-2015, 02:10 PM
  2. Rendering Contour Lines
    By Richard145 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-22-2006, 03:31 AM
  3. 'stepped' contour plots ?
    By joolz in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 07-18-2005, 10:48 PM
  4. CAE Coloured Stress Contour Plots - Efficient, Faster Way
    By cellox in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 03-09-2003, 11:42 AM
  5. CAE Coloured Stress Contour Plots - Efficient, Faster Way
    By cellox in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-07-2003, 09:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean