Rick Beaver

Ranch Hand

Posts: 464

posted 11 years ago

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

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

ph34r my 133t j4v4 h4><0r1ng sk177z

posted 11 years ago

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.

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

posted 11 years ago

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

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

ph34r my 133t j4v4 h4><0r1ng sk177z

posted 11 years ago

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 ]

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

Stan James

(instanceof Sidekick)

Ranch Hand

Ranch Hand

Posts: 8791

posted 11 years ago

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

Posts: 464

posted 11 years ago

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

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

ph34r my 133t j4v4 h4><0r1ng sk177z

Sachin Satija

Greenhorn

Posts: 28

posted 11 years ago

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

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

Posts: 464