PDA

View Full Version : Objects overlapping


lalechuza
06-04-2015, 09:16 AM
Hey there!
I'm new to Vizard and to Python.
I have to set a few cylinders to random positions, but they shouldn't overlap in any way.
I don't really know how to ensure this. I thought of an array that holds all the positions (resp. the areas) of the already loaded cylinders and comparing every new random position with it before loading the new cylinder. Now I wonder if there is an easier way to handle this?!

MissingAFew
06-04-2015, 12:19 PM
You could add a proximity sensor to each cylinder and add each cylinder as a target. Each sensor and target would get added to the proximity manager. Then when you create/spawn the cylinder and sensor if one of the other cylinder targets overlaps the proximity it calls a "try respawn" function. I would look at the following documentation pages here for details:

http://docs.worldviz.com/vizard/index.htm#vizproximity_manager.htm%3FTocPath%3DRef erence%7CProximity%20Sensors%7C_____4

http://docs.worldviz.com/vizard/index.htm#vizproximity_sensor.htm%3FTocPath%3DRefe rence%7CProximity%20Sensors%7C_____2

http://docs.worldviz.com/vizard/index.htm#vizproximity_target.htm%3FTocPath%3DRefe rence%7CProximity%20Sensors%7C_____3

What you said in your post could work fine, but its not very extendable. If you have different sized objects it could be a pain to get it working. With this you might have an easier time and there is less mathy stuff involved in regards to checking positions of objects, etc.

lalechuza
06-04-2015, 01:08 PM
Thank you so much for your help :)

lalechuza
06-09-2015, 01:14 AM
Hey again!

I tried to use the proximity sensors now, but I think it is not the solution I am looking for. (Although I love the sensors and using it for some other things now :) )
Maybe my description of what I am trying to do was inaccurate.
What I want to implement is a scene for an experiment where the cylinders are already initialized. If I understand correctly the sonsors are checking if a target enters/exits, but thats not happening when initializing. The new cylinder is "just there" at a moment.
Is there still a way to get it working with the sensors?

MissingAFew
06-11-2015, 12:26 PM
Hey again!

I tried to use the proximity sensors now, but I think it is not the solution I am looking for. (Although I love the sensors and using it for some other things now :) )
Maybe my description of what I am trying to do was inaccurate.
What I want to implement is a scene for an experiment where the cylinders are already initialized. If I understand correctly the sonsors are checking if a target enters/exits, but thats not happening when initializing. The new cylinder is "just there" at a moment.
Is there still a way to get it working with the sensors?

Well, what I was imagining was that when you create your cylinders in random spots, if a cylinder is too close to another cylinder then the proximity sensor would be aware that its too close and call a function to move that cylinder. This wouldn't be initializing their position before the program starts, it would be resetting their position during runtime until the cylinders are no longer touching/overlapping. Once they are no longer overlapping they will no longer be moved. This could be a very quick process and happen in a fraction of a second, depending on the number of cylinders and the area the cylinders are allowed to be in. Worst case, the space isn't big enough for them all and it continues to move the cylinders around randomly and it never stabilizes.

Your original idea wasn't a bad one though. You could still do it that way. Keep all the cylinders in an array along with their positions and manually loop through them to ensure they are far enough from each other.