Coordinate Transformation for Rotated Workpiece
#define PI 3.1415926535 /* * Macro to transform workpiece coordinates based on a rotation angle. * This is useful when the workpiece is fixtured at an angle relative to the machine axes. */ Sub TransformWorkpieceCoordinates(angleDegrees As Float, inputX As Float, inputY As Float,...
This macro applies a 2D rotation transformation to workpiece coordinates, which is essential when a part is fixtured at an angle on the CNC machine. It takes the rotation angle (in degrees) and the original X, Y, and Z c...
The `TransformWorkpieceCoordinates` macro takes an angle in degrees and input X, Y, Z coordinates. It first validates and normalizes the angle to be within 0-360 degrees. If the angle is 0 or 360, it directly assigns input to output coordinates, avoiding unnecessary calculations. Otherwise, it converts the angle to radians and computes its cosine and sine. The core transformation uses the 2D rotation matrix: `outputX = inputX * cos(angle) - inputY * sin(angle)` and `outputY = inputX * sin(angle) + inputY * cos(angle)`. The Z-coordinate remains unchanged. Helper functions `Modulo` and `Floor` are used for angle normalization. The time complexity is O(1) as it involves a fixed number of arithmetic and trigonometric operations. Space complexity is O(1) for its local variables.
FUNCTION TransformWorkpieceCoordinates(angleDegrees, inputX, inputY, inputZ, OUT outputX, OUT outputY, OUT outputZ): angleDegrees = Modulo(angleDegrees, 360.0) IF angleDegrees < 0 THEN angleDegrees += 360.0 IF angleDegre...