You should be able to cycle a list of waypoints,
measure the distance to all of them,
find the closest, calculate the bearing, and draw an arrow pointing to it.
Was that the idea?
I finally got PBP working with MPLab again today,
The trig functions should be fine to rotate points around a screen
(2D screen with X - Y coordinates) yes ?
This is how I'd rotate points about an origin in C, where 160x240 is the origin
this was to connect the points for a 3D cube, so has a faked z axis as well:
Code:
// do pre-calculations for rotation
theta = rotation; // pre calculations
thetab = 360 - theta;
thetab = (3.141592 / 180) * theta;
ztheta = rotationz;
zthetab = 360 - ztheta;
zthetab = (3.141592 / 180) * ztheta;
for(cnt=0; cnt<8; cnt++) { // 3D rotate points
xx = xpoints[cnt];
yy = ypoints[cnt];
x = xx - 160;
y = yy - 240;
xnew = cos(thetab)*x - sin(thetab)*y;
ynew = sin(thetab)*x + cos(thetab)*y;
xnew = xnew + 160;
ynew = ynew + 240;
if (cnt < 4) {zxx = 160 + 76;} else {zxx = 160 - 76;}
zyy = ynew;
zx = zxx - 160;
zy = zyy - 240;
zxnew = cos(zthetab)*zx - sin(zthetab)*zy;
zynew = sin(zthetab)*zx + cos(zthetab)*zy;
zxnew = zxnew + 160;
zynew = zynew + 240;
xcoords[cnt+1] = xnew;
ycoords[cnt+1] = zynew;
}
The source and return data is coordinate integers, but it appears the trick you do
is multiplying out the fractions in the formula is to occupy integers and divide later?
Bookmarks