0

I understand how to calculate the hypotenuse a^2 + b^2 = c^2, sqrt(c) = hypotenuse. And I am aware there are some relevant answers already on stackoverflow, but they are immersed in terminology I don't understand(yet) as a beginner programmer.

As this is more programming orientated I haven't been able to find anything relevant on math websites either.

If you have a right angle triangle

             * |
  7.07   *     | 5
      *        |
   *           |
*_  _  _  _  _ |
       5 

How do I increment x and y (x,y) in cartesian format, so that I can draw in pixels SetPixel(myDC, x, y, COLOUR);

I somehow understand the concept of sin, cos and tan and their inverses, but can not for the life of me figure out how to increment (x,y) together in relation to the size of the adjacent and opposite lengths.

Cameron P
  • 57
  • 6
  • 2
    Any reason you can't just draw a line with `MoveTo` and `LineTo`? – Igor Tandetnik Oct 13 '15 at 05:44
  • 3
    If you really want to rasterize the line yourself, have a look at [Bresenham's line algorithm](https://en.wikipedia.org/wiki/Bresenham's_line_algorithm). – matz Oct 13 '15 at 05:54
  • If your endeavour is to learn about drawing a line, then you need to understand the [line drawing algorithms](https://en.wikipedia.org/wiki/Line_drawing_algorithm). However, if you just want to draw the triangle, use whatever @IgorTandetnik suggests. – legends2k Oct 13 '15 at 05:54
  • @IgorTandetnik Sorry, forgot to mention this was C++ not Javascript :P – Cameron P Oct 20 '15 at 06:13
  • @legends2k That link was quite informative. A lot of what I just read undoubtedly will become useful later on in my course. Thanks ! – Cameron P Oct 20 '15 at 06:14
  • And? What does JavaScript have to do with anything? If you can call `SetPixel`, then you can also call [`MoveToEx`](https://msdn.microsoft.com/en-us/library/dd145069.aspx) and [`LineTo`](https://msdn.microsoft.com/en-us/library/dd145029.aspx) – Igor Tandetnik Oct 20 '15 at 13:35
  • My bad, I immediately recognized it from my HTML days, didn't realize there was a C++ equivalent. – Cameron P Oct 23 '15 at 00:06

2 Answers2

1

Well they would be incremented relative to each other. So, if the legs of the triangle are of equal length, then the x and y increments should also be equal. Similarly, if one leg is, say, 3 and the other 4, then x and y should be incremented such that for each each x and y increment (x,y), x=4y/3 or y=4x/3.

cowdrool
  • 314
  • 1
  • 6
1

You can draw the hypotenuse with graphic functions for drawing lines between two points. Otherwise you can calculate the straight line equation passing for two points: y=mx + n and you avoid trigonometry functions.