Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int data1[2], data2[2], DBTM = 2, ODBTM = 2;
- float pos1x, pos1y, pos2x, pos2y, dsq;
- double hvx = 0, hvy = 0, direction = 2*M_PI; //direction is the angle of the craft's orientation compared to the x axis, in radians! (going anticlockwise from the east) eg, 2pi = forward, pi/2 = facing to the left, pi = facing backwards, 3pi/2 = facing right, 0 = 2pi. direction = direction +- 2pi. in math.h pi is defined as M_PI. pi/2 = M_PI_2
- data1[1]=0;
- data1[2]=0;
- data2[1]=-1;
- data2[2]=1;
- pos1x = data1[1];
- pos1y = data1[2];
- while (((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2))>0) && (DBTM >= 0))
- {
- dsq = pow(DBTM-data1[1],2) + (data1[2]*data1[2]);
- DBTM--;
- }
- if (DBTM < 1) {DBTM = ODBTM;}
- while (((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2))>0) && (DBTM < (ODBTM * 2.0)))
- {
- dsq = pow(DBTM-data1[1],2) + (data1[2]*data1[2]);
- DBTM++;
- }
- if (DBTM<ODBTM*2.0)
- {
- dsq = pow(DBTM-data1[1],2) + (data1[2]*data1[2]);
- pos2x = DBTM;
- pos2y = 0;
- if (data2[2]<=0)
- {
- pos2y = (0.5 * (0 + data1[2])) + (0.5 * (0 - data1[2]) * (pow(DBTM,2) - (data2[1]*data2[1]+data2[2]*data2[2])) / dsq) - (2.0 * (DBTM-data1[1])*(0.25*sqrt(((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)))))/dsq);
- }
- else if (data2[2]>0)
- {
- pos2y = (0.5 * (0 + data1[2])) + (0.5 * (0 - data1[2]) * (pow(DBTM,2) - (data2[1]*data2[1]+data2[2]*data2[2])) / dsq) + (2.0 * (DBTM-data1[1])*(0.25*sqrt(((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)))))/dsq);
- }
- if (data2[1]<=0)
- {
- pos2x = (0.5 * (DBTM + data1[1])) + (0.5 * (DBTM - data1[1]) * (pow(DBTM,2) - (data2[1]*data2[1]+data2[2]*data2[2])) / dsq) - (2.0 * (0-data1[2])*(0.25*sqrt(((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)))))/dsq);
- }
- else if (data2[1]>0)
- {
- pos2x = (0.5 * (DBTM + data1[1])) + (0.5 * (DBTM - data1[1]) * (pow(DBTM,2) - (data2[1]*data2[1]+data2[2]*data2[2])) / dsq) + (2.0 * (0-data1[2])*(0.25*sqrt(((pow(DBTM+sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)-dsq)*(dsq-pow(DBTM-sqrt(data2[1]*data2[1]+data2[2]*data2[2]),2)))))/dsq);
- }
- } else {
- DBTM = ODBTM;
- pos2x = DBTM+data2[1];
- pos2y = data2[2];
- }
- if ((pos2x-pos1x > pow (2, -24)) || (pos2y-pos2x > pow (2, -24)) || (pos2y-pos2x < -pow (2, -24)) || (pos2y-pos2x < -pow (2, -24))) //pow(2, -24) = machine epsilon of "float"
- {
- direction += atan2(pos2y-pos1y, pos2x-pos1x);
- if (direction <= pow (2, -24)) {direction+=2*M_PI;}
- if (direction > 2*M_PI) {direction-=2*M_PI;}
- }
- printf("pos1x: %.1f\npos1y: %.1f\npos2x: %.1f\npos2y: %.1f\ndirection: %.5f\n",pos1x,pos1y,pos2x,pos2y,direction);
Add Comment
Please, Sign In to add comment