Hhhheeeellllpppppp!!!!!!!

Sharky Forums


Results 1 to 6 of 6

Thread: Hhhheeeellllpppppp!!!!!!!

  1. #1
    Hammerhead Shark m316foley's Avatar
    Join Date
    Nov 2000
    Posts
    2,706

    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!
    Amd Athlon Mobile 2600+ (200 X 12.5 @ 1.7)
    Asus A7N8X-Deluxe (Not Rev. 2)
    2-80gig WD Hard drives
    Corsair XMS pc3200 - 512megs
    Saphire Radeon 9800pro
    Soundblaster Live Platinum 5.1
    3Com EtherLink 10/100 3CR990-TX-97
    Creative Blaster v.92 Modem
    Sony Trinitron 21inch Monitor
    Plextor 24X Burnproof Cd-Writer
    Pioneer 16X DVD Drive
    Klipsch Ultras 5.1 Surround Sound
    Sony 3.5inch Floppy Drive
    Windows 2k of course...
    -------------------------
    Bart: Hey! Why is it killing my toys?
    Lisa: They must have programed it to destroy the competition.
    Bart: Sort of like Microsoft!
    -------------------------
    *HAVE A NICE DAY*

  2. #2
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077
    Well, my first instinct is the modulus operator. For integers that aren't factors of 360, save the remainder and apply it to future angles.

  3. #3
    Hammerhead Shark m316foley's Avatar
    Join Date
    Nov 2000
    Posts
    2,706
    But how would I apply it to other angles and still wind up in the same place? I guess I could just completely hack off the remainder and round it closest to one of the factors. But would that still leave me in the same place?
    Amd Athlon Mobile 2600+ (200 X 12.5 @ 1.7)
    Asus A7N8X-Deluxe (Not Rev. 2)
    2-80gig WD Hard drives
    Corsair XMS pc3200 - 512megs
    Saphire Radeon 9800pro
    Soundblaster Live Platinum 5.1
    3Com EtherLink 10/100 3CR990-TX-97
    Creative Blaster v.92 Modem
    Sony Trinitron 21inch Monitor
    Plextor 24X Burnproof Cd-Writer
    Pioneer 16X DVD Drive
    Klipsch Ultras 5.1 Surround Sound
    Sony 3.5inch Floppy Drive
    Windows 2k of course...
    -------------------------
    Bart: Hey! Why is it killing my toys?
    Lisa: They must have programed it to destroy the competition.
    Bart: Sort of like Microsoft!
    -------------------------
    *HAVE A NICE DAY*

  4. #4
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077
    I'm just kind of thinking off the cuff here, so bear with me...

    But why not just keep some variable as a "remainder" counter. Like:
    Code:
    remBucket=0;
    
    ...//code code code
    
    remBucket+=aNewRemainderFound;
    If you understand what I mean, you should be incrementing your remainder counter every time there's a remainder detected. Then, when you're drawing your final side to the polygon, divide remBucket by 10, and add 0.5 to it. Then type-cast that badboy into an integer, and ad the result to the angle on the final polygon side. I would think that would work just fine.

    Again, I'm just thinking off the top of my head, so if that was crappy advice I apologize

  5. #5
    Reef Shark
    Join Date
    Oct 2000
    Posts
    397

    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.

  6. #6
    Hammerhead Shark m316foley's Avatar
    Join Date
    Nov 2000
    Posts
    2,706
    Wow, thanks for the advice guys. Conrad nailed it with the turtle class I actually can't wait till I get to school tomorrow to try this out. Thanks!
    Amd Athlon Mobile 2600+ (200 X 12.5 @ 1.7)
    Asus A7N8X-Deluxe (Not Rev. 2)
    2-80gig WD Hard drives
    Corsair XMS pc3200 - 512megs
    Saphire Radeon 9800pro
    Soundblaster Live Platinum 5.1
    3Com EtherLink 10/100 3CR990-TX-97
    Creative Blaster v.92 Modem
    Sony Trinitron 21inch Monitor
    Plextor 24X Burnproof Cd-Writer
    Pioneer 16X DVD Drive
    Klipsch Ultras 5.1 Surround Sound
    Sony 3.5inch Floppy Drive
    Windows 2k of course...
    -------------------------
    Bart: Hey! Why is it killing my toys?
    Lisa: They must have programed it to destroy the competition.
    Bart: Sort of like Microsoft!
    -------------------------
    *HAVE A NICE DAY*

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •