This is quite an involved process and would be good to work with one of our partners on if you're not comfortable making the modifications to the post processor.
However, ere is an example showing how you can move the toolpath points to the center of the ball (I have not tested this, so it might need minor tweaks / additional changes). First you need to create a function that will shift the point by a given distance along a vector. Here is a sample that does that which you could add to your post:
// Assuming the point is an array of three numbers [x, y, z]
// and the vector is an array of three numbers [vx, vy, vz]
// and the distance is a positive number
function movePointByDistance(point, vector, distance) {
// Calculate the magnitude of the vector
let magnitude = Math.sqrt(vector[0] * vector[0] + vector[1] * vector[1] + vector[2] * vector[2]);
// If the magnitude is zero, return the original point
if (magnitude === 0) {
return point;
}
// Normalize the vector by dividing each component by the magnitude
let normalized = [vector[0] / magnitude, vector[1] / magnitude, vector[2] / magnitude];
// Multiply each component of the normalized vector by the distance
let scaled = [normalized[0] * distance, normalized[1] * distance, normalized[2] * distance];
// Add the scaled components to the point coordinates
point[0] += scaled[0];
point[1] += scaled[1];
point[2] += scaled[2];
if (points != '') {
points += ','
}
points += valFormat.format(point[0]) + ',' + valFormat.format(point[1]) + ',' + valFormat.format(point[2])
}
This function will allow you to pass a (point, direction, distance) to move by. We will use this to move the points where needed.
Next, you will need to change where coordinates are output. In the onLinear and onRapid, you will see this lines:
var x = xOutput.format(_x);
var y = yOutput.format(_y);
var z = zOutput.format(_z);
We can move these points by changing them to this (you can do it with a check on the ball tool, like my example):
var x = xOutput.format(tool.type == TOOL_MILLING_END_BALL ? movePointByDistance(_x, currentSection.workPlane.forward, tool.diameter / 2) : _x);
var y = yOutput.format(tool.type == TOOL_MILLING_END_BALL ? movePointByDistance(_y, currentSection.workPlane.forward, tool.diameter / 2) : _y);
var z = zOutput.format(tool.type == TOOL_MILLING_END_BALL ? movePointByDistance(_z, currentSection.workPlane.forward, tool.diameter / 2) : _z);
Then, you will also need to adjust the points for initial positioning. To do that, I would add something like this
function writeInitialPositioning(position, isRequired, codes1, codes2) {
if (tool.type == TOOL_MILLING_END_BALL) {
position = new Vector(
movePointByDistance(position.x, currentSection.workPlane.forward, tool.diameter / 2),
movePointByDistance(position.y, currentSection.workPlane.forward, tool.diameter / 2),
movePointByDistance(position.z, currentSection.workPlane.forward, tool.diameter / 2),
);
}
Finally, you can move the points in onCircular like this
function onCircular(clockwise, cx, cy, cz, x, y, z, feed) {
if (tool.type == TOOL_MILLING_END_BALL) {
cx = movePointByDistance(cx, currentSection.workPlane.forward, tool.diameter / 2);
cy = movePointByDistance(cy, currentSection.workPlane.forward, tool.diameter / 2);
cz = movePointByDistance(cz, currentSection.workPlane.forward, tool.diameter / 2);
x = movePointByDistance(x, currentSection.workPlane.forward, tool.diameter / 2);
y = movePointByDistance(y, currentSection.workPlane.forward, tool.diameter / 2);
z = movePointByDistance(z, currentSection.workPlane.forward, tool.diameter / 2);
}
Hope this helps!
-
George Roberts
Manufacturing Product managerIf you'd like to provide feedback and discuss how you would like things to be in the future, Email Me and we can arrange a virtual meeting!