# degrees to x and y

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

## Recommended Posts

Hello, I'm trying to make a particle editor and I have a problem trying to implement the "spread" of particles. It's hard for me to explain what I mean by this so I will show you [smile]. Say I want a spread of 90 degrees: Particles could be anywhere between the two upper 45 degree lines. Here is an example from another particle editor:

##### Share on other sites
What's the question?

##### Share on other sites
Quote:
 What's the question?

dirextion.x = ?
direction.y = ?

In other words if I have a spread of 90 degrees how do I make sure particles stay between those two upper 45 degree lines in the first picture?

##### Share on other sites
spread=pi/2; //90 degreesangle=random_scalar()*spread;direction.x=sin(angle);direction.y=cos(angle);

random_scalar just being a random function spitting out a value in the range of 0-1. A cheap example of that being:
float random_scalar(){  return (float)rand()/RAND_MAX;}

##### Share on other sites
Quote:
 random_scalar just being a random function spitting out a value in the range of 0-1. A cheap example of that being:

##### Share on other sites
Quote:
Original post by subflood
Quote:
 random_scalar just being a random function spitting out a value in the range of 0-1. A cheap example of that being:

Borrowing random_scalar() from ProPuke:
    angle = min_angle + random_scalar() * ( max_angle - min_angle );    x = cos( angle );    y = sin( angle );
or...
    angle = min_angle + random_scalar() * spread;    x = cos( angle );    y = sin( angle );
or...
    angle = center_angle + ( random_scalar() - 0.5f ) * spread;    x = cos( angle );    y = sin( angle );

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 9
• 42
• ### Forum Statistics

• Total Topics
634131
• Total Posts
3015718
×