JavaScript
语言:
JaveScriptBabelCoffeeScript
确定
//formula refer to: https://cscheng.info/2016/06/09/calculate-circle-line-intersection-with-javascript-and-p5js.html
const NCIRC = 10;
var circles = [];
var intersects = [];
var detector = {};
function setup() {
createCanvas(400, 400);
randomSeed(1);
circles.push(new Circle(310, 210, 20));
detector.p1 = {
x: 200,
y: 200
};
detector.p2 = {
x: 300,
y: 200
}
detector.theta = 0;
detector.update = function() {
this.theta += 0.02;
this.p2.x = 200 + 100 * cos(this.theta);
this.p2.y = 200 + 100 * sin(this.theta);
}
detector.draw = function() {
stroke(0);
<