Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,343 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,116 people online right now. Registration is fast and FREE... Join Now!




Polygons

 
Reply to this topicStart new topic

Polygons, Just need a point in the right direction please?

Tara200
post 2 Apr, 2008 - 08:04 AM
Post #1


New D.I.C Head

*
Joined: 13 Oct, 2007
Posts: 39


My Contributions


Hi , i have a piece of coursework that has to be in tomorrow -it calculates polygons using pythagoras equation the classes line.cc , point.cc and the h files are all complete and correctly coded i am just stuck on implementing the main file-any help would be great as i am really stuck?

CODE
//polygon.cc
#include "point.h"
#include "line.h"
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
  int x;
  int y;
  int sides;
  cout << "Enter the number of sides between 3 and 9 Inclusive" << endl;
  cin >> sides;
  for ( int i=0; i<sides; i++ )
  {
    cout << "Enter the co-ordinates as x and y" << endl;
    cin >> x >> y;
  }

  int length;
  for ( int i =0; i < length; length++)
  {
  int dx = p1.getx() - p2.getx();
  int dy = p1.gety() - p2.gety();
  length = sqrt ( (dx*dx) + (dy*dy));
  return length;

   cout << " Total length = " << length << endl;
  }
}  


The user enters the number of sides of a polygon and it calculates the polygon boundary blink.gif

*Mod Edit: added code tags: code.gif
User is offlineProfile CardPM

Go to the top of the page

Tara200
post 2 Apr, 2008 - 01:37 PM
Post #2


New D.I.C Head

*
Joined: 13 Oct, 2007
Posts: 39


My Contributions


Anyone???
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 2 Apr, 2008 - 02:00 PM
Post #3


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


So you are given a point and # sides. Well There are formulas that you can look up that will calculate the angles needed to construct a regular polygon. It might help if you knew something about the size of your polygon... Generally you would like to know the distance from the center to a vertex (the radius of the bounding circle).

I for one would probably use the parametric formula:

xi = r*cos(i*theta)
yi = r*sin(i*theta)

but that is only 1 of about 3 ways I can think of off the top of my head.
User is offlineProfile CardPM

Go to the top of the page

Tara200
post 2 Apr, 2008 - 02:36 PM
Post #4


New D.I.C Head

*
Joined: 13 Oct, 2007
Posts: 39


My Contributions


Hi thanks for your reply, no i haven't been given a size of the polygon, the instructions are
to determine the length of an irregular polgon between 3 and 9 sides
The user is prompted to enter the number of sides between 3 and 9 and prompted to enter the co-ordinates of each vertex point.
the program then calculates the length of the boundary and displays it ?

do you have simple way of doing it maths is not my best point?
User is offlineProfile CardPM

Go to the top of the page

KYA
post 2 Apr, 2008 - 02:59 PM
Post #5


#include <nerd.h>

Group Icon
Joined: 14 Sep, 2007
Posts: 4,205



Thanked 50 times

Dream Kudos: 1150
My Contributions


Oh, so you need to find the perimeter of the polygon?

Use the distance formula between each set of points and add them together.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 03:38AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month