Saturday, September 24, 2022
HomeiOS Developmentios - How you can constrain a shifting circle in a bigger...

ios – How you can constrain a shifting circle in a bigger circle

It is a lot simpler when you change the place the calculation is. As an alternative of attempting to calculate whether or not the circumference of the interior circle goes exterior the outer circle you’ll be able to cut back this to have a look at the centres.

When you have an outer circle of radius R and an interior circle of radius R' then, as a result of they’re circles we are able to say that if the interior circle centre is larger than (R - R') away from the centre it will likely be exterior the outer circle.

So, if the centre of the outer circle is at (0,0) then we simply must calculate the Pythagorean distance of the centre of the interior circle.

If the coordinates of the centre of the interior circle is (x,y) then we are able to do the calculation…

if x*x + y*y > (R - R') * (R - R') {
  // interior circle is exterior outer circle

If the outer circle centre just isn’t at (0,0) then you definately simply have to make use of dx and dy within the calculation the place dx = outer circle centre x - interior circle centre x and similar for dy.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments