Hi all,
I would like to find a way to compute the location of p4 on the picture below.
All I have is:
- the location of p1, p2 and p3
- the radius (length of segment p2 - p3)
- the angle between segment p1-p2 and segment p2-p3
Ideally, I would like to compute any location of p4 along the arc drawn on the picture.
My trigonometry is not on point and I would really appreciate some help !
void setup(){
size(400, 400, P2D);
strokeCap(SQUARE);
textSize(12);
fill(0);
noFill();
smooth(8);
}
void draw(){
background(255);
PVector p0 = new PVector(width/2 - 10, height/2);
PVector p1 = new PVector(width/2 + 20, height/3);
PVector p2 = new PVector(mouseX, mouseY);
// Display points -> p1, p2 and p3
strokeWeight(6);
stroke(0);
point(p0.x, p0.y);
point(p1.x, p1.y);
point(p2.x, p2.y);
text("p0", p0.x + 10, p0.y);
text("p1", p1.x - 23, p1.y);
text("p2", p2.x + 10, p2.y);
// Display lines between points
strokeWeight(1);
stroke(30, 90, 200);
line(p0.x, p0.y, p1.x, p1.y);
line(p1.x, p1.y, p2.x, p2.y);
// Draw arc
stroke(0, 205, 120);
strokeWeight(10);
arc(p1.x, p1.y, 40, 40, atan2(p1.y - p0.y, p1.x - p0.x), atan2(p2.y - p1.y, p2.x - p1.x));
// Compute angle between (p0 - p1) and (p1 - p2)
float angle = atan2(p2.y - p1.y, p2.x - p1.x) - atan2(p1.y - p0.y, p1.x - p0.x);
// Display text
text(degrees(angle), 15, 25);
// PROBLEM: Compute p4 location
float d = dist(p2.x, p2.y, p1.x, p1.y);
float f = 0.5; // between 0 and 1
float x = d * cos(angle*f);
float y = d * sin(angle*f);
stroke(255, 60, 60);
strokeWeight(5);
point(p1.x + x , p1.y + y);
text("p4", p1.x + x + 10 , p1.y + y);
}