I am practicing working with vectors. In this sketch I draw a line connecting centers of two ellipses. How can I shorten the line so that it touches the perimeter of each ellipse (not the center)?
PVector v1, v2;
void setup(){
noLoop();
v1 = new PVector(40, 20);
v2 = new PVector(25, 50);
}
void draw(){
ellipse(v1.x, v1.y, 12, 12);
ellipse(v2.x, v2.y, 12, 12);
line(v1.x, v1.y, v2.x, v2.y);
}
First you’d need to calculate the points where the line would cross the edges of the circles. Fortunately, this is quite easy: (Note that I don’t know Processing, so treat this as psuedocode)
Then just draw the line
(x1,y1,x2,y2)