14,639,480 members
Rate this:
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 ?
Posted
Updated 8-Aug-18 23:21pm
v3

Rate this:

## Solution 1

Assuming your car dimensionless (and `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?
:)
fika_fa 2-Jul-10 13:21pm

my car is a picture that moving on 2d screen
CPallini 2-Jul-10 14:22pm

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