need help in making shapes

Pages: 12
Your library likely has a function that draws a line from one point to another.
A triangle is drawn using three connected lines.
im just wondering if you can hint me on how to make the lines and set their angle? so they are equilateral triangle
Make a function that draws a pyramid at a specific point, this point being the middle of the triangle.
Note: the height of the triangle is sqrt(3)/2 times the side length.
Negating the height will reverse the pyramid.
Last edited on
line(int(x+L*cos(r)),int(y-L*sin(r)),int(x+L*cos(r+2*M_PI/3)),
int(y-L*sin(r+2*M_PI/3)));
line(int(x+L*cos(r+2*M_PI/3)),int(y-L*sin(r+2*M_PI/3)),
int(x+L*cos(r+4*M_PI/3)),int(y-L*sin(r+4*M_PI/3)));
line(int(x+L*cos(r+4*M_PI/3)),int(y-L*sin(r+4*M_PI/3)),
int(x+L*cos(r)),int(y-L*sin(r)));

ok this really killled my brain cells. i know its kinda messy and long. maybe you can give some advice?

the L is radius and r is rotation
Did you actually need rotatable triangles? It would have been a lot simpler if you could assume that the triangles would always point in the same direction.
thats what the assignment needs. :( mind to share the same direction triangle code?
Well, instead of making trigonometric calls, you could hard-code their results. For example, instead of cos(r+2*M_PI/3), you could have 1.0.
If (x|y) is the center, then (x-a/2 | y+h/2), (x+a/2 | y+h/2) and (x | y-h/2) are the three corners.
well but in the assignment the lecturer demanded : "a single number to indicate the angle of one vertex. This angle must be specified in radians, so if the vertex is straight up (above the center), then that parameter would have a value of M_PI/2. (The name M_PI is a predefined constant for pi from #include <cmath>.) Since the triange is equilateral, the other two vertexes will be at angles that are 2*M_PI/3 after the first vertex and 2*M_PI/3 before the first vertex."
Topic archived. No new replies allowed.
Pages: 12