How can one determine if a circle is inside another circle? I thought I had it figured out using isInside method.
Note: This code will run on http://sketch.paperjs.org
Expect Circle2 to be inside Circle1
var circle1 = new Path.Circle(new Point(100, 100), 100);
var circle2 = new Path.Circle(new Point(100, 100), 50);
circle1.strokeWidth = 2;
circle1.strokeColor = "black";
circle1.fillColor = "blue";
circle2.strokeWidth = 2;
circle2.strokeColor = "black";
circle2.fillColor = "green";
console.log(circle1.isInside(circle2));
console.log(circle2.isInside(circle1));
Outputs:
false false
2
Answers
From the docs isInside requires a rectangle object to be passed in as a parameter, not a path.
Working Code
Outputs:
To know if
circle_small
with radiusRs
is enterely insidecircle_big
with radiusRb
just check that the distance between their centers (Cb, Cs) is less thanRb-Rs
.If you allow both circles "touch" in one point then the condition is less or equal to
Rb-Rs
.General case: