[Date Index]
[Thread Index]
[Author Index]
resorting coordinates after the rotations
*To*: mathgroup at smc.vnet.net
*Subject*: [mg14027] resorting coordinates after the rotations
*From*: Tatyana Polenova <tatyana at chem.columbia.edu>
*Date*: Wed, 16 Sep 1998 14:12:06 -0400
*Sender*: owner-wri-mathgroup at wolfram.com
Hi,
I have the following problem: I generate a 2-dimensional grid of points
that represent x,y-cartesian coordinates. Separately I have a list of
numbers (z-coordinates that I would later like to use in a contour
plot) which will be mapped to the grid of x,y-coordinates. I create a
function that rotates the grid matrix by a certain angle. Now I need to
display a contour plot of the z-values in terms of the new rotated x,y
coordinates. Obviously, after the rotation the new matrix of x,y-
coordinates is not sorted anymore. To be able to display the contour
plot I need to resort the matrix of the coordinates in a conventional
way. WHat would be the best way to do that? Below there is an example
of what I wrote so far: _________
Grid11[horiz_, vert_]:=Table[Table[{k,l},{l,1, horiz}], {k,1,vert}];
GridRot[Grid1_,angle_]:=
Floor[Table[
Table[Rotate2D[Grid1[[m,n]],N[angle], {1.,1.}], {n,1,
Length[Grid1[[1]]]}],{m,1,Length[Grid1]}]];
grida=Grid11[5,5];
In[9]:=
gridb=GridRot[grida,3 Pi/4]
Out[9]=
{{{1,1},{1,0},{2,-1},{3,-2},{3,-2}},{{0,0},{1,-1},{1,-2},{2,-2},{
3,-3}},{{-1,-1},{0,-2},{1,-2},{1,-3},{2,-4}},{{-2,-2},{-1,-2},{0,-3},{
1,-4},{1,-4}},{{-2,-2},{-2,-3},{-1,-4},{0,-4},{1,-5}}}
Shift[gridd_]:=Block[{},
horizmin=
Min[Table[
Table[#[[m,n,2]]&@gridd,{n,Length[gridd[[1]]]}],{m,
Length[gridd]}]];
vertmin=
Min[Table[
Table[#[[m,n,1]]&@gridd,{n,Length[gridd[[1]]]}],{m,
Length[gridd]}]];
Table[Table[{gridd[[m,n,1]]+Abs[vertmin]+1,gridd[[m,n,2]]+Abs[horizmin]+1},{
n,Length[gridd[[1]]]}],{m,Length[gridd]}]]
(this will shift the grid in such a way that there won't be negative
coordinates)
In[12]:=
gridc=Shift[gridb]
Out[12]=
{{{4,7},{4,6},{5,5},{6,4},{6,4}},{{3,6},{4,5},{4,4},{5,4},{6,3}},{{2,5},{3,
4},{4,4},{4,3},{5,2}},{{1,4},{2,4},{3,3},{4,2},{4,2}},{{1,4},{1,3},{2,
2},{3,2},{4,1}}}
After this step I will map the z-values into the rotated grid:
FTGridCombo=
Table[Table[{gridc[[m,n,1]],gridc[[m,n,2]],zvalues[[m,n]]},{n,
Length[gridc[[1]]]}],{m,Length[gridc]}];
Now I will have to resort the x,y coordinates in a conventional way, so
that it will be a table of the form:
{{{1,3},{1,4}},{{2,2},{2,4},{2,5}},{{3,3},{3,4},{3,6}},{{4,1},{4,2},{4,
2},...etc.
What would be the best way to do this? There is also a problem that
contour plot accepts only rectangular matrices mXn, but obviously after
rotation the matrix won't look like this anymore. To bring it back to
the conventional form I simply filled the missing parts with zeros:
cnt1a:=Block[{},
temp=Table[
Join[Table[
0,{n,Ceiling[Length[cnt1[[31]]]/2]-Ceiling[Length[cnt1[[j]]]]/2}],
cnt1[[j]],
Table[0,{n,
Ceiling[Length[cnt1[[31]]]/2]-Ceiling[Length[cnt1[[j]]]]/2}]], {
j,Length[cnt1]}];
temp1=Table[Length[temp[[n]]], {n, Length[temp]}];
temp2=Max[temp1];
Table[Join[temp[[n]], Table[0,{temp2-Length[temp[[n]]]}]], {n,
Length[temp]}]]
But it seems to me that this approach is very cumbersome... Would there
be a better approach? Is it possible to display non-rectangular
matrices using ListContourPlot?
sorry for such a long message and thank you very much for your time.
Tatyana
Prev by Date:
**how to replace a list of variables**
Next by Date:
**Re: list referencing with [[]][[]]**
Previous by thread:
**Re: how to replace a list of variables**
Next by thread:
**Linear Algebra and Matrix Manipulation Archives?**
| |