0

I'm trying to figure out how to get the Height of a triangle:

enter image description here

I have startPoint, endPoint and Length:

Point startPoint = Start.GetPoint();
Point endPoint = End.GetPoint();
double Length = panel.W + startPoint.X;

I already figured out how to get the angle with startPoint and endPoint:

double diffX = endPoint.X - startPoint.X;
double diffY = endPoint.Y - startPoint.Y;
double angleRad = Math.Atan2(diffY, diffX);
double angleDeg = angleRad * (180.0 / Math.PI);

I tried some equations with Math.Cos, Math.Sin and Math.Tan but nothing worked.

So how to get the Height? And also, with only what I have is it possible to get the point (X,Y) at the top of the Height, or, in other words, at the end of the line crossing startPoint and endPoint?

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
  • 2
    This is not a question about programming, but about mathematics. You're probably on the wrong stack exchange site. – JHBonarius May 18 '23 at 20:37
  • You need to get angle of startpoint using angle = arcTan((y(end) - y(start))/(x(end) - x(start))). The height is calculated using following : Tan(Angle) = Height/Length – jdweng May 18 '23 at 21:33
  • [soh-cah-toa](https://en.wikipedia.org/wiki/Trigonometry#Mnemonics): if you have the angle, and the adjacent length, the opposite length is the "toa" part. – Mike 'Pomax' Kamermans May 18 '23 at 23:13
  • 2
    @JHBonarius remember that there's special syntax to send people to the right stackexchange site, in this case `[math.se]` so folks know that the [math.se] site exists =) – Mike 'Pomax' Kamermans May 18 '23 at 23:22
  • Similarity. just scale it(Triangle witch has the hypotenuse `startPoint to endPoint`). – fana May 19 '23 at 00:59
  • @Mike'Pomax'Kamermans thanks. I was looking for that. But it's not easy to find those from the help menu. And my google-fu didn't work. – JHBonarius May 19 '23 at 18:07
  • For future reference, it's on https://stackoverflow.com/editing-help#comment-formatting – Mike 'Pomax' Kamermans May 19 '23 at 22:22

1 Answers1

2

There is no need for arctan/tan mutual annihilation. I assume that the bottom side is horizontal.

Height = abs((endPoint.Y - startPoint.Y) * Length / (endPoint.X - startPoint.X))
VerticeX = StartPoint.X + Length
VerticeY = StartPoint.Y + Height
Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
MBo
  • 77,366
  • 5
  • 53
  • 86
  • Hey MBo and all. Do you know how to find the point at the end of the line crossing the startPoint and the endPoint (top of height)? I'm doing it like this: https://pastebin.com/Nvephzpr , but I don't know if it's appropriate. What do you say? – Contagrrla May 19 '23 at 09:10
  • I added coordinates of crossing (`?`) point. Your calculations are too complex for this task. You have similar triangles, so it is enough to use ratios rather than trigonometry functions. – MBo May 19 '23 at 09:16
  • Why are you answering this question instead of referring to math site? And you're just giving the solution instead of explaining the math. Is that the way to get 76k points? Just many easy pickings? – JHBonarius May 19 '23 at 18:09
  • Just note that if the bottom side is _not_ horizontal, you're back to (a)tan. – Mike 'Pomax' Kamermans May 19 '23 at 22:23
  • @Mike 'Pomax' Kamermans In this case additional data are needed – MBo May 20 '23 at 13:22
  • Overall rotation does not affect what to do. As long as they are similar, all you have to do is scaling. – fana May 22 '23 at 01:49
  • 1
    @fana I mean that two coordinates - vertice, some point at the side, and length of another side don't define triangle. – MBo May 22 '23 at 03:06