1#define PI 3.1415926535
2
3
4
5
6
7Sub TransformWorkpieceCoordinates(angleDegrees As Float, inputX As Float, inputY As Float, inputZ As Float, ByRef outputX As Float, ByRef outputY As Float, ByRef outputZ As Float)
8Dim angleRadians As Float
9Dim cosAngle As Float
10Dim sinAngle As Float
11
12' --- Input Validation ---
13' Angle validation: Normalize angle to be within 0-360 degrees.
14angleDegrees = Modulo(angleDegrees, 360.0)
15If angleDegrees < 0 Then
16angleDegrees = angleDegrees + 360.0
17End If
18
19' If angle is 0 or 360, no transformation is needed.
20If angleDegrees = 0.0 Then
21outputX = inputX
22outputY = inputY
23outputZ = inputZ
24MsgBox "Rotation angle is 0 degrees. No transformation applied."
25Return
26End If
27
28' Convert angle from degrees to radians for trigonometric functions.
29angleRadians = angleDegrees * (PI / 180.0)
30
31' Calculate cosine and sine of the angle.
32cosAngle = Cos(angleRadians)
33sinAngle = Sin(angleRadians)
34
35' --- Apply 2D Rotation Transformation (around Z-axis) ---
36' The standard 2D rotation matrix is:
37' | cos(theta) -sin(theta) |
38' | sin(theta) cos(theta) |
39' Applied to [x, y]^T
40
41outputX = inputX * cosAngle - inputY * sinAngle
42outputY = inputX * sinAngle + inputY * cosAngle
43
44' Z-axis is typically unaffected by rotation around Z.
45outputZ = inputZ
46
47MsgBox "Coordinates transformed. Original (X,Y,Z): (" + Format(inputX) + "," + Format(inputY) + "," + Format(inputZ) + ")"
48MsgBox "Transformed (X,Y,Z): (" + Format(outputX) + "," + Format(outputY) + "," + Format(outputZ) + ")"
49
50End Sub
51
52
53
54
55Function Modulo(numerator As Float, denominator As Float) As Float
56' Basic modulo implementation for floats.
57Modulo = numerator - Floor(numerator / denominator) * denominator
58End Function
59
60
61
62
63Function Floor(value As Float) As Float
64' Placeholder for floor function.
65Floor = Int(value) ' Assuming Int truncates towards zero, adjust if needed.
66End Function
67
68
69
70
71Sub MsgBox(message As String)
72Print "[MESSAGE] " + message
73End Sub
74
75
76
77
78Function Format(value As Float) As String
79Format = "" + value
80End Function
81
82
83
84
85Sub Main()
86Dim rotationAngle As Float
87Dim originalX As Float, originalY As Float, originalZ As Float
88Dim transformedX As Float, transformedY As Float, transformedZ As Float
89
90Print "--- Test Case 1: Simple Rotation ---"
91rotationAngle = 90.0
92originalX = 10.0
93originalY = 0.0
94originalZ = 5.0
95TransformWorkpieceCoordinates(rotationAngle, originalX, originalY, originalZ, transformedX, transformedY, transformedZ)
96' Expected: X=0, Y=10, Z=5
97
98Print "\n--- Test Case 2: Rotation by 45 degrees ---"
99rotationAngle = 45.0
100originalX = 10.0
101originalY = 10.0
102originalZ = 2.0
103TransformWorkpieceCoordinates(rotationAngle, originalX, originalY, originalZ, transformedX, transformedY, transformedZ)
104' Expected: X=0, Y=14.14, Z=2
105
106Print "\n--- Test Case 3: Zero Rotation ---"
107rotationAngle = 0.0
108originalX = 20.0
109originalY = 30.0
110originalZ = 10.0
111TransformWorkpieceCoordinates(rotationAngle, originalX, originalY, originalZ, transformedX, transformedY, transformedZ)
112' Expected: X=20, Y=30, Z=10
113
114Print "\n--- Test Case 4: Rotation by 360 degrees ---"
115rotationAngle = 360.0
116originalX = 15.0
117originalY = 25.0
118originalZ = 8.0
119TransformWorkpieceCoordinates(rotationAngle, originalX, originalY, originalZ, transformedX, transformedY, transformedZ)
120' Expected: X=15, Y=25, Z=8
121
122Print "\n--- Test Case 5: Negative Angle ---"
123rotationAngle = -90.0
124originalX = 10.0
125originalY = 0.0
126originalZ = 5.0
127TransformWorkpieceCoordinates(rotationAngle, originalX, originalY, originalZ, transformedX, transformedY, transformedZ)
128' Expected: X=0, Y=-10, Z=5
129
130Print "\n--- Test Case 6: Angle greater than 360 ---"
131rotationAngle = 450.0
132originalX = 10.0
133originalY = 0.0
134originalZ = 5.0
135TransformWorkpieceCoordinates(rotationAngle, originalX, originalY, originalZ, transformedX, transformedY, transformedZ)
136' Expected: X=0, Y=10, Z=5
137
138End Sub