LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Particle in 2D Box - Central Force?

I was trying to replace your random number initial position with a defined initial position but somehow it doesn't work. Do you know why?

0 Kudos
Message 11 of 18
(1,408 Views)

I follow your suggestions to do the collison problem, but somehow my codes don't work. Basically, I say that when the particle position vector equal to each other, their velocities have to flip the sign.

0 Kudos
Message 12 of 18
(1,401 Views)

@karryli wrote:

I was trying to replace your random number initial position with a defined initial position but somehow it doesn't work. Do you know why?


That code makes no sense at all. All you get back is the original array control, possibly truncated to 4 elements. The FOR loop is not needed.

 

Note that the lower array contains the speed components, not positions.

0 Kudos
Message 13 of 18
(1,389 Views)

@karryli wrote:

I follow your suggestions to do the collison problem, but somehow my codes don't work. Basically, I say that when the particle position vector equal to each other, their velocities have to flip the sign.


Please keep the code scalable, you need to detect collisions between all particles, no matter how many there are. 

 

"Delete from array" is not the right tool to split an array. Also remember that is is virtually impossible for two infinitely small particles to occupy the same space at the same time, so your comparison will never, ever be equal.

 

You would need to define a finite particle size. Collision detection would need quite different code and either trajectories need to caclulated with a much finer time resolution or you would need a much more intelligent geometric algorithm. You also need to consider the direction of each particle and how close the two trajectories are, etc.

0 Kudos
Message 14 of 18
(1,383 Views)

Oh, and just for kicks a quickly made a 3D version. as I said, minimal code changes! 😄

 

 

 

Download All
0 Kudos
Message 15 of 18
(1,375 Views)

When I try to replace your 3d position vector, which is generated by random number, with my 3d defined position vector, I find that I can't make my vector default in this code. Namely, when I have column vector 8 8 8 -1 -1 -1 7 7 7 and I make this to be default. Next time, I opened the same VI and all the vector become this, which is attached.

0 Kudos
Message 16 of 18
(1,340 Views)

Are you defining the default for the array or the default for the array element. It depends what you select or where you right-click. Done correctly, this should work just fine.

 

Maybe select all the array controls followed by "edit...make selected values default". Now save the VI.

0 Kudos
Message 17 of 18
(1,329 Views)

Your suggestion works, thanks!

0 Kudos
Message 18 of 18
(1,319 Views)