[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Common point puzzle

Bil Kleb

12/21/2006 1:26:00 AM

Warning: the following really needs a sketch.

I have a series of three (x,y) grids with values, z,
at each point. Each successive grid is twice as fine
as the previous, i.e., dx1 = 2 * dx2 = 4 * dx3.

For a series of three nested grids, I'd like to compute
(z2-z1)/(z3-z2) at each of the points shared between all
three grids, i.e., at all the points of the coarsest grid.

The catch? The (x,y) points are not ordered in the same
fashion for each grid. In other words, I need find the
(x,y) coordinate shared by all three for each point in
the coarsest grid.

Now, I can do this with a bunch of conditional checks,
but I thought it might be possible to use Ruby's set
functions or Array intersection in some elegant way to
create some sort of a mask that I could overlay the medium
and fine grids with to find the coincident points.

Thanks for reading this far,
--
Bil Kleb
http://fun3d.lar...
8 Answers

M. Edward (Ed) Borasky

12/21/2006 2:14:00 AM

0

Bil Kleb wrote:
> Warning: the following really needs a sketch.
>
> I have a series of three (x,y) grids with values, z,
> at each point. Each successive grid is twice as fine
> as the previous, i.e., dx1 = 2 * dx2 = 4 * dx3.
>
> For a series of three nested grids, I'd like to compute
> (z2-z1)/(z3-z2) at each of the points shared between all
> three grids, i.e., at all the points of the coarsest grid.
>
> The catch? The (x,y) points are not ordered in the same
> fashion for each grid. In other words, I need find the
> (x,y) coordinate shared by all three for each point in
> the coarsest grid.
>
> Now, I can do this with a bunch of conditional checks,
> but I thought it might be possible to use Ruby's set
> functions or Array intersection in some elegant way to
> create some sort of a mask that I could overlay the medium
> and fine grids with to find the coincident points.
>
> Thanks for reading this far,
Are these grids large enough that brute force in-core solutions are
ruled out? :)

--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blo...

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.


Bil Kleb

12/21/2006 2:33:00 AM

0

M. Edward (Ed) Borasky wrote:
>
> Are these grids large enough that brute force in-core solutions are
> ruled out? :)

Unfortunately, I don't understand the question.

Regards,
--
Bil Kleb
http://fun3d.lar...

William James

12/21/2006 2:52:00 AM

0

Bil Kleb wrote:
> Warning: the following really needs a sketch.
>
> I have a series of three (x,y) grids with values, z,
> at each point. Each successive grid is twice as fine
> as the previous, i.e., dx1 = 2 * dx2 = 4 * dx3.
>
> For a series of three nested grids, I'd like to compute
> (z2-z1)/(z3-z2) at each of the points shared between all
> three grids, i.e., at all the points of the coarsest grid.
>
> The catch? The (x,y) points are not ordered in the same
> fashion for each grid. In other words, I need find the
> (x,y) coordinate shared by all three for each point in
> the coarsest grid.
>
> Now, I can do this with a bunch of conditional checks,
> but I thought it might be possible to use Ruby's set
> functions or Array intersection in some elegant way to
> create some sort of a mask that I could overlay the medium
> and fine grids with to find the coincident points.
>
> Thanks for reading this far,
> --
> Bil Kleb
> http://fun3d.lar...

What is the layout of the array? Something like this?

[ [x1,y1,z1], [x2,y2,z2] ... ]

Devin Mullins

12/21/2006 2:55:00 AM

0

Bil Kleb wrote:
> M. Edward (Ed) Borasky wrote:
>> Are these grids large enough that brute force in-core solutions are
>> ruled out? :)
> Unfortunately, I don't understand the question.
The naive implementation is n^2 (with n being the number of gridpoints),
and simply iterates over the coarsest grid, each time finding the
matching points in the two others. That code's destined not to look to
ugly (possibly helped with clever application of #zip or sth? dunno),
but if you have stricter speed requirements...

(Not the OP.. just taking a crack at a translation.)

Devin

Bil Kleb

12/21/2006 12:21:00 PM

0

William James wrote:
>
> What is the layout of the array? Something like this?
>
> [ [x1,y1,z1], [x2,y2,z2] ... ]

No, not currently, but it could be made to look that way
with some zip action.

Currently, each grid is in a separate hash that contains
variable_name => [ array of values ]

Regards,
--
Bil Kleb
http://fun3d.lar...

Bil Kleb

12/21/2006 12:26:00 PM

0

Devin Mullins wrote:
> The naive implementation is n^2 (with n being the number of gridpoints),
> and simply iterates over the coarsest grid, each time finding the
> matching points in the two others.

That's going to be my route unless someone comes up
with a nifty array intersection sort of solution.

Speed is not a requirement, yet.

Thanks,
--
Bil Kleb
http://fun3d.lar...

F. Senault

12/21/2006 1:10:00 PM

0

Le 21 décembre à 13:21, Bil Kleb a écrit :

> William James wrote:
>>
>> What is the layout of the array? Something like this?
>>
>> [ [x1,y1,z1], [x2,y2,z2] ... ]
>
> No, not currently, but it could be made to look that way
> with some zip action.
>
> Currently, each grid is in a separate hash that contains
> variable_name => [ array of values ]

Couldn't you make three hashes with the structure h["#{x}x#{y}"] = z ?

After that, you get the keys of the coarse grid and fetch the datapoints
of the others directly.

If you format the x and y in the hash key, you can even order them içf
needed...

Fred
--
Do you know how far this has gone ? Just how damaged have I become ?
When I think I can overcome It runs even deeper
Everything that matters is gone All the hands of hope have withdrawn
Could you try to help me hang on ? (Nine Inch Nails, Even Deeper)

William James

12/21/2006 3:00:00 PM

0

F. Senault wrote:
> Le 21 décembre à 13:21, Bil Kleb a écrit :
>
> > William James wrote:
> >>
> >> What is the layout of the array? Something like this?
> >>
> >> [ [x1,y1,z1], [x2,y2,z2] ... ]
> >
> > No, not currently, but it could be made to look that way
> > with some zip action.
> >
> > Currently, each grid is in a separate hash that contains
> > variable_name => [ array of values ]
>
> Couldn't you make three hashes with the structure h["#{x}x#{y}"] = z ?
>
> After that, you get the keys of the coarse grid and fetch the datapoints
> of the others directly.
>
> If you format the x and y in the hash key, you can even order them içf
> needed...

I think you'd only need to make the hashes for the medium and for the
fine grid. Then you'd iterate through the points in the course grid,
checking to see if each point is in both of the hashes.

And the keys to the hashes could be arrays:
h[ [x,y] ] = z