# [ncl-talk] understanding function gc_pnt2gc

Joe Grim grim at ucar.edu
Thu Aug 10 10:41:37 MDT 2017

```I wonder if gc_pnt2gc uses the entire great circle around the globe, and
not just the shortest section between the two points defining the great
circle, in calculating the distance.

On Thu, Aug 10, 2017 at 10:39 AM, Joe Grim <grim at ucar.edu> wrote:

> Alan,
>
> That is a great workaround for this problem!  I'll try your approach
> unless I can find a way to get gc_pnt2gc to work the way I want it to.
>
> I looked up the source code, which is located at ncl/ni/src/lib/nfpfort/sg_tools.f,
> under FORTRAN function XDPGCDP, and was written by David Kennison.  It
> would take me a while to figure it all out, so hopefully your workaround is
> fast enough for my purposes.
>
> Thanks again!
>
> Joe
>
> On Thu, Aug 10, 2017 at 9:55 AM, Alan Brammer <abrammer at albany.edu> wrote:
>
>> As another person who uses gc_latlon extensively but didn't know
>> gc_pnt2gc existed.
>>
>> You could use gc_latlon to recreate gc_pnt2gc().  Definitely seems like
>> that function is doing some weird stuff.
>> Though this wouldn't be directional but that could be worked out
>> relatively easily.
>>
>>
>>
>> p_lat = 41.6
>> p_lon = -76.84
>>
>> lat = (/52.9921,55.3543/)
>> lon = (/-168.693,-160.346/)
>> dist = gc_pnt2gc(p_lat,p_lon,lat,lon)
>>
>> line         = gc_latlon( lat(0), lon(0), lat(1), lon(1), 1000, 2)
>>   ;; create the GC path
>> distances =  gc_latlon(p_lat, p_lon, line at gclat, line at gclon, 0, 2)  ;;
>> find distances to GC path
>> shortest   = minind(distances)
>>
>> print ("The gc_pnt2gc distance is: " + dist)
>> print ("The gc_latlon distance is: " + distances(shortest) )
>>
>> ; The gc_pnt2gc distance is: -0.105952
>> ; The gc_latlon distance is: 53.5385
>>
>> On Thu, Aug 10, 2017 at 10:46 AM, Joe Grim <grim at ucar.edu> wrote:
>>
>>> Thank you, Dennis.  Yes, I have used the gc_latlon function many times;
>>> it is very useful!
>>>
>>> But, I am hoping to use a function that finds the distance between a
>>> point, and where it is closest to a line.  If I can't, I'll just have to
>>> write my own function in FORTRAN instead to do that.
>>>
>>> Hopefully someone else is familiar with the *gc_pnt2gc* function.
>>>
>>> Joe
>>>
>>> On Thu, Aug 10, 2017 at 8:12 AM, Dennis Shea <shea at ucar.edu> wrote:
>>>
>>>> Hi Joe,
>>>>
>>>> I have never used the '*gc_pnt2gc*' function. Hopefully, somebody will
>>>>
>>>> There us an alternative:
>>>>   https://www.ncl.ucar.edu/Document/Functions/Built-in/gc_latlon.shtml
>>>>
>>>> Try the following interactively
>>>>
>>>> %> ncl <return>
>>>> Then enter the following
>>>>
>>>> p_lat = 41.6
>>>> p_lon = -76.84
>>>> lat = (/52.9921,55.3543/)
>>>> lon = (/-168.693,-160.346/)
>>>> dist = gc_latlon(p_lat,p_lon,lat,lon,10,2)
>>>> print(dist)
>>>>
>>>> Variable: dist
>>>> Type: float
>>>> Total Size: 8 bytes
>>>>             2 values
>>>> Number of Dimensions: 1
>>>> Dimensions and sizes:   [2]
>>>> Coordinates:
>>>> Number Of Attributes: 4
>>>>   units :       degrees
>>>>   gclon :       <ARRAY of 20 elements>
>>>>   gclat :       <ARRAY of 20 elements>
>>>>   spacing :     ( 6.551194, 5.948726 )
>>>>
>>>> (0)     58.96074
>>>> (1)     53.53853
>>>>
>>>> ===
>>>> Cheers
>>>> D
>>>>
>>>>
>>>> On Wed, Aug 9, 2017 at 1:21 PM, Joe Grim <grim at ucar.edu> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I have used the function gc_pnt2gc, but it doesn't appear to be doing
>>>>> what I think it should be doing.  I assume this is because I am
>>>>> misunderstanding it.  What I think it does is give the distance in degrees
>>>>> between a lat/lon point (p_lat, p_lon), and its closest approach to the
>>>>> great circle line between two other lat/lon pairs (lat[2], lon[2]: and I
>>>>> assume that this great circle line is the shortest greatest circle line
>>>>> between these lat/lon pairs.)  Here is an example snippet of what I am
>>>>> trying to do:
>>>>>
>>>>>  p_lat = 41.6
>>>>>  p_lon = -76.84
>>>>>  lat = (/52.9921,55.3543/)
>>>>>  lon = (/-168.693,-160.346/)
>>>>>  dist = gc_pnt2gc(p_lat,p_lon,lat,lon)
>>>>>  print ("The distance is: " + dist)
>>>>>
>>>>> Here is the output:
>>>>> (0)     The distance is: 0.105952
>>>>>
>>>>> I would expect the distance to be something around 53 degrees.
>>>>>
>>>>> Could someone please explain to me what I am misunderstanding about
>>>>> this function?  And, do you know of another function that does what I am
>>>>> trying to do?  (That is, find the shortest distance between a point and a
>>>>> line on the Earth.)
>>>>>
>>>>> Thank you!
>>>>>
>>>>> Joe Grim
>>>>>
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> ncl-talk at ucar.edu
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>
>>>>>
>>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170810/f92e5538/attachment.html
```