How to calculate missing point of triangle?

235 Views Asked by At

I am about to develop a special animation where I want to rotate a triangle (given a specific width angle) around a circle (given a specific radius) given a specific rotationAngle.

img

This is how I can calculate the 2 coordinates x1 / x2 that stands for the base of the triangle (the two coordinates that are hitting the circle). But I'm not able to calculate the third one!

triangle = {
    x1: image.width / 2 + radius * cos((rotationAngle * PI / 180)),
    y1: image.height / 2 + radius * sin((rotationAngle * PI / 180)),

    x2: image.width / 2 + radius * cos(((rotationAngle + triangleSize) * PI / 180)),
    y2: image.height / 2 + radius * sin(((rotationAngle + triangleSize) * PI / 180))
  }

Since I know that the opposite sides of the triangle are of equal length, I only have to calculate the last point. I know the theoretical path:

  • Calculate gradient A of distance xy1/xy2
  • Calculate the center M of distance xy1/xy2
  • Calculate the normale from A with a certain length from the center M calculate = h of triangle

Nevertheless I have problems to implement it and hope that someone will help me. Thanks in advance.

img

1

There are 1 best solutions below

2
On

You need to define the height of the triangle, in the code segment below I have used a height of one tenth of the radius. I have also made it that the apex of the triangle is the part at exactly the rotation angle.

   triangle = {
   x3: image.width / 2 + 1.1 * radius * cos((rotationAngle * PI / 180)),
   y3: image.height / 2 + 1.1 * radius * sin((rotationAngle * PI / 180)),
   x1: image.width / 2 + radius * cos(((rotationAngle - 0.5 * triangleSize) * PI / 180)),
   y1: image.height / 2 + radius * sin(((rotationAngle - 0.5 * triangleSize) * PI / 180))
   x2: image.width / 2 + radius * cos(((rotationAngle + 0.5 * triangleSize) * PI / 180)),
   y2: image.height / 2 + radius * sin(((rotationAngle + 0.5 * triangleSize) * PI / 180))
      }