MulletDevil
MulletDevil

Reputation: 909

as one variable increases another decreases

I have 2 variables.

float Speed;

float SteeringAngle;

My speed value currently increases. What I want to do is reduce the steering angle as speed increases. It should be a simple equation but I can't seem to work it out.

Thanks

Upvotes: 0

Views: 1562

Answers (2)

quamrana
quamrana

Reputation: 39404

You could try this formula:

  • factor - a number in the range 1..N which is used to scale down the steering angle.
  • maxSpeed - the value of the expected maximum speed at which the maximum factor is applied to reduce the steering angle.
  • requestedAngle - the currently required steering angle

.

float factor;
float maxSpeed;
float requestedAngle;
float Speed;

float SteeringAngle = requestedAngle/( (Speed * factor / maxSpeed) + 1);

There are many possible formulas.

I would suggest you try to plot graphs of speeds and angles

Upvotes: 1

Jerry Coffin
Jerry Coffin

Reputation: 490573

The obvious approach would be something like:

Speed = factor / steeringAngle;

Edit: oops -- I misread your request. If you want to reduce the steering angle as the speed increases, you'd want something like:

if (speed > 0)
    steeringAngle -= factor / speed;

Upvotes: 1

Related Questions