2.6 Right-Triangle Math for Programming

Key Takeaways

  • A programmed displacement is destination minus current position. Keep the coordinate signs through every subtraction.

  • For perpendicular legs, the Pythagorean theorem gives their straight-line separation: square the legs, sum the squares and take the square root.

  • With an angle measured from +X, use distance × cosine for X and distance × sine for Y. Add the components to the drawing center.

  • Use degree mode for drawing dimensions in degrees, keep full calculator precision through intermediate steps, and verify the quadrant before rounding the programmed endpoint.

Last updated: November 2026

2.6 Right-Triangle Math for Programming

The NIMS competency crosswalk lists signed arithmetic, the Pythagorean theorem, right-angle trigonometry and calculator use. These skills belong together when a drawing locates a feature by a length and an angle. Before entering a number in a mill program, draw a small sketch showing the origin, X and Y directions, the starting point and the target. Use one unit system throughout.

Find the Displacement Between Two Points

A drilling sketch gives points A = (−6, 9) mm and B = (6, 14) mm from the setup origin. The horizontal displacement is 6 − (−6) = +12 mm. The vertical displacement is 14 − 9 = +5 mm. The parentheses around the negative starting coordinate keep the subtraction unambiguous.

Because the X and Y movements are perpendicular, the hole center separation is 122+52=13\sqrt{12^2 + 5^2} = 13 mm. Adding 12 and 5 would give the length of an X-then-Y route, 17 mm. The drawing distance between the centers is the diagonal.

What the shop needsValue from sketch
B as an absolute endpoint, G90X6.0 Y14.0, with the drawing origin already active
B as an incremental endpoint from A, G91X12.0 Y5.0
Move back to A from B, G91X−12.0 Y−5.0
Straight center-to-center distance13 mm

The displacement uses the current position when the block runs, even if the program originally expected a different start. A shift of the work origin changes how both points map to the machine, but it does not change their separation. The diagonal calculation describes part geometry. For physical motion, still check that the selected feed or rapid path clears stock and fixtures.

Convert a Clockwise Drawing Angle

Suppose a second drawing locates a hole 24.000 mm from center C = (−12.000, +6.000) mm. The angle is 30 degrees clockwise from +X in the plan view. The hole is to the right and below C. With positive angles counterclockwise in this coordinate sketch, use θ=−30∘\theta=-30^\circ. Set the calculator to degrees before using sine and cosine.

  1. Compute the X component: 24.000cos⁡(−30∘)≈+20.784609724.000\cos(-30^\circ) \approx +20.7846097 mm.
  2. Compute the Y component: 24.000sin⁡(−30∘)=−12.00024.000\sin(-30^\circ)=-12.000 mm.
  3. Add both signed components to C. X is −12.000+20.7846097≈8.784610-12.000+20.7846097\approx 8.784610 mm and Y is 6.000−12.000=−6.0006.000-12.000=-6.000 mm.
  4. If the setup and programmed precision support the example’s 0.001 mm resolution, the rounded absolute location is X8.785 Y−6.000.
  5. Check the result: before rounding, the X and Y components give a separation of 24.000 mm by the Pythagorean theorem.

The center can be in a different quadrant from the resulting hole. Here C has negative X and positive Y, and the hole has positive X and negative Y. The sketch gives you a fast sign check. If a drawing measures the angle from +Y, convert the reference angle to +X first or label which measured leg is adjacent. Swapping the angle reference without swapping the legs puts the hole in the wrong place.

Solve an Angle from Measured Rise and Run

A ramp sketch rises 5 mm over a horizontal run of 12 mm. From the positive horizontal axis, the angle is arctan⁡(5/12)≈22.620∘\arctan(5/12)\approx22.620^\circ. Tangent compares opposite rise and adjacent run. Reverse the slope and the angle changes sign for the same +X run. When a vector points left or when the run is zero, a basic inverse tangent by itself cannot determine the full direction. Use the drawing quadrant or a documented two-argument arctangent function where available.

A setup print might give the same acute angle for holes above and below the center. If the previous 30-degree example were counterclockwise from +X, X would stay about 8.785 mm and Y would become +18.000 mm. Check which hole is intended before programming either sign. If you measure an angle clockwise from +Y, subtract that angle from +90 degrees to express it from +X. For example, 60 degrees clockwise from +Y equals +30 degrees from +X. Both components are positive in that case.

During a print and program check, keep the unrounded coordinate for the calculation record and round the program output to the precision allowed for that job. Then compare the calculated position, programmed destination, expected fixture origin and actual setup. Derived coordinates do not establish the allowable position error. The drawing and its tolerances govern the acceptance decision.

Sources: NIMS CNC mill competency crosswalk, OpenStax right-triangle trigonometry, and Haas absolute and incremental positioning.

Test Your Knowledge

What incremental motion goes from work (−6, 9) mm to (6, 14) mm?

A

X12.0 Y5.0

B

X0.0 Y23.0

C

X−12.0 Y−5.0

D

X6.0 Y14.0

Test Your Knowledge

A hole is 24 mm from a center at (−12, +6) mm, 30 degrees clockwise from +X. Where is the hole, rounded to 0.001 mm?

A

(−32.785, −6.000) mm

B

(8.785, 18.000) mm

C

(0.000, −14.785) mm

D

(8.785, −6.000) mm

Test Your Knowledge

A drawn ramp rises 5 mm in a horizontal run of 12 mm. What is its angle above the run?

A

About 67.380°

B

About 22.620°

C

About 24.624°

D

About 30.000°

Sections you finish are checked off in the contents.