
June 28th, 2014, 03:34 AM
#1
Making an octagon out of right triangles
Hello all,
One exercise says that, "Define a right triangle class. Make an octagonal shape out of eight right triangles of different colors."
Making such a class isn't difficult. I wrote it as follows:
Code:
#include "Simple_window.h"
class right_triangle : public Shape {
public:
right_triangle(Point p, int l, int sh): c(p), _long(l), _short(sh)
{ add(Point (p));}
void draw_lines () const
{
fl_line(point(0).x, point(0).y, point(0).x, point(0).y+_long, point(0).x+_short, point(0).y+_long);
fl_line(point(0).x+_short, point(0).y+_long, point(0).x, point(0).y);
}
private:
Point c;
int _long, _short;
};
//*********************************
int main()
{
Simple_window win(Point(100,100), 700,500, "Octagon");
Point p(200,200);
int l = 80, sh = 60;
right_triangle rt(p,l,sh);
win.attach(rt);
win.wait_for_button();
}
But it sounds that making an octagon using eight right triangles isn't possible!
What's your thoughts please?

June 28th, 2014, 03:57 AM
#2
Re: Making an octagon out of right triangles
Originally Posted by abbassi
But it sounds that making an octagon using eight right triangles isn't possible!
What's your thoughts please?
It's easier with a picture but I'll try in words.
To get an octagon you inscribe a circle with 8 isosceles triangles. The angle between the equal sides of the triangles will be 45 degrees (8 time 45 degrees is 360 which is a full circle).
Now you inscribe two right triangles in each isosceles triangle. This splits the isosceles triangles in the middle giving them one 90 degree angle each making them right triangles.
So all in all you need 16 right triangles to build an octagon.
Last edited by razzle; June 28th, 2014 at 05:02 AM.

June 28th, 2014, 08:44 AM
#3
Re: Making an octagon out of right triangles
Yes, that's right. Thank you.

June 28th, 2014, 04:48 PM
#4
Re: Making an octagon out of right triangles
Originally Posted by abbassi
Yes, that's right. Thank you.
You're wellcome.
I know it's an exercise but note that representing an octagon with 16 right triangles is very inefficient. All it takes are two points, the centre point and one perimeter corner point. The rest can be deducted from that.

June 30th, 2014, 05:04 AM
#5
Re: Making an octagon out of right triangles
You don't need 16 triangles if it is okay to overlap them. Use two triangles to make a rectangle that touches two opposite sides of the octaton.
Make another such rectangle rotated 45 degrees to form the next pair of sides of the octagon. Repeat the procedure again two times...
Nobody cares how it works as long as it works

June 30th, 2014, 07:42 AM
#6
Re: Making an octagon out of right triangles
Last edited by razzle; June 30th, 2014 at 09:03 AM.

June 30th, 2014, 10:16 AM
#7
Re: Making an octagon out of right triangles
if the octagon is symettric, then you can do it with as few as 10 right triangles of 3 different sizes.
 take any 2 opposing edges, and connect them to make a rectangle. split the rectangle diagonally, these are the first 2 triangles
 both sides of the rectangle now have a trapezoid. Cut of the 2 "pointy sides" (2 more triangles on each of the 2 trapezoids = 4)
 split the remaining 2 rectangles diagonally to make 2 more for each (totalling 4 more)
There might be a way to do any convex octagon with fewer than 10 right triangles, but I'm not really seeing how.
a concave octagon can be done with as few as 4 right triangles. just make 2 rectangles (split diagonally) then put one short end of the rectangle next to the long end of the other.
Code:
++
\ 
 \ ++
 \ /
 \ ++
 \
++
the outer shape is a concave octagon

June 30th, 2014, 11:37 AM
#8
Re: Making an octagon out of right triangles
Crudely drawn but this is how you can do it with 8 right angle triangles.

June 30th, 2014, 04:17 PM
#9
Re: Making an octagon out of right triangles
Originally Posted by DavidI
Crudely drawn but this is how you can do it with 8 right angle triangles.
I'm pretty certain this doesn't work with a regular octagon (fully symmetric and equally long sides L). I suspect your solution works only if the diagonal sides in your picture have length sgrt(2)*L and the other sides length L. When all sides are L your solution will produce two nonright triangles. They must be split to be become right triangles. So to me it looks like 10 is the true minimum number of right triangles to cover a regular octagon but I may be wrong.
By all means if you have a solution I would be very interested. On the other hand I don't think the OP should worry much about it. People shouldn't be required to struggle with irrelevant secondary topics when the primary task is to learn how to program C++.
Last edited by razzle; July 1st, 2014 at 01:28 AM.

July 1st, 2014, 08:15 AM
#10
Re: Making an octagon out of right triangles
interesting approach
but yes, it only works for a very specific type of nonsymmetric octagon.
Using the orientation from #8, if the length of the edges of the vertal left/rightmost edge is X,
then the length of the diagonal outer edges will be
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!
