Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, it seems more like a math problem than a python problem, since the same rationale would work for any language.</p> <p>Second, if all your objects are spherical, then you doesn't need to actually detect a TRUE COLLISION, but actually just to check if the distance between object centers is smaller than the sum of their radius. You can get quickly this distance (if your space is euclidean) with this function (which I havent seen defined in your code):</p> <pre><code>def get_distance(obj1, obj2): # euclidean distance in three dimensions: return ( (obj2.x-obj2.x)**2 + (obj2.y-obj2.y)**2 + (obj2.z-obj2.z)**2 ) ** 0.5 </code></pre> <p>Now, from what I have understood, you want to BOUNCE the objects. This requires, by definition, that for any moment the object has a VELOCITY property, which is a vector with direction and magnitude. When you update the object position, you must also update its velocity (most probably from its previous position).</p> <p>Finally, when you bounce you have to consider the object position, its velocity vector, and the normalized vector which points to the center of the other object it is colliding with. Then, you would perform some vector arithmetics to get its new velocity vector.</p> <p>(UPDATE): if the objects have different masses, and you want a realistic bouncing, then use the Ellastic Collision concepts in Thomas' answer!</p> <p>So, as further research "directions", I'd suggest:</p> <ul> <li>Study some basic vector operations, specially dot product and cross product (you'll be glad you did after you "get" it);</li> <li>Consider STRONGLY using Numpy, which implements vectors and vector operations in a very very convenient way, so that you won't have to implement a lot of things, and it's very faster than anything you could do by hand. You don't have to learn it all, learn just enough to solve your problem.</li> </ul> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COHey, thanks for the answer, the way I got the distance is pretty much exactly as you suggested haha, but I also left in the x,y,z values for if they were needed :) The velocity is also calculated more or less in the same way by skipping back a frame and subtracting the values from the current frame, annoyingly I have no idea how to do it without manually updating the frame so 5+ objects tends to take a few seconds for 100 frames :P But yeah, thanks, I'll check out the product things you suggested soon, gotta stick with python though as it's within maya :)
      singulars
    2. CO@Peter When I talk about Numpy, it's a numeric library to be used IN python, you only have to import it. I have seen a major improvement in speed using Numpy, because when you perform an operation with a large array of points, it's like it processes all the points at once instead of inside a loop (this is called vectorization). For example, if you have a point represented as a 3x1 array, and a set of N points represented as a 3xN array, you could perform an operation with the point and the vector of N points and get another vector with results (say, distances) with a single function call.
      singulars
    3. COAhh right sorry, I just looked it up expecting a download but it seems a bit more tricky to set up aha, I'll definitely look into it some more, my knowledge is still a bit basic at the moment though so for now I'm just going to try get it working ;D What you said about vectorisation though, only kinda half understood that - just say I had 20,000 values stored, part of a different code assigns colours by running through once, getting the high/low values, then runs through again to apply the shaders correctly, would vectorisation work on the first calculation but not the second?
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload