- Home /
Calculating a point on the edge of a circle
Hi,
I'm trying to calculate a point on the edge of a circle, where this point is also the closest possible point to the origin of another circle. I've done some Googling and come up with this (where origin refers to the first circle, and origin2 to the second circle):
private Vector2 point = new Vector2((origin.x + radius) * Mathf.Cos(Mathf.Atan2(origin2.y - origin.y, origin2.x - origin.x)), (origin.y + radius) * Mathf.Sin(Mathf.Atan2(origin2.y - origin.y, origin2.x - origin.x)));
Unfortunately, the point this creates is far from where I actually need the point to show up. For a little more help, I've got this visual representation, where the yellow dot is about where the point should be showing up (please bear in mind that the origins of these circles are variable, though):
Any help with this formula would be much appreciated!
Answer by LCStark · Sep 24, 2018 at 05:16 AM
You can use vectors to simply get the direction from origin
to origin2
. When you have that it's simply a matter of multiplying the direction by the radius of your circle and adding it to the origin
:
Vector2 direction = origin2 - origin;
direction.Normalize();
Vector2 point = origin + direction * radius;