looking for formula on spawning/creating circle checks

Started by
1 comment, last by JoeJ 2 years, 7 months ago

Im trying to spawng a new point via mouse click,
it is simply as when a use clicks on an area it spawns a new point, if the clicked area is inside a circle, it will not create a new point, when it is outside and will have a collision on an existing point, i compute direction vector by getting the clicked point - collided circle center point, multiply by radius and create a circle on it.

My issue is if the clicked point collides in two circles, I can compute the new direction by summing the vectors of the two circle, but i am confuse on how to compute for the new position of the new circle.

Any suggestions? how can i compute for new position that is closest to the two cicle collided that also covers the the mouse clicked position, what is the most efficient way?

Advertisement

You can use simple pythagoras.

You know the length of the red line.
You can set the length of the blue line to be circle radius * (2 + 0.3), where 0.3 is some constant >0 to define some distance preventing contact with the newly generated circle.
We get a right angled triangle:
a = length of red line / 2
b = circle radius * 2.3
c = sqrt (a^2 + b^2)

So we now know the length of the green line to be c.
Make a perpendicular line from the red line with that length from the red midpoint and you're done.


However, if you have more points than two, you have the same problem known as generating 'poisson samples'.
Many solutions exist. Personally i usually do some iterations of collision detection and resolve of the circles.


This topic is closed to new replies.

Advertisement