+ Reply to Thread
Results 1 to 7 of 7

Interpolating in a spherical triangle

  1. #1
    Registered User
    Join Date
    08-22-2017
    Location
    Virginia, United States
    MS-Off Ver
    16.0.8326.2076
    Posts
    16

    Interpolating in a spherical triangle

    Hello gurus,

    I'm not sure if this is the best place to start with these questions, because they're really more related to mathematics, but I've got a good feeling y'all will help. Right now I'm really looking more for some input on how I'm planning to approach the problem rather than the code itself. I'd like to give people the opportunity to suggest alternatives before I pour my heart into this.... I have searched far and wide for similar questions/solutions, but nothing seems to fit quite right.

    Here's the scenario:

    I have a set of about 200 Lat/Long points each with an associated value of some magnitude, B. These points represent "stations" where data is collected.

    The desire is for an end user to enter in any Lat/Long point, Pw, and have a value B returned that is interpolated from the known values....below is how I plan to interpolate this value:

    1. Calculate the distances from each data point to Pw using the haversine formula

    2. Define data points P1 and P2 as the two closest points to Pw

    3. Define data point Pn as the next closest point that satisfies the criteria: Pw is in triangle P1P2Pn (note: I plan to use haversine distances for proximity, but lat long values to test that Pw is enveloped, is there anything wrong with that logic?)

    4. Calculate the distances P1P2, P2P3, P1P3, P1Pw and P2Pw using the haversine formula

    5. "flatten" the triangle (generate cartesian coordinates) that honor the distances calculated in step 4 (I think this skews distance P3Pw, not sure how problematic that is)

    6. Now that my triangle is flat, and all points are located, use barycentric coordinates and interpolate B for Pw


    How convoluted is this? Is there any accuracy to this? What would be the magnitude of error if all my data points are in the same state and I just used Lat/Long coords and jumped to barycentric coordinates?

    My search for answers keeps leading me to dissertations and abstracts as if this is some unsolved paradox, but it seems like the answer should be simple... (simpler than my logic)


    ANY help is appreciated, and I will post code as I write it once I get some feedback.

    Thanks guys!

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,352

    Re: Interpolating in a spherical triangle

    Hi Ihargr2,

    I've learned that when you have a hard problem, make one that is similar and easier. So to solve this problem I'd attack it like this. I assume we are talking about 3 space, perhaps air pressure at different locations on earth. I'd start with a flat cartesian plane and pick 3 points and millibar hights above those 3 points. How about (x,y,z) (z is the heights above the XY plane. Try (0,0,0), (3,5,2) and (0,2,6). Now pick your Pw point on the cartesian plane like point (1,2) and you need to find interpolated Z. If you can't do this problem then the harder one above, you can't do either. I'd guess the Z number by drawing a picture and GUESS an ANSWER. I'd guess Z is 3 knowing it wrong. Now how do I show it isn't 3? By showing it isn't 3 builds the formulas to find what it really is.

    It seems to me staying in 3 space without using spherical geometry is a first step. The 3 given points above define a unique plane. Then where does (1,2) project onto this plane? Does the projection on the plane need to be orthoginal to the xy plane or orthoginal to the newly defined plane?? Do these with simple numbers and diagrams.

    NOW - is the 3d (non spherical) answer correct? Do you really need to do spherical geometry? Will it add accuracy?

    I hope the above suggestions helps solve the bigger problem.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    08-22-2017
    Location
    Virginia, United States
    MS-Off Ver
    16.0.8326.2076
    Posts
    16

    Re: Interpolating in a spherical triangle

    MarvinP, I appreciate the strategy. Solving your example problem with pencil and paper helped me to understand the barycentric component of the problem, and for what it's worth, I arrive at 5/3 as the final answer. My biggest qualm with keeping it this simple are units. Using lat and long as if they are Cartesian values doesn't seem wise. Because I'm enjoying the learning experience, I'd like to keep this spherical, and have started to code it with the same basic approach I previously outlined. I made it pretty far before my first snag. Please see the attached spreadsheet.

    Here's my new scenario:

    1. A haversine UDF is used to calculate the distance from each data point to my target point in a helper column

    2. Another UDF for testing if a point is in the triangle created by the three data points is defined

    3. a Third UDF defines the station names and coordinates, using the 2 closest data points, while finding a third that satisfies the triangle test.

    My problem is, in my code, if I define i as any value and delete the Do Until Loop then I get expected results. As soon as I add the Loop statement and try to call the PTINPOLY function I get #VALUES.

    What's wrong with my Loop?

    Please Login or Register  to view this content.
    BDE Testing.xlsm

  4. #4
    Registered User
    Join Date
    08-22-2017
    Location
    Virginia, United States
    MS-Off Ver
    16.0.8326.2076
    Posts
    16
    Can someone have a look, please? If I can troubleshoot the Loop I think I can finish this thing!

  5. #5
    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: Interpolating in a spherical triangle

    I think you might Google kriging with irregularly spaced data. See, for example, http://amath.colorado.edu/faculty/kl...leiber2015.pdf
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    08-22-2017
    Location
    Virginia, United States
    MS-Off Ver
    16.0.8326.2076
    Posts
    16

    Re: Interpolating in a spherical triangle

    Thanks for the link, shg. Looks like I have some studying to do! In the meantime, could you please look at the Do Until Loop... Even if my approach is flawed, this is eating me up. Each UDF works independently, and I can manually change i until I arrive at a solution, but I can't get it to iterate without #VALUE!s

    I think it's a simple syntax error, but I'm guessing at this point.

    Please Login or Register  to view this content.
    ....full code in previous post

  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: Interpolating in a spherical triangle

    I don't know what's wrong with your code, but it is inefficient.

    Instead of calculating this

    Please Login or Register  to view this content.
    a zillion times, just sort the rows by distance from the top row, take rows 2 and 3 as the closest two points, then continue down the list until you find a point that makes a triangle that encloses the first.

    You can step through the code to find what's causing the error.
    Last edited by shg; 05-13-2018 at 05:38 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. interpolating factors
    By Farnarkler in forum Excel General
    Replies: 2
    Last Post: 01-20-2009, 12:31 PM
  2. interpolating
    By Farnarkler in forum Excel General
    Replies: 6
    Last Post: 10-16-2008, 09:19 AM
  3. interpolating graph
    By calypso in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 08-11-2008, 10:54 AM
  4. Interpolating data
    By ebill in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-08-2008, 12:45 PM
  5. Interpolating an x, y point from known x's and y's
    By Steve in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-27-2006, 03:10 PM
  6. [SOLVED] Interpolating an x, y point from known x's and y's
    By Steve in forum Excel General
    Replies: 3
    Last Post: 06-26-2006, 01:20 PM
  7. [SOLVED] Interpolating an x, y point from known x's and y's
    By Steve in forum Excel General
    Replies: 1
    Last Post: 06-25-2006, 01:50 PM
  8. [SOLVED] Excel 2003 charting circular or spherical coordinates
    By Scott @ Nordion in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 04-07-2005, 10:06 AM

Tags for this Thread

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