#### Archived

This topic is now archived and is closed to further replies.

# Random Coords that lie inside geometry

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

## Recommended Posts

Hello, I have started work on a particle engine, and I have the basics. One of the things I would like to implement would be different types of emitters. IE - Particles can be generated at a single point, on a line, on a quad, on a circle, in a sphere, etc. What the problem is is that I don''t fully understand sin/cos in computing. What troubles me is that there can be 2 different orientations for the triangle. For example:
.

.

can be interpreted like this:
.....     .
.  .     ..
. .     . .
..     .  .
.  or .....

which switches around the opposite/adjacent sides. Now, I can easily look up the function to calculate a point on a circle, actually I have memorized it. However, I have never truely understood it and I really need to understand it well if I''m going to have a chance of modifying it, transforming it in 3d space, adding angles that the particles are emitted at, etc. So, in order to understand the method for calculating a point on a circle, can someone please give me the code, and explain why you used sin or cos where, and also be willing to answer questions. Thanks a lot. PS. While I''m talking about geometry, is there a name for a 2d torus type thing? Meaning, is there a name for a circle with a circle chopped out of the middle of it? I plan on having something like this as an emitter and I want to know the name of it! Thanks again. PPS. Also if you have any ideas for emitters, drop a line. Also, if it is a complex shape, give an idea on how to generate a point that lies on/in it.

##### Share on other sites
that would be a ring

anyhooo, the sin() cos() stuff deals with the unit circle and vectors. math books explain this quite well. one method for getting a point in a sphere is to get random x, y, z values.

x = rand()%SOMEMAX;
y = rand()%SOMEMAX;
z = rand()%SOMEMAX;

then normalize the valus by pretending its a vector. we find the length by using the length formula.

mag = sqrt(x*x+y*y+z*z);

then divide
x /=mag;
y /=mag;
z /=mag;

now mulitply by the radius of the sphere

ok that is a point on the sphere, randomizing radius will get you points within the sphere.

now this is not the best method since its not flexible. you cant limit it to specific cone (ie partial sphere volume).

look up spherical/polar coordinate systems.

the sin/cos relation is probably confusing because you did not learn about teh unit circle and how the point
x = sin(angle)
y = cos(angle)

is a point on the unit circle. being that any angle you choose gives you a different point on the circle. unfortunatly you cant just add z to the mix. being that z is going to be slices of the unit circle so as z goes the radius of the circle increases and decreases. thus a single angle cant give you the value you want. you can rotate a unit vector around the x axis and the y/z relation changes. you rotate round the y axis and the x/z relation changes. some goes for a rotation around the z axis (ie any 2d animation) which now is changing x/y realtion.

thus you must have two varibles to determine z. the angle and for now a depth slice (ie we just rotate the 2d unit vector around the x axis). this is not correct way of doing things, but you can use it to maybe help understand a better explaination that will come, or after reading your math book, or looking over some web sites explaining sphercial/polar coordinate systems.

if my math is correct, that should work. if not i may have swapped things or just forgot something. in any case i would not advise using a formula like above since its hackish at best. unfortunatly i dont have and skeleton workspace to test and make sure that actually creates a sphere. so test it and see if it creates a sphere, if it does not, ignore it (or try to fix it based on what you know which is that it is rotation of the vector [radius*sin(angle), radius*cos(angle), 0] around the x axis. i tried speeding things up by using the knowledge that z is 0 therefore its half of the rotation formula is left out).

trainagles come in one way with three vertices. you always go around clockwise or counterclockwise depending on the system you use. thus you keep it consistent, there is no confusion.

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633763
• Total Posts
3013728
×