Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

where is my mistake

Status
Not open for further replies.

sisqu

Programmer
Feb 9, 2002
1
BG
Hi,
First I want to show you what I read in book and apply in this programme.
I want to write a programme for manage a cutting machine. For this I need a cicle for, whitch I count points by moving into circle. In book i read:
represent a sircle x=RcosA+x0;
y=RsinA+y0;
where: x0,y0 coordinates of center of circle,
R radius
or if I use integrale arithmetic: dx=-RsinAda dy=RcosAda
follow this:RcosA=x-x0, RsinA=y-y0;
so: dx=-(y-y0)da
dy=(x-x0)da

That means that I would use this extenses for count points:
x2=x1+dx=x1-(y1-y0)da
y2=y1+dy=y1+(x2-x0)da
In cutting machine I have first point x1, y1 present point x2,y2
and distance between first point x1,y1 and center of circlex0,y0
I and j t.e. x-x0=I, y-y0=J. And this programme must give points to moving by clockwise begin from x=0, y=10 (angle=90 degree) and stop when angle=45 degree(0,78 rad) instead it give points if it moves contraclock wise.
I wander if i'm wrong or the book wrong?

double wmin(double a1,double a2);

int main(void) {

int in=0;
double adrawn=0.00,x=0.00,y=10.00;
//adrawn-angle by moving, x y begin points
double xar=0.00,yar=10.00,i=0,j=10,da;
//* xar, yar present points; i and j distance between first point and center of circle i=x-x0, j=y-y0 */
da=wmin(0.01,1/(3.2*(i+j)));
//da=0,017453292

for(adrawn=0.00;adrawn<=0.785398163;adrawn=adrawn+da) {

xar=xar+(y-j-yar)*da;
yar=yar+(xar-x+i)*da;
printf(&quot; x=%f y=%f&quot;,xar,yar);
}

return 0;
}

double wmin(double a1,double a2) {
if(a1>a2) return a2;
return a1;
}
Thank you very much
 
use
xar=xar-(y-j-yar)*da;

instead of

xar=xar+(y-j-yar)*da;

in the FOR loop
Just check for the formula the book has used
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top