+ Reply to Thread
Results 1 to 8 of 8

Rounding Vectors based on length of line

Hybrid View

  1. #1
    Registered User
    Join Date
    06-18-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2002
    Posts
    7

    Rounding Vectors based on length of line

    I am seeking a function that can round the angle of a vector based on the length of line of that vector.

    The parameters I require are as follows:

    1. If the length of the vector is less than 250 then round the respective angle to the nearest 10 seconds
    2. If the length of the vector is between 251 to 500 then round the respective angle to the nearest 5 seconds
    3. If the length of the vector is greater than 501m do not round the respective angle

    The vectors are in the following format:

    295° 41' 17" 949.393

    Note there is a space after the ° and ‘ symbols and furthermore the angle and distance values are in separate cells.

    Currently I am using the substitute function to format the angle without symbols i.e. 295.4117.

    See below.

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"° ","."),"' ",""),"""","")
    I then round these values using the MROUND function which requires individual analysis of each vector and therefore is time consuming.

    Any advice or assistance to speed up this process would be much appreciated.

    Thanks in advance.
    Last edited by jeffreybrown; 06-19-2012 at 06:40 PM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,396

    Re: Rounding Vectors based on length of line

    I think, rather than combine degrees/minutes/seconds into one "number", I'd try to separate them out. This would be pretty easy with the Text to Columns command on the Data menu.

    Then, you can use the =vlookup() function to return the multiple to round the seconds to. Something like =vlookup(949.393,{0,10;251,5;501,1})
    Then, as you noted, use the MROUND function to get the rounding. =MROUND(17,vlookup(949.393,{0,10;251,5;501,1},2)) should return 17.

    Replace the values with references to cells with those values as desired. It might also be preferable to pull the lookup table out and have it in the spreadsheet rather than hard coded into the function.

    At this point, it would be easy enough to use the concatenate function to put it back into the 0° 0' 0'' format if desired.

  3. #3
    Registered User
    Join Date
    06-18-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2002
    Posts
    7

    Re: Rounding Vectors based on length of line

    Thank you MrShorty.

    I based the function I will now use on your recommendations.

    The desired format of the angle is without symbols. The reason being is it can then be imported directly into the survey software I use.

    Therefore I used a combination of your recommendation and my initial attempt.

    The end result is:

    =(MROUND(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(L4,"° ","."),"' ",""),"""",""),VLOOKUP(M4,{0,0.001;251,0.0005;501,0.0001},2)))

    where L4 contains the angle value and M4 the distance value.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Rounding Vectors based on length of line

    What does that round 59 seconds to?
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    06-18-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2002
    Posts
    7

    Re: Rounding Vectors based on length of line

    I am picking up what you are putting down.

    The function I am using generates a false result in this circumstance.

    Do you have a solution?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Rounding Vectors based on length of line

    Are the angles always positive?

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Rounding Vectors based on length of line

    Assuming so,

          -----A------ --B--- ---C----
      1      Angle     Length  Result 
      2   295° 41' 58"    100 295.4200
      3   295° 41' 57"    250 295.4155
      4   295° 41' 57"    500 295.4157
    The formula in C2 and down is

    =TEXT(MROUND(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2, "° ", ":"), "'", ":"), """",""), LOOKUP(B2,{0,250,500}, {10,5,1}/86400)), "[h].mmss")

    That returns a string. You could instead use

    =MROUND(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2, "° ", ":"), "'", ":"), """",""), LOOKUP(B2,{0,250,500}, {10,5,1}/86400))

    and format the result as [h].mmss

  8. #8
    Registered User
    Join Date
    06-18-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2002
    Posts
    7

    Re: Rounding Vectors based on length of line

    SHG

    Both options work great. Thanks heaps.

+ 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