Friday, September 23, 2022
HomeiOS Developmentios - The way to constrain a transferring circle in a bigger...

ios – The way to constrain a transferring circle in a bigger circle


This can be a lot simpler should you change the place the calculation is. As a substitute of attempting to calculate whether or not the circumference of the interior circle goes outdoors the outer circle you may scale back this to have a look at the centres.

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

So, if the centre of the outer circle is at (0,0) then we simply have to 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 will do the calculation…

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

If the outer circle centre will not be at (0,0) then you definitely simply have to make use of dx and dy within the calculation the place dx = outer circle centre x - interior circle centre x and identical for dy.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments