-
Pumpkin Carving 2008
Stupid pythagorean decimal time question...
All I'm trying to do is calculate how long it takes an object to reach it's target on a grid. delta would be √(a^2 + b^2).
So, say on this map starting position is -152, 15. Target is -153, 17:
Code:
sp = new Point(-152, 15);
tp = new Point(-153, 17);
speed = 14;
dx = Math.abs(sp.x - tp.x);
dy = Math.abs(sp.y - tp.y);
d = Math.sqrt(dx*dx + dy*dy);
dt = d/speed; // (√5) / 14;
// rest of math here
At this point speed becomes a factor. I've found the hypotenuse and now dividing it by speed (unit tiles/hour in this case) to see how long it would take in a decimal form. I do not how to reach the answer, but a rough estimate by an online calculator gave me 9 minutes, 35 seconds.
I kind of have this theory in my head that you take dt and multiply it by 60 to give you minutes (if it's over 60 reduce by 60 and increment hours), then you remove the base value and take just the left side of the decimal point, multiply it by 60 again and that's your seconds (if over 60 reduce by sixty and increment minutes). For some sad reason, I keep getting the wrong answer (and I'm even taking physics studying torque on rigid objects and circular motion). Anyone wanna take a stab?
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Please, Call Me Bob
Not sure why you'd be getting the wrong answer
Well if the calculator is right then this code should also be correct:
Code:
hours=Math.floor(dt);
minutes=Math.floor(dt*60);
seconds=Math.round((dt*60-minutes)*60);
EDIT: I think you mean "remove the base value and take just the right side of the decimal point"... yes?
You wouldn't have to increment anything because the stuff to the right of the decimal is less than 1, so multiplying it by 60 will never produce something greater than 60
Last edited by trogdor458; 03-25-2009 at 11:17 PM.
-
Pumpkin Carving 2008
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|