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 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

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...

[edit] using your notation:

HorizontalSpeed = sine(b) * S

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

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

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.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi

Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464

posted

0

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)

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

SCJP1.4--91%<br />IBM 399

Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464

posted

0

You lot are brilliant - thanks.

This has to be one of the smartest communities on the net. I feel my inferiority complex kicking in