Wednesday, 20 May 2020

Chapter 13 // Exercise 14 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and the graphics files found here:
https://github.com/l-paz91/principles-practice/tree/master/Graphics%20Files

Chapter 13 // Exercise 14

Define a right triangle class. Make an octagonal shape out of eight right triangles of different colours.

Github: https://github.com/l-paz91/principles-practice/tree/master/Chapter%2013/Exercise%2014


I really wanted to make a function that could draw any polygon with triangles but it required way to much brain power and at this point in the evening I've had quite a bit to drink and can't be bothered so I'm just going to brute force it. I was also confused because I kept thinking of a Regular octagon and seriously wondered if you could even make a regular octagon out of right triangles. I googled this high and low and managed to find this thread of someone doing the same exercise: 
http://forums.codeguru.com/showthread.php?545831-Making-an-octagon-out-of-right-triangles

An image of a regular octagon made out of right triangles is shown but there are arguments as to whether this is correct or not. So I thought, why not make the constructor throw an error if one of the angles in the triangles is not 90 degrees? Turns out determining the angles of intersecting lines is a bit more complicated then I thought.

I eventually found this post which made sense. I can't stand it when they use things like slope and r1 and squiggly symbols. I have no idea what any of that means, maths stack overflow is my worst nightmare:
https://stackoverflow.com/questions/3365171/calculating-the-angle-between-two-lines-without-having-to-calculate-the-slope

With this though I managed to give RightTriangle a function that gets the angle between 2 lines. You do need to input the points in a certain way when creating the triangle (the right-angle should always be the second point) but it is possible to create an octagon with all right-angled triangles; but it is not possible to create a regular octagon out of all right-angled triangles. 


No comments:

Post a Comment