简短的回答是,您必须使用基本三角函数来计算点之间的角度,然后使用更基本的三角函数来确定圆形路径上的后续点。
查看the Processing reference 的三角函数部分了解更多信息。
但基本上,如果你有两个点,你可以使用atan2() 函数来计算它们之间的角度。您可以使用它来找到从圆心到形状的起始角度。
获得该角度后,您可以简单地增加它,然后使用cos() 和sin() 计算出该新角度处的x 和y 坐标。
这是完成上述所有操作的基本草图:
PVector center;
float angle;
float radius;
void setup() {
size(500, 500);
center = new PVector(width/2, height/2);
//get the initial point
//for you, this would be the initial location of the object
PVector point = new PVector(random(width), random(height));
//find the angle between the points
float deltaX = center.x - point.x;
float deltaY = center.y - point.y;
angle = atan2(deltaX, deltaY);
//find the radius of the circle
radius = dist(center.x, center.y, point.x, point.y);
ellipseMode(RADIUS);
}
void draw() {
background(0);
//draw the center point
ellipse(center.x, center.y, 10, 10);
//find the point based on the angle
float x = center.x + cos(angle)*radius;
float y = center.y + sin(angle)*radius;
//draw the traveling point
ellipse(x, y, 10, 10);
//increment the angle to move the point
angle += PI/120;
}