有人可以给我一个非常简单的例子,如何在javascript中使用KevLinDev类方法intersectCircleLine。一些价值观:
circle_x = 100;
circle_y = 100;
radius = 200;
a1.x = -100;
a1.y = -100;
a2.x = 0;
a2.y = 0;
http://www.kevlindev.com/gui/math/intersection/index.htm#Anchor-intersectCircleLin-40934
我想知道如何:
答案 0 :(得分:1)
包括这些文字:
<script type="text/javascript" src="http://www.kevlindev.com/gui/math/intersection/Intersection.js"></script>
<script type="text/javascript" src="http://www.kevlindev.com/gui/math/point2d/Point2D.js"></script>
查看该库的source code,这样的内容似乎就是您想要的:
var circle = new Point2D(circle_x, circle_y),
point1 = new Point2D(a1.x, a1.y),
point2 = new Point2D(a2.x, a2.y),
intersection = Intersection.intersectCircleLine(circle, radius, point1, point2);
对于这个例子:
var circle = new Point2D(50, 50),
point1 = new Point2D(0, 0),
point2 = new Point2D(100, 100),
intersection = Intersection.intersectCircleLine(circle, 50, point1, point2);
console.log(intersection)
将显示:
{ // (Intersection Object)
status: "Intersection", // Can also be "Inside" or "Outside".
points: [ // If `status` is "Intersection". Otherwise, it's [].
{ // (Point2D Object)
x: 85.35533905932738,
y: 85.35533905932738
},
{ // (Point2D Object)
x: 14.644660940672624,
y: 14.644660940672624
}
]
}
<强> Working example 强>