0

Can someone help?Pls!

Answered # Polygon formula [for graphics]

Featured Reply nmaillet 97 Featured Reply nucleon 114 Discussion Starter Alex_ Discussion Starter Alex_ Alibeg 1 Featured Reply Alibeg 1 Alibeg 1 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

0

Can someone help?Pls!

1

If my math is correct,

```
x(n) = x + r*cos(a + n*pass)
y(n) = y + r*sin(a + n*pass)
```

where `0 <= n < vertex`

, x and y is the center point, a is the angle of the first point to the right of the center point from the horizontal(counter-clockwise) and r is the distance from the center point to each of the vertices(the "radius"). Let me know if this is what you were looking for.

1

Also note that you have to use radians (not degrees) for your angles, so `pass = 2 * M_PI / vertex`

(M_PI is in math.h) .

0

Sort of ! But not really..

This is what i wrote

```
void polygon(int x, int y, int n, int r){
int k=0, *poly;
double pass= 360/n, _n=0,pass2=n*pass;
poly=new int[n];
while(k<n*2){
poly[k++]=x +r * cos(pass2);
poly[k++]=y +r * sin(pass2);
pass2+=pass;
}
drawpoly(n,poly);
}
```

as i understood , a is a=a+a; at each iteration? If it is so, it is not really what i expected, though it's better than nothing. Thx!

This is the output,at:

[img]http://sites.google.com/site/alexzaim/_/rsrc/1234900573771/Home/temp.jpg[/img]

0

tried some modifications

```
void polygon(int x, int y, int n, int r){
int k=0, *poly;
double pass= 2* M_PI/n,pass2=n*pass, a=360/n;
poly=new int[n];
while(k<n*2){
pass2+=a;
poly[k++]=x +r * cos(pass2);
poly[k++]=y +r * sin(pass2);
}
drawpoly(n,poly);
}
```

check:

[IMG]http://sites.google.com/site/alexzaim/_/rsrc/1234900573771/Home/temp2.jpg[/IMG]

0

a is constant, but n*pass changes because n changes

i dont know why do you use double pass = 360 / n

and after that pass2 = n * pass, do you mean pass2 = 360?

and why do you use _n?

dont forget about radians, because, i think, sin() and cos() use radians as input parameters

this is not about your previous post but one before it

1

double pass2 = a; //where a is angle between line (first point of polygon joined with centre of polygon) and x axis.....you might like to set pass2 to 0 in the beginning

while(k<n*2)

{

poly[k++]=x +r * cos(pass2);

poly[k++]=y +r * sin(pass2);

pass2 += pass;

}

this is how it goes i think

0

no prob, just dont forget to give the credits to a man who gave you the formula in the first place ;) (nmaillet)

This question has already been answered. Start a new discussion instead.

Recommended Articles

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...

the function that I created to find the ...