+ Reply to Thread
Results 1 to 10 of 10

Calculate Direction from U,V

  1. #1
    Registered User
    Join Date
    11-28-2012
    Location
    Newfoundland
    MS-Off Ver
    Excel 2010
    Posts
    21

    Calculate Direction from U,V

    Hi,

    I have the u,v component of ocean currents and I want to calculate the direction using excel. Can someone provide the formula and/or macro needed?

    Thanks in advance.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Calculate Direction from U,V

    Hi
    Personally, I have no idea what you are talking about. U, v are just letters so you'll have to explain some more.
    If you don't know what formula to use, how can an Excel forum be of help ? Perhaps first find the formula describing this physical property, we will be glad to translate it to Excel

  3. #3
    Registered User
    Join Date
    11-28-2012
    Location
    Newfoundland
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Calculate Direction from U,V

    Sorry, I should have clarified. For vector fields (such as winds, ocean currents), the zonal component (or x-coordinate) is denoted as u, while the meridional component (or y-coordinate) is denoted as v. The wind direction can be determined from the zonal (u)/meridional (v) components using the arctan function, but I haven't had any success. So, I was hoping someone on this forum has calculated wind/ocean current direction using the u/v components.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Calculate Direction from U,V

    Like pepe, I have no idea what this calc would look like If you were doint this by hand, what would the forumula look like?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Calculate Direction from U,V

    It sounds to me like a basic "how to convert rectangular to polar coordinates" type problem. (basic tutorial with a calculator here http://www.analyzemath.com/Calculators/Rect_Polar.html).

    You are correct that this usually involves the arctan function (=ATAN() and ATAN2() functions in Excel see help file here http://office.microsoft.com/en-us/ex...in=HP010342680). When you say you " haven't had any success." in what specific ways has it failed? Have you gotten error values back? Incorrect values? Excel's trig functions operate on angles in radians, are you looking for results in degrees and did not realize that Excel used radians? Perhaps if you can explain to us what you have done that has not worked, we can better help.

    On edit: Another thing to consider - by convention, the arctan function usually returns angles in the 1st and 4th quadrant (-pi/2 to +pi/2). Your directions can probably cover the entire circle, so you may need an additional step in the algorithm if the desired angle is in the 2nd and 3rd quadrants.
    Last edited by MrShorty; 01-21-2013 at 05:00 PM.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Registered User
    Join Date
    11-28-2012
    Location
    Newfoundland
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Calculate Direction from U,V

    Thanks MrShorty.

    Yes, I am looking for the direction in degrees, not radians. I found this equation (WDIR= 270-atan2(V,U)*180/pi), but it is not giving me the values I would expect.

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Calculate Direction from U,V

    What value is it returning for a given V,U and what value do you expect?

    Brief trig lesson for today. Recall from the very beginning of trigonometry (probably even studied in geometry) the concept of the unit circle, from which we derived the trig functions. Recall that all angles were measured from the positive x axis. positive angles were CCW from the x axis, negative angles are measured in a CW direction from the positive x axis.

    So the first step in understanding/developing/debugging this is to identify the direction of our unit vectors. According to Wikipedia, U is east-west and V is north-south. Is positive V due north or south? Is positive U due west or east?

    Remember that angles from the trig functions are increasing CCW. Compass directions, of course, are just the opposite. Compass directions start with due north being 0 and increase CW from there. Once we know which direction U and V are, then we can look at the result and see if we need to apply a transformation to the result to get the trig angle in radians converted to a global direction in degrees.

  8. #8
    Registered User
    Join Date
    11-28-2012
    Location
    Newfoundland
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Calculate Direction from U,V

    I was given the u,v components in a text file; previously, I had a program that would extract data from a GRIB file and within the code, it calculated the direction based on u and v. So, with a u value of 6.58 and v=-1.83, I should get a wind direction of 285 degrees. Using formulas I have found so far in excel, I get 164 degrees.

    To answer your question, positive u winds (zonal) are FROM the west, while positive v winds (meridional) are from the south.

  9. #9
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Calculate Direction from U,V

    So, we are looking at a polar/rectangular coordinate system with the following characteristics and analysis:

    1) we are treating V as X and u as Y.
    2) +V is due south, +U is due west.
    3) Constructing a unit circle in this system yields the following analysis. Recognizing that the ATAN2() function returns values between pi and -pi (explained in the help file linked to above), we can see that
    a) 0 is due south (180 compass)
    b) pi/2 (90) is due west (270 compass)
    c) pi (180) is due north (360 compass)
    d) -pi/2 (-90) is due east (90 compass)
    e) -pi (-180) is due north (0 compass)

    From this, it looks like a function of compass direction=180 +degrees(atan2(v,u)) should return the correct compass direction for a given V,U. If this isn't obvious, put the atan2() outputs and the corresponding compass points into a table and regress a straight line for them.

    The only hiccup I see is that the atan2() function will probably prefer to return +pi rather than -pi for due north (v<0, u=0), which means the function will prefer to return 360 rather than 0 for north. An IF function should be able to test and correct this condition if it is a real problem.

  10. #10
    Registered User
    Join Date
    11-28-2012
    Location
    Newfoundland
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: Calculate Direction from U,V

    Awesome, thank you so much. This equation worked perfectly. I really appreciate your help and detailed explanation.

    Thanks again.

    Brian

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1