Re: IDLgrPolygon unexpected result [message #83349] |
Thu, 28 February 2013 23:51 |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
On Thursday, February 28, 2013 5:51:41 AM UTC-8, David Fanning wrote:
> Dick Jackson writes:
>
>> Mesh_Obj, 1, verts, conn, FltArr(n, 2), P1=x ; Provide X values, receive verts and conn
>> verts[1, n:n+n-1] = y ; Set the desired Y values for the plot shape
>
> Wow! That is an *extraordinary* parsing of the MESH_OBJ documentation.
> On par with the best legal minds in the world. I'm impressed. I've read
> it over 10 times just this morning, and I'm *still* convinced it says do
> this:
>
> Mesh_Obj, 1, verts, conn, FltArr(n, 2), P1=x, P2=y
>
> Which, of course, doesn't work at all.
>
> Just out of curiosity, how long did you puzzle over this before the
> scales fell from your eyes? :-)
>
> Cheers,
> David
Why, thanks for asking... I've used Mesh_Obj a number of times, so I've trod this path before. Last time I used it was to make a little animated GIF of a 3-D rendering of my business logo for my home page (www.d-jackson.com). In case anyone's curious, I just added a link to the source code for djsclogo.pro, here using types 4, 5 and 6 to make spheres, cylinders and tori. Fun stuff! (I used the XObjView routines to arrange the snapshots for the animation frames, but that part could equally be done using Coyote or Function graphics)
Cheers,d
-Dick
Dick Jackson Software Consulting
Victoria, BC, Canada --- http://www.d-jackson.com
|
|
|
|
Re: IDLgrPolygon unexpected result [message #83375 is a reply to message #83373] |
Thu, 28 February 2013 05:51  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Dick Jackson writes:
> Mesh_Obj, 1, verts, conn, FltArr(n, 2), P1=x ; Provide X values, receive verts and conn
> verts[1, n:n+n-1] = y ; Set the desired Y values for the plot shape
Wow! That is an *extraordinary* parsing of the MESH_OBJ documentation.
On par with the best legal minds in the world. I'm impressed. I've read
it over 10 times just this morning, and I'm *still* convinced it says do
this:
Mesh_Obj, 1, verts, conn, FltArr(n, 2), P1=x, P2=y
Which, of course, doesn't work at all.
Just out of curiosity, how long did you puzzle over this before the
scales fell from your eyes? :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: IDLgrPolygon unexpected result [message #83377 is a reply to message #83375] |
Thu, 28 February 2013 05:22  |
lecacheux.alain
Messages: 325 Registered: January 2008
|
Senior Member |
|
|
Le mercredi 27 février 2013 19:41:58 UTC+1, nata a écrit :
> Hi guys,
>
>
>
> I am trying to create a polygon using the following set of points. I want my IDLgrPolygon to look like the plot so I add some vertices to close the shape.
>
>
>
> I don't understand what is going on here. I cannot get the polygon correctly. What am I missing?
>
>
>
> Thank you in advance for your help,
>
> nata
>
>
>
> x=[0.000,0.019,0.037,0.056,0.074,0.093,0.111,0.130,0.148,0.1 67,0.185,0.204,0.222,0.241,0.259,0.278,0.296,0.315,$
>
> 0.333,0.352,0.370,0.389,0.407,0.426,0.444,0.463,0.481,0.500, 0.519,0.537,0.556,0.574,0.593,0.611,0.630,0.648,$
>
> 0.667,0.685,0.704,0.722,0.741,0.759,0.778,0.796,0.815,0.833, 0.852,0.870,0.889,0.907,0.926,0.944,0.963,0.981,1.000]
>
>
>
> y=[0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.0 02,0.000,0.029,0.037,0.037,0.020,0.019,0.036,0.046,$
>
> 0.044,0.049,0.074,0.147,0.186,0.217,0.262,0.399,0.416,0.411, 0.391,0.577,0.459,0.376,0.318,0.387,0.316,0.431,$
>
> 0.421,0.318,0.413,0.628,0.665,0.541,0.714,0.536,0.594,0.606, 0.437,0.804,0.594,0.629,0.836,0.631,0.827,0.910,1.000]
>
>
>
> PLOT, x, y, /XS, /YS
>
>
>
> N=N_ELEMENTS(X)
>
>
>
> x=[0.,x,x[N-1],0]
>
> y=[0.,y,0.,0.]
>
>
>
> poly=OBJ_NEW('IDLgrPolygon',x,y)
>
> XOBJVIEW, poly
Since your (x,y) curve is increasing from [0,0] to [1,1], you can close it by simply adding the (1,0) point. Try this:
x=[0.000,0.019,0.037,0.056,0.074,0.093,0.111,0.130,0.148,0.1 67,0.185,0.204,0.222,0.241,0.259,0.278,0.296,0.315,$
0.333,0.352,0.370,0.389,0.407,0.426,0.444,0.463,0.481,0.500, 0.519,0.537,0.556,0.574,0.593,0.611,0.630,0.648,$
0.667,0.685,0.704,0.722,0.741,0.759,0.778,0.796,0.815,0.833, 0.852,0.870,0.889,0.907,0.926,0.944,0.963,0.981,1.000]
y=[0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.0 02,0.000,0.029,0.037,0.037,0.020,0.019,0.036,0.046,$
0.044,0.049,0.074,0.147,0.186,0.217,0.262,0.399,0.416,0.411, 0.391,0.577,0.459,0.376,0.318,0.387,0.316,0.431,$
0.421,0.318,0.413,0.628,0.665,0.541,0.714,0.536,0.594,0.606, 0.437,0.804,0.594,0.629,0.836,0.631,0.827,0.910,1.000]
pl = plot(x, y)
pol = polygon([x,x[-1]],[y,y[0]], /DATA, /FILL_BACKGROUND, FILL_COLOR='grey')
alain.
|
|
|
Re: IDLgrPolygon unexpected result [message #83378 is a reply to message #83377] |
Thu, 28 February 2013 01:03  |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
On Wednesday, February 27, 2013 10:41:58 AM UTC-8, nata wrote:
> Hi guys,
>
> I am trying to create a polygon using the following set of points. I want my IDLgrPolygon to look like the plot so I add some vertices to close the shape.
>
> I don't understand what is going on here. I cannot get the polygon correctly. What am I missing?
>
> Thank you in advance for your help,
>
> nata
Hi nata,
IDL's rendering of polygons can really only display triangles and quadrilaterals. What happens when you give a list of points [p0, p1, ... pn] to IDLgrPolygon is that it makes triangles of them using points [p0, p1, p2], then [p0, p2, p3], then [p0, p3, p4] and so on, which is what you saw as a result, and *not* what you want.
Imagine 54 squares side-by-side, so that each pair of neighbouring squares shares a side and two vertices (this is a strip of quadrilaterals, or a quad-strip). Then imagine leaving all the bottom vertices where they are, and pulling the top ones up or down to different heights to make the shape of your plot. That's how we'll make the polygon mesh that will be your filled plot.
A handy routine for making a quad-strip is Mesh_Obj. Its documentation is tricky, but it works. We use type 1 (rectangular), give it a bunch of zeroes for desired Z values, give it the vector of X values, and leave it to create Y values of 0 and 1. It returns 2*n points in a [3, 2*n] array of XYZ values (verts). All the y=0 points are first (rows 0..n-1), then the y=1 points follow (rows n..2*n-1). We set the desired Y values as a second step. We also get the connectivity array (conn) that describes which vertices to use for each quadrilateral, just the way IDLgrPolygon wants it.
To convince yourself of how it's built, in XObjView, choose View:Drag Quality:Low, then drag the mouse to see the wireframe showing the quadrilaterals.
x=[0.000,0.019,0.037,0.056,0.074,0.093,0.111,0.130,0.148,0.1 67,0.185,0.204,0.222,0.241,0.259,0.278,0.296,0.315,$
0.333,0.352,0.370,0.389,0.407,0.426,0.444,0.463,0.481,0.500, 0.519,0.537,0.556,0.574,0.593,0.611,0.630,0.648,$
0.667,0.685,0.704,0.722,0.741,0.759,0.778,0.796,0.815,0.833, 0.852,0.870,0.889,0.907,0.926,0.944,0.963,0.981,1.000]
y=[0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.0 02,0.000,0.029,0.037,0.037,0.020,0.019,0.036,0.046,$
0.044,0.049,0.074,0.147,0.186,0.217,0.262,0.399,0.416,0.411, 0.391,0.577,0.459,0.376,0.318,0.387,0.316,0.431,$
0.421,0.318,0.413,0.628,0.665,0.541,0.714,0.536,0.594,0.606, 0.437,0.804,0.594,0.629,0.836,0.631,0.827,0.910,1.000]
PLOT, x, y, /XS, /YS
N=N_ELEMENTS(X)
Mesh_Obj, 1, verts, conn, FltArr(n, 2), P1=x ; Provide X values, receive verts and conn
verts[1, n:n+n-1] = y ; Set the desired Y values for the plot shape
poly = OBJ_NEW('IDLgrPolygon', verts, Polygons=conn)
XObjView, poly
Hope this helps!
-Dick
Dick Jackson Software Consulting
Victoria, BC, Canada --- http://www.d-jackson.com
|
|
|
|
Re: IDLgrPolygon unexpected result [message #83381 is a reply to message #83380] |
Wed, 27 February 2013 12:23  |
DavidF[1]
Messages: 94 Registered: April 2012
|
Member |
|
|
On Wednesday, February 27, 2013 12:48:55 PM UTC-7, Coyote wrote:
> On Wednesday, February 27, 2013 12:43:00 PM UTC-7, nata wrote:
>
>> So, any ideas David ?
>
>>
>
>>
>
>>
>
>> I am not sure to understand what are you saying... right hand - left hand rules.. if you see the values of the X vertices, they are increasing, from 0 to 1.
>
>>
>
>> That should be ok from my point of view. I tried to use a smaller set of vertices and it works. I am missing something here...
>
>
>
> Well, I tried this:
>
>
>
> x=[0,1.0,reverse(x)]
>
> y=[0,0.0,reverse(y)]
>
> cgPLOT, x, y, /XS, /YS, color='red'
>
> cgcolorfill, color='blue', x, y
>
> poly=OBJ_NEW('IDLgrPolygon',x,y)
>
> XOBJVIEW, poly
>
>
>
> And this doesn't work either. :-)
This works, so the data must be going into the Polygon object correctly.
a=[0,1.0,reverse(x)]
b=[0,0.0,reverse(y)]
cgPLOT, a, b, /XS, /YS, color='red'
cgcolorfill, color='blue', a, b
poly=OBJ_NEW('IDLgrPolygon',a,b)
XOBJVIEW, poly
poly ->GetProperty, data=d
p = idlgrplot(d[0,*], d[1,*])
xobjview, p
David
|
|
|
Re: IDLgrPolygon unexpected result [message #83382 is a reply to message #83381] |
Wed, 27 February 2013 11:48  |
DavidF[1]
Messages: 94 Registered: April 2012
|
Member |
|
|
On Wednesday, February 27, 2013 12:43:00 PM UTC-7, nata wrote:
> So, any ideas David ?
>
>
>
> I am not sure to understand what are you saying... right hand - left hand rules.. if you see the values of the X vertices, they are increasing, from 0 to 1.
>
> That should be ok from my point of view. I tried to use a smaller set of vertices and it works. I am missing something here...
Well, I tried this:
x=[0,1.0,reverse(x)]
y=[0,0.0,reverse(y)]
cgPLOT, x, y, /XS, /YS, color='red'
cgcolorfill, color='blue', x, y
poly=OBJ_NEW('IDLgrPolygon',x,y)
XOBJVIEW, poly
And this doesn't work either. :-)
Don't know. Sorry.
David
|
|
|
Re: IDLgrPolygon unexpected result [message #83383 is a reply to message #83382] |
Wed, 27 February 2013 11:43  |
natha
Messages: 482 Registered: October 2007
|
Senior Member |
|
|
So, any ideas David ?
I am not sure to understand what are you saying... right hand - left hand rules.. if you see the values of the X vertices, they are increasing, from 0 to 1.
That should be ok from my point of view. I tried to use a smaller set of vertices and it works. I am missing something here...
Bernat
On Wednesday, February 27, 2013 2:34:23 PM UTC-5, Coyote wrote:
> On Wednesday, February 27, 2013 11:41:58 AM UTC-7, nata wrote:
>
>> Hi guys,
>
>>
>
>>
>
>>
>
>> I am trying to create a polygon using the following set of points. I want my IDLgrPolygon to look like the plot so I add some vertices to close the shape.
>
>>
>
>>
>
>>
>
>> I don't understand what is going on here. I cannot get the polygon correctly. What am I missing?
>
>
>
> I'm no expert in this area, but it looks to me like you have created your polygon using the left-hand rule, rather than the expected right-hand rule. Thus, you are looking at the back of your polygon, rather than the front. It is pretty important with polygons that you get the normal facing the viewer.
>
>
>
> Cheers,
>
>
>
> David
|
|
|
Re: IDLgrPolygon unexpected result [message #83384 is a reply to message #83383] |
Wed, 27 February 2013 11:34  |
DavidF[1]
Messages: 94 Registered: April 2012
|
Member |
|
|
On Wednesday, February 27, 2013 11:41:58 AM UTC-7, nata wrote:
> Hi guys,
>
>
>
> I am trying to create a polygon using the following set of points. I want my IDLgrPolygon to look like the plot so I add some vertices to close the shape.
>
>
>
> I don't understand what is going on here. I cannot get the polygon correctly. What am I missing?
I'm no expert in this area, but it looks to me like you have created your polygon using the left-hand rule, rather than the expected right-hand rule. Thus, you are looking at the back of your polygon, rather than the front. It is pretty important with polygons that you get the normal facing the viewer.
Cheers,
David
|
|
|