Be Excellent To Each Other

And, you know, party on. Dude.

All times are UTC [ DST ]




Reply to topic  [ 19 posts ] 
Author Message
 Post subject: Maths!
PostPosted: Thu Mar 19, 2009 15:07 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69809
Location: Your Mum
You've got a square with sides S long. I don't know S, and it's likely going to change periodically.
The top-left grid reference is -180, 85.
The centre is 0, 0.
The bottom-right is 180, -85;

I know X and Y, and if X is 0 it needs to map to the far left, and if X = S then it needs to map to the far right.
The same for Y, 0 = top and S = bottom.

So. What calculations do I have to perform on X and Y to get them to map properly? My brain is tired and now I'm hungry, so I'll see if someone has an answer when I get back with my lunch.

(It's probably not hard to guess which of my other threads today relate to this)

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 15:10 
User avatar
Comfortably Dumb

Joined: 30th Mar, 2008
Posts: 12034
Location: Sunny Stoke
Grim... wrote:
(It's probably not hard to guess which of my other threads today relate to this)


You're going to do your own Street View program?

_________________
Consolemad | Under Logic
Curse, the day is long
Realise you don't belong


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 15:18 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69809
Location: Your Mum
No answers? I expected the geeks to be slobbering over this one.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 15:21 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
Grim... wrote:
No answers? I expected the geeks to be slobbering over this one.
I didn't want to type it out then find Mr Dave had already done it.

Why do you say S can change, then give us the numbers?


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 15:27 
Excellent Member

Joined: 30th Mar, 2008
Posts: 489
Assuming you have 'S' as a variable?

MapWidth = 360
MapHeight = 170

SWidth = 100
SHeight = 100

Sx = 50
Sy = 50

Mapx = ((MapWidth/SWidth)*Sx)-(MapWidth/2)
Mapy = ((MapHeight/SHeight )*Sy)-(MapHeight/2)

does that seem right?


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 15:29 
User avatar

Joined: 31st Mar, 2008
Posts: 1883
-180 + (X/S)*180*2

and

85 - (Y/S)*85*2.

I think.


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 15:34 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69809
Location: Your Mum
Thanks, all!
I have used:
x = ((x-(s/2))/s)*360;
y = (((y-(s/2))/s)*170)*-1;

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 16:47 
User avatar
Paws for thought

Joined: 27th Mar, 2008
Posts: 17161
Location: Just Outside That London, England, Europe
Doctor Glyndwr wrote:
Grim... wrote:
No answers? I expected the geeks to be slobbering over this one.
I didn't want to type it out then find Mr Dave had already done it.


Alas, I have only just arrived, and am too late.


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 16:54 
User avatar
Paws for thought

Joined: 27th Mar, 2008
Posts: 17161
Location: Just Outside That London, England, Europe
Grim... wrote:
Thanks, all!
I have used:
x = ((x-(s/2))/s)*360;
y = (((y-(s/2))/s)*170)*-1;


How frequently would you use them, as that could be fairly easily optimised. For a start z*170*-1 = z*-170.

360/s, -170/s and s/2 could also be precalculated and stored, avoiding most of those division ops division ops frequently. Or indeed I'd imagine you can take the reciprocal, and avoid them altogether.


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 18:01 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69809
Location: Your Mum
Only about (max) 30 times per page load, so optimisation isn't really an issue.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 18:03 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
I would expect my compiler to take care of such basic arithmatic re-ordering optimisations like that.


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 18:04 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69809
Location: Your Mum
/kicks Javascript

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 18:10 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
Grim... wrote:
/kicks Javascript
It still gets compiled and it still gets optimised. Where do you think all these massive 10x-20x-30x speedups are coming from in modern browsers?


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 18:12 
User avatar
Hibernating Druid

Joined: 27th Mar, 2008
Posts: 49434
Location: Standing on your mother's Porsche
Doctor Glyndwr wrote:
Where do you think all these massive 10x-20x-30x speedups are coming from in modern browsers?


Migrant workers?

_________________
SD&DG Illustrated! Behance Bleep Bloop

'Not without talent but dragged down by bass turgidity'


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 18:22 
User avatar
Paws for thought

Joined: 27th Mar, 2008
Posts: 17161
Location: Just Outside That London, England, Europe
Doctor Glyndwr wrote:
I would expect my compiler to take care of such basic arithmatic re-ordering optimisations like that.


Only in certain circumstances though - And that isn't just reordering, it relies on s being constant, not something your compiler would always assume, it's somewhat context dependant, the kind of thing aliasing would play havoc with.


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 19:16 
User avatar
Peculiar, yet lovely

Joined: 30th Mar, 2008
Posts: 7046
I find the answer is usually to start crying. Hope this helps!

_________________
Lonely as a Mushroom Cloud


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 22:34 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69809
Location: Your Mum
Fuck, I can't think today!
Right, same thing, except now I've got he answer (somewhere between -180:85 and 180:-85) and I want X and Y in regards to S (which I still know). So basically, the same thing again, but backwards.
Why is my brain so dumb?

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 22:37 
User avatar
Worst

Joined: 30th Mar, 2008
Posts: 6197
sinister agent wrote:
I find the answer is usually to start crying. Hope this helps!

Yes. It helped me laugh this evening.

_________________
>Image<


Top
 Profile  
 
 Post subject: Re: Maths!
PostPosted: Thu Mar 19, 2009 22:41 
User avatar

Joined: 30th Mar, 2008
Posts: 32624
x'= ((x+180)/360)S
y'= ((y+85)/170)S

(obv you can expand brackets to prevent mr dave upset)


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 19 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search within this thread:
You are using the 'Ted' forum. Bill doesn't really exist any more. Bogus!
Want to help out with the hosting / advertising costs? That's very nice of you.
Are you on a mobile phone? Try http://beex.co.uk/m/
RIP, Owen. RIP, MrC. RIP, Dimmers.

Powered by a very Grim... version of phpBB © 2000, 2002, 2005, 2007 phpBB Group.