Click to See Complete Forum and Search --> : NEED a function to draw an arc using lines!


gillagolla
October 17th, 2008, 11:44 AM
Hi guys,
i need to write a function in C++ which draws an arc on a graphic window using lines.. the function description follows;

prompts the user to click on the centre Point of the circular arc and then on the starting Point of the arc circumference. Next it asks the user to click on any Point on the terminal arm of the arc. This Point does not have to be at the correct radius, since that would be almost impossible. The function draws the counterclockwise arc. If the terminal arm is located clockwise at an angle less that 180 degrees relative to the starting Point, then the reflexive angle will be drawn as shown if Figure 3..

i tried ma best and came up with an algorithm to for this(image attached), but I'm unable to complete that. hope some one can help me out!!

This is my code, I'm using a different class for the graphic window! All i want is just an idea, an algorithm!! even if someone can come up with something in other programming languages that would be helpful!!

void mouseArc()
{
Point center = cwin.get_mouse("Click on Arc Center");
Point start = cwin.get_mouse("Click on the arc start point on its circumference");
Point cir = cwin.get_mouse("Click on anypoint on the CCW terminal arm of the arc");

float cenX=center.get_x(), cenY=center.get_y(); //center point
float srtX=start.get_x(), srtY=start.get_y(); //starting point
float cirX=cir.get_x(), cirY=cir.get_y(); //ending point
float tempx=0.0, tempy=0.0;

//radoius of the arc
float radious = sqrt(pow((srtX-cenX),2)+pow((srtY-cenY),2));

//distance from the center to circumference point
float distance = sqrt(pow((cirX-cenX),2)+pow((cirY-cenY),2));

//x Axis of the original end point(unit vector*radios+centerpoint)
float endX= ((radious*(cirX-cenX))/distance)+cenX;

//y Axis of the Original end point(unit vector*radios+centerpoint)
float endY= ((radious*(cirY-cenY))/distance)+cenY;
while(srtX+(radious-radious*cos(theta))!=endX && srtY+radious*sin(theta)!=endY)
{
tempx=0;
tempy=0;
tempx= srtX+(radious-radious*cos(theta));
tempy= srtY+radious*sin(theta);
cwin<<Line(Point(srtX,srtY),Point(tempx,tempy));
srtX=tempx;
srtY=tempy;
}

/*for(float theta=2*M_PI/60; srtX+(radious-radious*cos(theta))!=endX && srtY+radious*sin(theta)!=endY; theta+=6)
{
tempx= srtX+(radious-radious*cos(theta));
tempy= srtY+radious*sin(theta);
cwin<<Line(Point(srtX,srtY),Point(tempx,tempy));
srtX=tempx;
srtY=tempy;
}*/

}

i don't know whether to use the for loop or while loop!

Lindley
October 17th, 2008, 01:53 PM
Couple of things I notice.....

-Radius and distance are going to be the same.
-I don't see any calls to atan2(), which is typically used for problems like this.
-You probably want to calculate your tempx/tempy from cenX/Y, not srtX/Y.

There may be more, I didn't look too closely.