Programming with triangles!

Fuzzyzilla:
Hello!

I have quite a weird question, but a rather important one nonetheless.
See image for my problem.


I have three points: A,B, and C.
I have the positions of A and B
I have the lengths of lines AB, AC, and BC.
What are the coordinates of point C?


I need to know this because due to the nature of my machine, and how it uses polar coordinates, drawing a straight line correctly is difficult.

I'm not quite to trig in high school yet, so I don't know how to solve this. All I know is that it is trig! :slight_smile:

The following code is from my 128 x 64 VFD graphics driver. It's used to draw polygons of any number of sides, any "radius" (distance from the origin to any node) and at any angle (i.e. drawing over and over again with increasing (or decreasing) angles animates rotation).

It's got all the trig, the polar to rectangular conversions and everything else you should need in order to get going and understand this.

Hope it helps.

////////////////////////////////////////////////////////////////////////
// draw a polygon of any number of sides, rotated by any "angle"
// note angle "0" degrees is straight up (i.e. a triangle is
// drawn like this: /\
//                 /__\
// and the angle goes clockwise so that an angle of 90 degrees
// points the apex to the 3:00 o'clock position.
//
// TONS of thanks to Arduino forum user ROBTILLAART for helping
// me figure out a subtle problem and speeding up the code too!
// Reference: http://forum.arduino.cc/index.php?topic=343198
////////////////////////////////////////////////////////////////////////
void Noritake_VFD_GUU100::drawPolygon (int x, int y, uint8_t radius, int angle, uint8_t sides, uint8_t on)
{
    int x1, y1, x2, y2;
    double th, inc, start;

    if (sides < 3) { // polygon must be at least 3 sides!
        return;
    }

    if (sides > 31) { // too many sides is slow and just makes a circle anyway...
        drawCircle (x, y, radius, on);
        return;
    }

    // starting angle (in radians)
    start = rad (angle - 90); // make 0 degrees straight up
    th = start; // first vertex is at the start (of course)
    inc = ((M_PI * 2.0) / sides); // increment (in radians) to next vertex
    x2 = round ((cos (th) * radius) + x); // get first vertex
    y2 = round ((sin (th) * radius) + y);

    while (sides--) {
        x1 = x2; // old vertex is...
        y1 = y2; // ...the new startpoint
        th = ((sides * inc) + start); // increment to the next vertex
        x2 = round ((cos (th) * radius) + x); // get next vertex
        y2 = round ((sin (th) * radius) + y);
        drawLine (x1, y1, x2, y2, on); // draw side
    }
}