Quelqu'un pourrait-il me donner un exemple très simple de l'utilisation de KevLinDev Class Method intersectCircleLine en javascript. Quelques valeurs:
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
Je voudrais savoir comment:
Incluez ces scripts:
<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>
En regardant le code source de cette bibliothèque, quelque chose comme ceci semble être ce que vous voulez:
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);
Pour cet exemple:
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)
affichera:
{ // (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 } ] }
Exemple de travail