For those who read this thread and like me were disappointed by the complete lack of response I eventually worked out a solution myself. Here is my (coded with comments) solution to the problem. I am not a expert and it may not be the best solution but it works.

Geometry/Trigonometry purist may frown about the conversions from radians to degrees but this is essential for this solution which works on the use of sectors determined by splitting a full rotation into a equal set of sectors.

If anyone has any improvements to this function I would appreciate any feedback.

Call the function with the last point plotted (fromX, fromY) and the current mouse position (toX, toY) as input parameters. The function returns a structure (DD.coords) that contains the coordinates of the end point of the rubber band line. You can use these coords along with the last point plotted to construct the rubber band line. (DD.RotationDivider can be set to any whole number number that is a divisor of 360 and represent sectors the edge lines of which are possible rubber band lines).

function determineAdjustedCoords(fromX, fromY, toX, toY) {

// this function uses the last point plotted, the length of the lines to the new x and y coords (using toX and toY) to determine an adjusted rubber band end-point

if (DD.ctrlPressed) {// if control is pressed then use toX and toY point for the coords of the end point of the rubber band line

DD.coords.x = toX;

DD.coords.y = toY;

return;

}

// find the angle subtended by the current rubber band line i.e. unadjusted (as dictated by the actual mouse coords) and the x axis

var xLen = toX - fromX;

var yLen = toY - fromY;

// if x or y difference is zero then no action needed so return

if (xLen == 0 && yLen == 0)

return;

var theta = Math.atan((yLen / xLen)) * (180 / Math.PI);

// find the hypontenuse of the triangle bounded by the x axis and the actual rubber band line - this will also be the hypontenuse of the adjusted rubber band line

var hyp;

// verify if any of the components are zero

if (Math.sin(theta * (Math.PI / 180)) == 0)

hyp = xLen;

else {

if (yLen == 0)

hyp == xLen;

else

hyp = yLen / ((Math.sin(theta * (Math.PI / 180))));

}

// find which sector the angle lies in and round it to the nearest sector

var sector = Math.round((theta / DD.RotationDivider));

// find the angle subtended by the adjusted rubber band line (as dictated by the coords we are trying to determine)

var thetaNew = sector * DD.RotationDivider;

// find new x and y coords of the adjusted rubber band line end points

var xNew = Math.cos(thetaNew * (Math.PI / 180)) * hyp;

var yNew = Math.sin(thetaNew * (Math.PI / 180)) * hyp;

// required coords equal the new coords added to the last point plotted (fromX,fromY)

DD.coords.x = fromX + Math.round(xNew);

DD.coords.y = fromY + Math.round(yNew);

return DD.coords;

}

As a challenge to all the experts on this forum please try to improve this solution.

Regards,