# sin & cos.... any direction

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

## Recommended Posts

I have a simple particle system that uses sin & cos to move in radial type directions... // something like this VECTOR3 spawnPos = EmitterPos; spawnPos.y = sin( spawnPos.x ); spawnPos.z = cos( spawnPos.x ); this creates the correct effect but obviously only allows for movement in the X direction... I have been tring to create the same effect for any direction, but have yet to do so.. I need a little help.. thanks

##### Share on other sites
Err, I'm confused about the posted snippet.

You use an argument of the unit "length" in a trigonometric function?! That is a hint that something is wrong or at least missing.

You are computing the y and z co-ordinate of the spawn position inside the interval [-1,+1] regardless of the position of the emitter. That seems me not to be the intention, or the use of the emitter position is at least spurious.

Please explain in more detail what your desires are. E.g. should the particles all be spawned at the point location or in a disk area around the emitter's location, or something else? How do you intent to alter the current position of the particles with time?

Btw: I would expect code like this for a point located emitting
randomAngle = randomNumberBetween( 0, 2*PI );particle.currentPos = EmitterPos;particle.velocity.x = aConstantOrWhatever;particle.velocity.y = particle.speed * cos( randomAngle );particle.velocity.z = particle.speed * sin( randomAngle );

and similarly for an emitter with disk area
randomAngle = randomNumberBetween( 0, 2*PI );randomRadius = randomNumberBetween( 0, radiusOfDisk );particle.currentPos = EmitterPos;particle.currentPos.y += randomRadius * cos( randomAngle );particle.currentPos.z += randomRadius * sin( randomAngle );particle.velocity.x = aConstantOrWhatever;particle.velocity.y = particle.speed * cos( randomAngle );particle.velocity.z = particle.speed * sin( randomAngle );

But perhaps I misunderstood your intention ...

[Edited by - haegarr on March 29, 2006 3:04:56 AM]

##### Share on other sites
MTclip:
The math you present will cause your particles to move in a circular helix (spiral) around the X-axis if you alter the x-component. Is this the effect you desire?

##### Share on other sites
thanks guys...
I figured my post may have been a little confusing...

from my snippet.. only the emitter is moving from its origin to the target ( the particles are stationary ) and the spawn position is found based on the emitter position..

Quote:
 randomAngle = randomNumberBetween( 0, 2*PI );randomRadius = randomNumberBetween( 0, radiusOfDisk );particle.currentPos = EmitterPos;particle.currentPos.y += randomRadius * cos( randomAngle );particle.currentPos.z += randomRadius * sin( randomAngle );particle.velocity.x = aConstantOrWhatever;particle.velocity.y = particle.speed * cos( randomAngle );particle.velocity.z = particle.speed * sin( randomAngle );

this would cause a random postion based off the sin / cos wave.. I want it to flow along the sin wave..

I am looking to make it so that the same "spiral" effect occurs no matter the direction the emitter is going...

staaf: I would like it to rotate around any axis

is that more clear?
Thanks

##### Share on other sites
Okay, so you want the emitter follow any straight line. During the movement of the emitter particles should be emitted perpendicular to the line of movement in a spiral arrangement. Sorry for my misunderstanding.

You could define the location and orientation of the emitter by using an own co-ordinate frame (e.g. a transformation matrix).

(1) Create the emitter with a frame located in the world origin and oriented with the world co-ordinate system.

(2) Initialize the emitter's frame with the desired initial orientation, followed by the initial position.
emitter.frame = RotationMatrix( initialOrientation )
emitter.frame *= TranslationMatrix( initialPosition )
emitter.summedDistance = 0

(3) Each particle is emitted similarly like you've already done, but interpret the position of the particle in the local co-ordinates of the emitter.
angle = emitter.summedDistance/distanceScale
particle = new Particle
particle.position = VECTOR3( cos(angle), sin(angle), 0 )

Here you have to decide which of the axes should denote the direction of motion of the emitter. In your OP it was the x axis. I've chosen the z axis, since that is the most often used axis for such purposes.

(4) Transform the new particle to world co-ordinates. If you use column vectors
particle.position = emitter.frame * particle.position
or else if you use row vectors
particle.position = particle.position * emitter.frame

(5) Move the emitter's frame a bit along its path. Change its orientation if wanted as well.
emitter.frame *= TranslationMatrix( emitter.frame.z * movementDistance )

(6) Add the moved distance to an internal distance sum, so that you have the gone way distance independent of the path's absolute location.
emitter.summedDistance += movementDistance

(7) Continue with (3)

With this approach you could let the emitter even follow curved pathes. You could make the whole thing display frame rate independent if computing the movementDistance from a speed and the time duration elapsed since the last rendering. You could control how many particles per distance are emitted by varying distanceScale.

(Btw: Interestingly, you could simulate the sin/cos thing by rolling (i.e. rotating around the axis of movement) the emitter and emitting at a fixed local position.)

Hopefully I've matched your desires better this time :)

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 9
• 19
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633382
• Total Posts
3011580
• ### Who's Online (See full list)

There are no registered users currently online

×