Drawing lines from centre of circle to its boundary

Discussion in 'Homework Help' started by zulfi100, Feb 3, 2014.

Jun 7, 2012
320
0
Hi,
I want to draw lines from centre of circle to its boundary. First I want to draw lines on one half of the circle. I am using Ellipse function for drawing circle in VC++ which draws a square of diagonal (x1, y1) and (x2, y2).
Code ( (Unknown Language)):
1.
3.
6.
7.
8. int x1, y1, x2, y2, i, r, old_xc,old_yc, x,y;
9. int xc, yc;
10. x1=170;
11. y1=300;
12. x2=70;
13. y2=400;
14. pDC->Ellipse(x1,y1,x2,y2);
15. r= (y2-y1)/2;
16. old_xc=xc=x2+r;
17. old_yc=yc=y1+r;
18.
19. int Angle=360;
20.
21.
22.
23. x1 = (r) * Cos(Angle) ;
24. y1 = (r) * Sin(Angle) ;
25. for(i=0; i<50; ++i) {
26. x2 = (xc) + ((x1 * Cos(Angle)  - y1 * Sin(Angle)));
27. y2 = (yc) + ((x1 * Sin(Angle)  + y1 * Cos(Angle)));
28. pDC->MoveTo(old_xc, old_yc);
29. pDC->LineTo(x2,y2);
30. x1=x2;
31. y1=y2;
32. }
33.
34.
35.
Some body plz guide me with this problem.

Zulfi.

2. WBahn Moderator

Mar 31, 2012
18,087
4,917
This isn't making much sense.

You want to draw on a circle, but are using an Ellipse function that draws a square.

Huh?????

Could you provide a sketch, even in Paint, to give us a hint as to what you have and are trying to accomplish?

BMorse likes this.

Jun 7, 2012
320
0
Hi,
Actually there is no "circle" command in Visual C (VC).Turbo C has. So VC uses "Ellipse" function having four points (x1, y1, x2, y2) where (y1+x2= x1+y2) for circle. This results in a square formed with 2 coordinates and circle lies within the square (Note square is not visible). This is the explantion of Ellipse function if you are not familiar with VC.

My objective is to draw lines from centre of circle to boundary of a circle same thing as the CDC:ie function does but i dont want to use this function because i want to understand the underlying technology.

Right now i am using the equations of rotation transformation but its not producing lines within the circle. Lines are crossing the boundary of circle. Also there are only few lines. First of all i want to fill only half circle with lines that's why my loop counter variable is set to 50.

I have attached the output of my program. Sombody plz guide me.

Zulfi.

File size:
93.4 KB
Views:
15
4. MrChips Moderator

Oct 2, 2009
12,636
3,455
Your code seems very complicated. Why not something such as:

Code ( (Unknown Language)):
1.
2.
3. xc = 120;
4. yc = 350;
5. r = 50;
6. n = 50;
7. pi = 3.14159;
8.
9. for ( i = 0; i < n; i++)
10. {
11.   angle = i * 2 * pi /n;
12.   x = xc + r*cos(angle);
13.   y = yc + r*sin(angle);
14.   MoveTo( xc, yc);
15.   LineTo( x, y);
16. }
17.
18.
19.
20.

Jun 7, 2012
320
0
Hi,
Thanks for your work. I have attached the output. You can see the output that still there is some space between lines. I want to end up this space so that we can observe Moire Effect.

Zulfi.

File size:
4.8 KB
Views:
18