new version following your 2nd image with the web image of a drawing machine with 2 rotating wheels connected by 2 arms and a blue pen
This calls for a Wheel class…
final color BLACK = color(0);
final color WHITE = color(255);
final color RED = color(255, 0, 0);
final color GREEN = color(0, 255, 0);
final color BLUE = color(0, 0, 255);
// WHEEL I
PVector centerPV1=new PVector (200, 300);
float angle1=1.3;
float angleSpeed1=.1;
float radiusWheel1= 44;
// WHEEL II
PVector centerPV2=new PVector (300, 320);
float angle2=0;
float angleSpeed2=.021;
float radiusWheel2= 22;
// resulting drawing
ArrayList<PVector> list = new ArrayList();
void setup() {
size(600, 600);
background(WHITE);
}
void draw() {
background(WHITE);
// points A and B from WHEELS
PVector A = new PVector(
cos(angle1)*radiusWheel1+centerPV1.x,
sin(angle1)*radiusWheel1+centerPV1.y);
PVector B = new PVector(
cos(angle2)*radiusWheel2+centerPV2.x,
sin(angle2)*radiusWheel2+centerPV2.y);
// move WHEELS
angle1+=angleSpeed1;
angle2+=angleSpeed2;
// show WHEELS
noFill();
stroke(BLACK);
ellipse(centerPV1.x, centerPV1.y,
radiusWheel1*2, radiusWheel1*2);
ellipse(centerPV2.x, centerPV2.y,
radiusWheel2*2, radiusWheel2*2);
// CALC
// https : // en.wikipedia.org/wiki/Isosceles_triangle#Height
float lineC = A.dist(B);
float distFromBase= (100*100) - ( lineC*lineC / 4 ) ;
distFromBase=sqrt(distFromBase);
// the core: get side point C
PVector C = getSidePoint(A, B, distFromBase); // -100 would make the triangle to the other side
// add to drawing
list.add(C);
// connectedPoints(C, center, RED);
// draw triangle from ABC
trianglePV(A, B, C);
// highlight its corners
ellipsePV(A, RED);
ellipsePV(B, GREEN);
ellipsePV(C, BLUE);
fill(0);
text( A.dist(C),
22, 22);
// show drawing
for (PVector pv : list) {
stroke(BLUE);
point(pv.x, pv.y);
}
//
}
// ----------------------------------------------------------------
void trianglePV(PVector pv1, PVector pv2, PVector pv3) {
fill(144); // gray
stroke(BLACK);
triangle( pv1.x, pv1.y,
pv2.x, pv2.y,
pv3.x, pv3.y );
}
void ellipsePV(PVector pv, color col) {
fill(col);
ellipse(pv.x, pv.y, 10, 10);
}
PVector getSidePoint(PVector A, PVector B,
float distFromLine) {
// the core function of the demonstrator
// thanks to amnon
// difference between A & B
PVector difference = PVector.sub(B, A);
difference.normalize();
difference.mult(distFromLine);
PVector sidePoint = new PVector(-difference.y, difference.x);
// center between A & B
PVector center = getCenter(A, B);
// from relative pos to absolute pos
sidePoint.add(center);
return sidePoint;
}
// ---------------------------------------------------
// help functions
void connectedPoints(PVector A, PVector B, color myColorStroke) {
// show 2 points A and B and connect them
stroke(myColorStroke);
line(A.x, A.y, B.x, B.y);
ellipse(A.x, A.y, 10, 10);
ellipse(B.x, B.y, 10, 10);
}
PVector getCenter(PVector A, PVector B) {
// returns center point
return PVector.lerp(A, B, 0.5); // 0.5 defines center
}
//