Hhhheeeellllpppppp!!!!!!!
Ok, in my computer math class my teacher asked me personally to see if I could create a program that would run a for loop to create a polygon. The user is to input the amount of sides and you should draw it. We start off looking to the stright up, then we start drawing the shape, the only problem are shapes that have interior angles that aren't factors of 360. I don't want the actual code, but is there maybe a formula that would do this?
Code:
for(int i=0;i<numOfSides;i++)
{
bot.move(100);
bot.turnRight(360/num);
}
My main problem is that I have to get the drawing tool to end up exactly where it started in the same direction (straight up). This is what I think I have:
Initial Turn:
Code:
int initialTurn=Math.abs(90-(360/numOfSides));
bot.turnRight(initialTurn);
Final Turn:
Code:
bot.turnRight(180);
bot.turnRight(180-initialTurn);
This all works as long as the interior angles are factors of 360.
Any solutions?
Thanks in advance!
Re: Hhhheeeellllpppppp!!!!!!!
To get an equilateral polygon from only integer commands is not possible. Check to see if your turtle (bot) class accepts floating-point. If so, this is trivial.
If not, then you can 'draw' on inspiration from a snail to get a concave polygon. If you need the polygon to be convex, then it is still possible, but a bit trickier.
If you study fractals, you may find more information. This problem is more creativity than math.