3

I know of an equilateral triangle the center (cx,cy) and the radius (r) of a blue circle which circumscribed it.

If I draw a green circle of any radius (radius), assuming the circle is large enough to have this intersection, can I get the coordinates of the 6 intersection points (P1, P2, P3...)?

Text

I'm looking for P5JS/processing but any other clue can help me...

Thank you in advance

Richnou
  • 106
  • 8

2 Answers2

5

Distance from the center to top point is r.
Distance from the center to the lowest triangle side is r/2 (median intersection point is center, they are divided in 1:2 ratio).
Horizontal distance from cx to p4 (and p5) is (Pythagoras' theorem)

dx = sqrt(radius^2 - r^2/4)

So coordinates of p4 and p5 are (relative to center)

p4x = dx
p4y = r/2
p5x = -dx
p5y = r/2

Other points might be calculated using rotation by 120 degrees

p2x = p4x*(-1/2) - p4y*(sqrt(3)/2)
p2y = p4x*(sqrt(3)/2) + p4y*(-1/2)

and so on.

And finally add cx,cy to get absolute coordinates

MBo
  • 77,366
  • 5
  • 53
  • 86
  • 1
    Great answer. Notice that when R == 1/2r, there are just three points, and dx is 0, which makes sense. When R < 1/2r, there are no intersections and dx is complex. What I can't figure is how this degenerates when R is very large. – danh Jan 07 '23 at 17:29
  • 1
    @danh When R is too large, intersections lie at continuations of triangle sides. – MBo Jan 07 '23 at 17:36
  • But I don't know how calculate other points with the 120 degrees rotation... – Richnou Jan 09 '23 at 11:28
  • 1
    @Richnou I wrote formula for p4->p2 . Similarly p5->p3, p2->p6, p3->p1 – MBo Jan 09 '23 at 12:55
1

If you want to test... ;-)

function setup() {
    createCanvas(500, 500);

    const cx = width / 2;
    const cy = height / 2;
    const r = 250; // taille du triangle

    const radius = 180; // externe

    noFill();
    strokeWeight(3);
    stroke(0, 0, 0);
    drawTriangle(cx, cy, r);

    strokeWeight(1);
    stroke(0, 0, 255);
    circle(cx, cy, r * 2);

    strokeWeight(2);
    stroke(8, 115, 0);
    circle(cx, cy, radius * 2);

    noStroke();
    fill(215, 0, 0);

    // dx = sqrt(Math.pow(r / 2, 2) - Math.pow(r / 2, 2 / 4));
    
    dx = sqrt(radius * radius - (r * r) / 4);

    p4x = dx;
    p4y = r / 2;
    circle(cx + p4x, cy + p4y, 20);
    text("p4", cx + p4x, cy + p4y + 30);

    p5x = -dx;
    p5y = r / 2;
    circle(cx + p5x, cy + p5y, 20);
    text("p5", cx + p5x - 10, cy + p5y + 30);

    p6x = p4x * (-1 / 2) - p4y * (sqrt(3) / 2);
    p6y = p4x * (sqrt(3) / 2) + p4y * (-1 / 2);
    circle(cx + p6x, cy + p6y, 20);
    text("p6", cx + p6x - 30, cy + p6y);

    p2x = p6x * (-1 / 2) - p6y * (sqrt(3) / 2);
    p2y = p6x * (sqrt(3) / 2) + p6y * (-1 / 2);
    circle(cx + p2x, cy + p2y, 20);
    text("p2", cx + p2x + 10, cy + p2y - 10);

    p1x = p5x * (-1 / 2) - p5y * (sqrt(3) / 2);
    p1y = p5x * (sqrt(3) / 2) + p5y * (-1 / 2);
    circle(cx + p1x, cy + p1y, 20);
    text("p1", cx + p1x - 20, cy + p1y - 10);

    p3x = p1x * (-1 / 2) - p1y * (sqrt(3) / 2);
    p3y = p1x * (sqrt(3) / 2) + p1y * (-1 / 2);
    circle(cx + p3x, cy + p3y, 20);
    text("p3", cx + p3x + 20, cy + p3y - 10);

    noFill();
    stroke(0, 255, 255);
    triangle(cx + p2x, cx + p2y, cx + p4x, cx + p4y, cx + p6x, cx + p6y);

    stroke(255, 0, 255);
    // prettier-ignore
    triangle(
        cx + p1x, cx + p1y,
        cx + p3x, cx + p3y,
        cx + p5x, cx + p5y,
    )
}

function drawTriangle(cx, cy, radius) {
    noFill();
    trianglePoints = [];
    for (var i = 0; i < 3; i++) {
        var x = cx + radius * cos((i * TWO_PI) / 3.0 - HALF_PI);
        var y = cy + radius * sin((i * TWO_PI) / 3.0 - HALF_PI);
        trianglePoints[i] = {
            x,
            y,
        };
    }
    triangle(
        trianglePoints[0].x,
        trianglePoints[0].y,
        trianglePoints[1].x,
        trianglePoints[1].y,
        trianglePoints[2].x,
        trianglePoints[2].y
    );
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.min.js"></script>
Richnou
  • 106
  • 8
  • 1
    Are you sure in `dx = sqrt(Math.pow(r / 2, 2) - Math.pow(r / 2, 2 / 4));`? Seems incorrect (note `radius` is not used at all). I think it should look like `dx = sqrt(radius*radius - r*r/4);` – MBo Jan 10 '23 at 08:31
  • You are absolutely right! My points seemed good at first glance, but there was a very small misalignment... – Richnou Jan 12 '23 at 13:55