m316foley
12-11-2002, 07:49 PM
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?
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:
int initialTurn=Math.abs(90-(360/numOfSides));
bot.turnRight(initialTurn);
Final Turn:
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!
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:
int initialTurn=Math.abs(90-(360/numOfSides));
bot.turnRight(initialTurn);
Final Turn:
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!