# Re: Filling colors in Delaunay triangles

From: Roshil Paudyal <p.roshil1994_at_nyahnyahspammersnyahnyah>
Date: Mon Jul 08 2013 - 09:38:09 MDT

Hi,

I tried that but it still doesn't solve the problem. Using polyline gives
good results; so I don't think there is anything wrong in the rest of the
code. The problem must lie somewhere in executing the gsn_polygon function.

It would be great if you could run this script once, which may make the
problem clearer. It does give some output; but that is very different from
what is expected (or what polyline gives). I have already attached the only
datafile I used (illdt1).

Thank you,
Roshil

On Mon, Jul 8, 2013 at 10:38 AM, Adam Phillips <asphilli@ucar.edu> wrote:

> Hi Roshil,
> I believe you have to enclose a complete polygon for gsn_polygon to work.
> In other words, the first and last latitude/longitude points are usually
> the same. Also, you need to make sure that you are advancing the frame at
> the end of your script.
>
> Try changing this:
>
> qlat = new(3,float)
> qlon = new(3,float)
> gsres@gsEdgesOn = True
> gsres@gsEdgeColor = 4
> gsres@gsFillColor = False
> do np=0,num_triangles-1
> qlat(0) = lat_in(triangles(np,0))
> qlon(0) = lon_in(triangles(np,0))
> qlat(1) = lat_in(triangles(np,1))
> qlon(1) = lon_in(triangles(np,1))
> qlat(2) = lat_in(triangles(np,2))
> qlon(2) = lon_in(triangles(np,2))
> gsn_polygon(wks,map,qlon,qlat,gsres)
> end do
>
> to this:
>
> qlat = new(4,float)
> qlon = new(4,float)
> gsres@gsEdgesOn = True
> gsres@gsEdgeColor = 4
> gsres@gsFillColor = False
> do np=0,num_triangles-1
> qlat(0) = lat_in(triangles(np,0))
> qlon(0) = lon_in(triangles(np,0))
> qlat(1) = lat_in(triangles(np,1))
> qlon(1) = lon_in(triangles(np,1))
> qlat(2) = lat_in(triangles(np,2))
> qlon(2) = lon_in(triangles(np,2))
> qlat(3) = qlat(0)
> qlon(3) = qlon(0)
> gsn_polygon(wks,map,qlon,qlat,gsres)
> end do
> frame(wks)
>
>
> If that does not solve the problem, please respond to ncl-talk to let
> everyone know.
>
>
> On 07/07/2013 11:31 AM, Roshil Paudyal wrote:
>
> Hi,
>
> I am trying to plot some data on a sphere and create a Delaunay
> triangulation out of it and fill colors into each of the triangles using a
> custom color map. Following code does a good job of creating the
> triangulation: (ncl v. 6.1.2 in cygwin)
>
>
>
> begin
>
> NARC = 50
>
> id_in = jps(1:100,0)
> lat_in = jps(1:100,1)
> lon_in = jps(1:100,2)
> dt_in = jps(1:100,3)
> N = 100
>
>
> gsres = True
>
>
> ; Create the triangulation.
> ;
> triangles = csstri(lat_in,lon_in)
> tri_sizes = dimsizes(triangles)
> num_triangles = tri_sizes(0)
>
>
>
> cmap = (/ \
> (/ 1., 1., 1. /), \
> (/ 0., 0., 0. /), \
> (/ 1., 0., 0. /), \
> (/ 0., 0., 1. /), \
> (/ 1., 0., 0. /), \
> (/ 0., 1., 0. /), \
> (/ 0., .8, 0. /), \
> (/ .65, .65, .65 /) \
> /)
>
> NCGM=1
> X11=0
> PS=0
> PDF=0
>
> if (NCGM .eq. 1) then
> wks = gsn_open_wks("ncgm","nm21n")
> end if
> if (X11 .eq. 1) then
> wks = gsn_open_wks("x11","nm21n")
> end if
> if (PS .eq. 1) then
> wks = gsn_open_wks("ps","nm21n")
> end if
> if (PDF .eq. 1) then
> wks = gsn_open_wks("pdf","nm21n")
> end if
> gsn_define_colormap(wks,cmap)
>
>
>
> ;
> ; Draw a globe
> ;
> map_resources = True
> map_resources@gsnFrame = False
> map_resources@mpOutlineBoundarySets = "National"
> map_resources@mpNationalLineColor = 1
> map_resources@mpGeophysicalLineColor = 7
>
> map_resources@mpLimbLineColor = 7
> map_resources@mpGridLineColor = 0
> map_resources@mpGridAndLimbDrawOrder = "PreDraw"
>
> map_resources@mpCenterLatF = 40.
> map_resources@mpCenterLonF = -105.
> map_resources@vpXF = 0.06
> map_resources@vpYF = 0.90
> map_resources@vpWidthF = 0.88
> map_resources@vpHeightF = 0.88
> map_resources@mpSatelliteDistF = 4.0
>
> map_resources@mpGreatCircleLinesOn = True
>
> map = gsn_map(wks,"Satellite",map_resources)
>
>
>
> ; Draw the triangles.
> ;Ignore the blue for now
>
> qlat = new(4,float)
> qlon = new(4,float)
> gsres@gsLineColor = 5
> do np=0,num_triangles-1
> qlat(0) = lat_in(triangles(np,0))
> qlon(0) = lon_in(triangles(np,0))
> qlat(1) = lat_in(triangles(np,1))
> qlon(1) = lon_in(triangles(np,1))
> qlat(2) = lat_in(triangles(np,2))
> qlon(2) = lon_in(triangles(np,2))
> qlat(3) = lat_in(triangles(np,0))
> qlon(3) = lon_in(triangles(np,0))
> gsn_polyline(wks,map,qlon,qlat,gsres)
> end do
>
> end
>
> However, is there a way to fill colors into the triangles created using
> polylines? I didn't find any. So, I thought maybe I could give the end
> points of triangles as an input to gsn_polygon. If that created the
> triangles, that would have given me a full set of resources to modify,
> including the fill colors. So, I replaced the blue part with the following
> code:
>
> qlat = new(3,float)
> qlon = new(3,float)
> gsres@gsEdgesOn = True
> gsres@gsEdgeColor = 4
> gsres@gsFillColor = False
> do np=0,num_triangles-1
> qlat(0) = lat_in(triangles(np,0))
> qlon(0) = lon_in(triangles(np,0))
> qlat(1) = lat_in(triangles(np,1))
> qlon(1) = lon_in(triangles(np,1))
> qlat(2) = lat_in(triangles(np,2))
> qlon(2) = lon_in(triangles(np,2))
> gsn_polygon(wks,map,qlon,qlat,gsres)
> end do
>
> But this doesn't even create all the triangles. So, is there a way to
> fix this problem? I have attached the data I used for this (illdt1.txt).
>
>
> Thank you,
> Roshil
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> --
> ______________________________________________________________
> NCAR/Climate and Global Dynamics Division (303) 497-1726
> P.O. Box 3000
> Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli
>
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jul 8 09:38:23 2013

This archive was generated by hypermail 2.1.8 : Fri Jul 12 2013 - 16:37:39 MDT