# How do I calculate opposite of a vector, add some slack

How can i calulate a valid range (RED) for my object's (BLACK) traveling direction (GREEN). The green is a Vector2 where x and y range is -1 to 1.

What I'm trying to do here is to create rocket fuel burn effekt. So what i got is

• rocket speed (float)
• rocket direction (Vector2 x = [-1, 1], y = [-1, 1])

I may think that rocket speed does not matter as fuel burn effect (particle) is created on position with its own speed.

You need a normal vector for your rocket direction. You can use cross product to calculate it, which in 2D results to normal = vector(direction.y, -direction.x);

Now the burn vector is just a normalized linear combination of -direction and normal. E.g.

float k = random() * 0.3;
burn = normalize(normal * k - direction * (1 - k));


I'd suggest you calculate the polar angle (angle with the X axis) of the vector. Then you can rotate it by 180° and for each particle add a randomized value based on the width of the burn effect cone (e.g. +/- 30°). Then convert the angle back to vector.

Here's some C# example code to add a PolarAngle property to a Vector2D class. Note that it's operating in Radian not Degree.

/**
* An angle describing the orientation of the Vector. (-1,0) is 0. (1,0) is Pi.
*/
public double PolarAngle
{
get
{
return Math.Atan2(Y, X) + Math.PI;
}

set
{
double len = Length;
X = len * Math.Cos(value);
Y = len * Math.Sin(value);
}
}