 programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Junilu Lacar
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• Jeanne Boyarsky
• Rob Spoor
• Bear Bibeault
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Piet Souris
• Carey Brown
• Stephan van Hulst
Bartenders:
• Frits Walraven
• fred rosenberger
• salvin francis

# Math help

Ranch Hand
Posts: 464
• • Number of slices to send:
Optional 'thank-you' note:
• • Hi all

I am writing a simple boat simulation and I am stuck on one part of calculating a boats speed / position. Please can someone help me with an equation?

Given a fixed speed (lets call it S - in metres per second) and a given bearing ( call it B - 0-359) - can anyone please tell me what calculation will tell me how many metres North (+ve or -ve) and how many metres East (+ve or -ve) the boat moves per second

I am sure there is rinky dink fangled equation for this - but I didn't do well in Math

Thanks guys

Trailboss Posts: 23328   • • Number of slices to send:
Optional 'thank-you' note:
• • I've done something like this: given a polygon defined with a series of lat/long points, determine the square kilometers.

The trick is that as you get further from the equator, the distance between 0 degrees and 1 degree east gets smaller.

So the answer I'm giving you is that this is not a quick, simple thing.

Rick Beaver
Ranch Hand
Posts: 464
• • Number of slices to send:
Optional 'thank-you' note:
• • Hi Paul

Thanks for responding - I am modelling this on a theoretically flat planet so I am not taking into account any real-world variations etc. I am assuming a steady course at a constant speed for a fixed period of time. The stuff you mentioned is way over my head I just wanted to make a little boat gif move about on a JPanel I think what I am looking for is something like "The square on the hypotenuse is equal to the sum of the squares of the other two sides" but based on only knowing the angle of the triangle and the length of the hypotenuse - yeah, I know, I should have listened in class lowercase baba Posts: 12993
66   • • Number of slices to send:
Optional 'thank-you' note:
• • it's been a while, but you want the sine and the cosine of the angle. asuming 0 is due north, and you go around clockwise, the sine(angle) * speed will give you the horizontal speed, and the cosine(angle) * speed will give you the vertical.

i think...

HorizontalSpeed = sine(b) * S

VerticalSpeed = cosine(b) * S
[ December 22, 2005: Message edited by: fred rosenberger ]

(instanceof Sidekick)
Posts: 8791
• • Number of slices to send:
Optional 'thank-you' note:
• • If you're working on a flat plain (not the real earth) you might need to convert to polar coordinates to move and then back to cartesian. The math is over my head (music major) but I managed to use the constructs my dad gave me (math prof) to do some neat 3D motion stuff in Pascal in a former life.

Rick Beaver
Ranch Hand
Posts: 464
• • Number of slices to send:
Optional 'thank-you' note:
• • I think that was it Fred - thanks.

If my boat is on a bearing of 30 degrees and travels 10 metres per second

(sine 30) * 10 = 5 metres East
(cosine 30) * 10 = 8.66 metres North

That seems just about perfect to me.

Follow on question - why does 30 sin on a calculator give me 0.5 (correct) but Math.sin(30) gives me -0.9880316240928618 (wrong)

I appreciate all the help Thanks again

Greenhorn
Posts: 28
• • Number of slices to send:
Optional 'thank-you' note:
• • Originally posted by Rick Beaver:
I think that was it Fred - thanks.
Follow on question - why does 30 sin on a calculator give me 0.5 (correct) but Math.sin(30) gives me -0.9880316240928618 (wrong)

I appreciate all the help Thanks again

Beacuse the sine function in math class takes radians as parameters. But you can use Math.sin(Math.toRadians(30)) to achieve the same.

Sachin

Rick Beaver
Ranch Hand
Posts: 464
• • Number of slices to send:
Optional 'thank-you' note:
• • You lot are brilliant - thanks.

This has to be one of the smartest communities on the net. I feel my inferiority complex kicking in fred rosenberger
lowercase baba Posts: 12993
66   • • Number of slices to send:
Optional 'thank-you' note:
• •  