如何使用Paper.js判断圆是否在圆内?

问题描述 投票:0回答:1

如何判断一个圆是否在另一个圆内?我以为我已经使用 isInside 方法弄清楚了。

注意:此代码将在 http://sketch.paperjs.org

上运行

期望 Circle2 在 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));

输出:

假假

javascript geometry paperjs
1个回答
0
投票

从文档中isInside需要将矩形对象作为参数传入,而不是路径。

工作代码

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.bounds));
console.log(circle2.isInside(circle1.bounds));

输出:

假真

© www.soinside.com 2019 - 2024. All rights reserved.