NCAR / nclcomp

0 stars 0 forks source link

Problem with gc_clkwise with Pacific Ocean coordinates [NCL-1699] #2

Open khallock opened 5 years ago

khallock commented 5 years ago

The following demonstrates two large simple polygons over the Pacific ocean. Both are written in clockwise order, yet the function gc_clkwise returns the wrong value for the first polygon.

lats = (/ 15, 40, 0, -30, -30 /)
lons = (/ 150, 210, 260, 265, 160 /)
func = gc_clkwise (lats, lons)
print ("Result #1 = " + func)

lons(3) = 250
func = gc_clkwise (lats, lons)
print ("Result #2 = " + func)
mac56:~/ncl/bugs/gc_clkwise 63> ncl demo.gc_clkwise.ncl
NCAR Command Language Version 6.1.2
(0) Result #1 = False
(0) Result #2 = True

I believe that both polygons conform to the documented constraint that each must be containted in a hemisphere. We get the same behavior with NCL 6.0.0 and 6.1.2 on Mac OS 10.8.3, 64-bit x86 CPU. Am I mistaken, or is this a bug in the function? Thanks for looking into this.

khallock commented 5 years ago

A slight variation ..... If the following is done

lats = (/ 15, 40, 0, -30, -30 /)
lats = lats + 30

Both return False!

khallock commented 5 years ago

I am using NCL 6.3.0 on recent versions of both Mac OS and Linux. gc_clkwise returns the wrong value for this simple clockwise polygon:

ncl 1> lats=(/8,15,5,0/)
ncl 2> lons=(/38,130,130,38/)
ncl 3> print (gc_clkwise(lats,lons))
(0) False

However, the correct value is returned for the same polygon, with the order of coordinates simply rotated by one position:

ncl 4> lats=(/0,8,15,5/)
ncl 5> lons=(/38,38,130,130/)
ncl 6> print (gc_clkwise(lats,lons))
(0) True

This may be related to a similar gc_clkwise problem that was assigned to JIRA NCL-1699. Please add this case to that ticket. Thank you.