-2

I'm currently working on my computer science culminating and I'm stuck and cannot seem to find any answers on similar questions asked on stack overflow.

The problem I am trying to solve is there are three given points in the form (x, y) on a screen (1280 by 720 where the top left corner is (0, 0)) and you have to find a curve that passes through all three points.

So, knowing there are three points, you know that they form a triangle. After finding the circumcentre, you now have:

  • The radius,
  • The origin,
  • And three angles

The curve must start at the first given point, pass through the second given point, and end at the third given point.

int pointX = Math.round(circumcentreX + radius * Math.cos(angle));
int pointY = Math.round(circumcentreY + radius * Math.sin(angle));

Above are the equations I found to find the points on the curve given the angle.

I also know how to find the angles of the three given points with Math.atan2(y, x);

The main problem I have is finding the angles that lie on the curve. So far I have

float angle = (float)Math.toRadians(beginningAngle - (beginningAngle - endAngle) * t);

, where t is the percent of the curve it is at, but it doesn't work half the time.

The angles of the circle would be where North is 270, East is 0, South is 90, West is 180.

Here is what the curve should look like

Angles: 183.57921 : 264.60202 : 358.09354 X coordinates: [473, 597, 747] Y coordinates: [376, 248, 380]

Here is a case of where it fails

Angles: 179.00537 : 270.5897 : 2.6373901 X coordinates: [473, 614, 752] Y coordinates: [376, 234, 380]

Please let me know if you found a way to find the angles or would like some source code. Thank you in advance!

Geon Youn
  • 1
  • 3
  • Hope this link would be helpful. https://stackoverflow.com/questions/46387747/find-angle-of-point-on-circle – Dhaval Goti Dec 28 '18 at 04:30
  • If your points are ordered, find the circle's center (which is super easy, and even easier to find with a web search), and then find the angles for p0, p1, and p2 _with respect to that center_ so that you know at which angle to start your circular arc, and which angle to run the arc to. – Mike 'Pomax' Kamermans Dec 28 '18 at 04:33

1 Answers1

0

After fiddling around with what causes errors and what works, I ended up with four if, else-if, and else's to fix my problem.

float change;
float tba = (ba / 100 < 1) ? ba + 360 : ba;
float tma = (ma / 100 < 1) ? ma + 360 : ma;
float tea = (ea / 100 < 1) ? ea + 360 : ea;
    if(tba > tma && tma > tea && ea > ba)
        change = ea - ba - 360;
    else if(tba < tma && tma < tea && ea < ba)
        change = tea - ba;
    else if(ea < ba && ma < ba)
        change = ea - ba;
    else
        change = (ea - ba < 0f) ? ea - ba + 360 : ea - ba;
    change %= 360;

the float change is the difference between the first angle and the third angle. The floats tba, tma, and tea are only temporary versions of ba, ma, and ea (which are the angles of the given points) which are used so that comparing the angles are easier. For example, when the ba is 350° and ma is 10° and ea is 15°, instead, they could be 350°, 370°, and 375°, respectively. (change would be 25° in this case) I'm not sure if the last line is necessary but I'm keeping it there just in case.

By the way, the reason I'm using floats instead of doubles is that slick2D usually have floats as arguments and not doubles.

Geon Youn
  • 1
  • 3