Public Group

This topic is 2647 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am building a particle system and my current problem is with spread angle.

I'm not using Vectors, instead I have 2 coordinates.

In initialization phase I m doing:
 float angle = random.Next(0,90); parts.Angle_X = AngleToVector(angle)[0]; parts.Angle_Y = AngleToVector(angle)[1]; 

and this the way I m getting vector from angle:

private float[] AngleToVector(float angle) { //vector[0] = X; //vector[1] = Y; float[] vector = new float[2]; vector[0] = (float)Math.Cos(angle); vector[1] = (float)Math.Sin(angle); return vector; } 

I update my particles position:

 parts.Position_X += parts.Angle_X * parts.Velocity; parts.Position_Y += parts.Angle_Y * parts.Velocity;

what I get after this is :

particles are spread not from 0 till 90 but all over the screen.

When I m using random.nextDouble() I m getting spread angle:

How can I control the angle, so when angle is from 0 to 90 it would be upper right square, from 90 to 180 - upper left and so on?

##### Share on other sites
You need to supply Sin and Cos with an angle in radians. I think you can do MathHelper.ToRadians(float degree) in XNA.

Edit:

And you probably want to do:

 float vector[2] = AngleToVector(angle); 

Instead of calling AngleToVector() twice. Not sure if the compiler optimize the duplicate call somehow tho.

##### Share on other sites

You need to supply Sin and Cos with an angle in radians. I think you can do MathHelper.ToRadians(float degree) in XNA.

Edit:

And you probably want to do:

 float vector[2] = AngleToVector(angle); 

Instead of calling AngleToVector() twice. Not sure if the compiler optimize the duplicate call somehow tho.

It's perfect!
exactly what I wanted. Solution was using radians 8-)
Oh, and calling twice AngleToVector() didn't matter, it gave me the same results doing both ways.

p.s. I m suppose to build this without using XNA so to get radians I used:
double radians = (Math.PI / 180) * angle;

and the result:

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 15
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633352
• Total Posts
3011483
• ### Who's Online (See full list)

There are no registered users currently online

×