noshenim

Last Login:
May 25, 2013
Warn:

Rank:
Member
Member Points:
50


User Profile
Follow

Hits: 28,076
Joined April 30, 2006
Games (5)

ludakill
June 15, 2006
Robot Killer
February 20, 2007
techno slalom
August 20, 2006
Neo
March 22, 2007
Circle Pong Combo
March 15, 2007
Examples (6)

shooting
May 03, 2006
Smooth platforming
June 07, 2008
versatile time lines
June 10, 2010
Graphing Calculator
July 21, 2010
Intercepting moving objects
August 25, 2010
Quality window resizing
September 05, 2010
Favorite Users
Dev - Sort these by name
Favorite Games


how to convert co-ordinates into spiral# thing.?
Posted on July 12, 2010 at 13:36

\~There's a way to convert an integral co-ordinate field into a spiral index number..

I want to convert 10,000 different co-ordinates with a range of over 1000 ( from (0,0) to more than (1000,1000) ) into single integers (just 'cause :P).
The number and maximum range of the co-ordinates is variable.

Does anyone know what this is called or how to do this efficiently?


So (2,1) would become 9, (1,1)-->8, (2,2)-->24, etc.

reminder: http://fuldans.se/


Dev - Warning
Dev - After editing rating, make rating display change
Dev - When editing, update "edited" column
Dev - Restore deleted comments
Dev - Display deleted comments if mod (hidden, then with dropdown)
Dev - After deletion or during edit, make rating dropdown appear again
Dev - Stricter rating rules. Prevent user from rating again
Dev - Pages
Dev - Reporting
Interesting question. I'll work on it now.
Posted by Juju July 12, 2010 14:03 - 2.9 years ago
| [#01]

Interesting challenge. Might work on it later this day.
Posted by sirxemic July 12, 2010 14:08 - 2.9 years ago
| [#02]

thanks ^.^
Posted by noshenim July 12, 2010 14:14 - 2.9 years ago
| [#03]

Solution:

if (abs(x)>abs(y))
{
if (x < 0) return 4*x*x-x+y; else return 4*x*x-3*x-y;
}
else
{
if (y < 0) return 4*y*y+y-x; else return 4*y*y+3*y+x;
}
Posted by sirxemic July 12, 2010 14:54 - 2.9 years ago
| [#04]

0 lies at co-ordinate (0,0)
1 lies at co-ordinate (1,0)
2 lies at co-ordinate (1,1)
The numbers 1 to 8 inclusive lie on ring 1.
The numbers 9 to 24 inclusive lie on ring 2.

The numbers along the x-axis (that is: 1, 10, 27, 52, 85 et cetera) are defined by 4n^2 - 3n where n is the ring number.

The formula for working out which ring n a number x lies on is as follows: n = ipart( ( 3 + sqrt(9 + 16x) ) / 8 )
Mathematical ipart() is the same as programming floor()

That's the maths behind it anyway. sirXemic has got the implementation.
Posted by Juju July 12, 2010 14:59 - 2.9 years ago
| [#05]

Quote
Mathematical abs() is the same as programming floor()

Wut.

Also, wut @ your maths. I didn't approach it that way =P
EDIT: I just realized your maths is useful for calculating the other way around.
Posted by sirxemic July 12, 2010 15:26 - 2.9 years ago
| [#06]

Whoops, I mean ipart not abs.
Posted by Juju July 12, 2010 16:17 - 2.9 years ago
| [#07]

genius :o

I wonder how to make this work in 3 dimensions.
Posted by noshenim July 12, 2010 21:57 - 2.9 years ago
| [#08]

I forgot that I need to reverse this function... any help?

Quote

if (abs(x)>abs(y))
{
if (x < 0) return 4*x*x-x+y; else return 4*x*x-3*x-y;
}
else
{
if (y < 0) return 4*y*y+y-x; else return 4*y*y+3*y+x;
}
Posted by noshenim July 13, 2010 1:11 - 2.9 years ago
| [#09]

"return 4*x*x-x+y; else return 4*x*x-3*x-y;"

Just wondering, does the x-3 need to be in parentheses or not? Otherwise, you could have -12*x*x*x-y.
Posted by Avenger July 13, 2010 2:10 - 2.9 years ago
| [#10]

To both of you - work it out yourselves. You're not gonna get better at this unless you do some work.
Posted by Juju July 13, 2010 4:42 - 2.9 years ago
| [#11]

Quote
I wonder how to make this work in 3 dimensions.

I wonder how you would make a 3D spiral similar to that 2D one.

Quote
Just wondering, does the x-3 need to be in parentheses or not? Otherwise, you could have -12*x*x*x-y.

Of course not. They would be there if they needed to.
Posted by sirxemic July 13, 2010 13:23 - 2.9 years ago
| [#12]

Maybe I could run the function twice:
Quote

f(f(x,y),z)
Posted by noshenim July 13, 2010 21:00 - 2.9 years ago
| [#13]

Ingenious! Juju, I applaud your ingenuity.
Posted by Ross July 23, 2010 12:13 - 2.8 years ago
| [#14]

Recent Activity
 
Active Users (0)