`speed()`

positive), shouldn't```
if (gearState() == -1)//reverse gear
{
position.X += (Int32)(speed() * Math.Sin(theta * Math.PI / 180));
position.Y
```**<big>+=</big>** (Int32)(speed() * Math.Cos(theta * Math.PI / 180));
}

do the trick?

:)

See more:

hi everyone

I want to write a program that simulate a car .

I have a problem with calculating position in the reverse gear

this is my code in forward gear:

theta is the angle of wheels of the car

-45<angle<45

primary position of car is in (800,500) in the form

if (gearState() == 1)//forward gear

{

position.X += (Int32)(speed() * Math.Sin(theta * Math.PI / 180));

position.Y -= (Int32)(speed() * Math.Cos(theta * Math.PI / 180));

}

this code work very good but doesn't work in reverse gear.

when theta=20 and car is in reverse gear car goes to the left instead of going right

do you have any idea ?

please help me

I want to write a program that simulate a car .

I have a problem with calculating position in the reverse gear

this is my code in forward gear:

theta is the angle of wheels of the car

-45<angle<45

primary position of car is in (800,500) in the form

if (gearState() == 1)//forward gear

{

position.X += (Int32)(speed() * Math.Sin(theta * Math.PI / 180));

position.Y -= (Int32)(speed() * Math.Cos(theta * Math.PI / 180));

}

this code work very good but doesn't work in reverse gear.

when theta=20 and car is in reverse gear car goes to the left instead of going right

do you have any idea ?

please help me

Assuming your car dimensionless (and

do the trick?

:)

`speed()`

positive), shouldn't```
if (gearState() == -1)//reverse gear
{
position.X += (Int32)(speed() * Math.Sin(theta * Math.PI / 180));
position.Y
```**<big>+=</big>** (Int32)(speed() * Math.Cos(theta * Math.PI / 180));
}

do the trick?

:)

Comments

your code doesn't work !

my car is a picture that moving on 2d screen

my car is a picture that moving on 2d screen

What do you mean, exactly, with 'doesn't work'? What is the expected behaviour? What is the observed behaviour? Are the prerequisites satisfied (i.e. irrelevant car dimensions, positive speed)?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada
+1 416-849-8900 x 100