跳到正文
DEV Community· Oleg Shapkin·· 34 分鐘前AI 評分29

捲尺讀數為 1,502 mm 時:比較對角線而不預先進位

When the tape says 1,502 mm: comparing diagonals without premature rounding

AI 導讀

兩條相鄰邊長為 1,197 mm 和 903 mm 時,對角線目標長度約為 1,499.4 mm;捲尺讀數為 1,502 mm,與目標相差 2.6 mm。若先把目標進位至 1,499 mm,差值便會顯示為 +3 mm;應先按實際邊長計算,再只為顯示而進位。要確認對角線是否一致,應從相同的內角或外角參考點量度兩條對角線,並按工程項目和建造方式判斷可接受的公差。

正文

Oleg Shapkin

Disclosure: This article was drafted by an AI agent for the Pro² developer account. The numbers in the example were checked independently.

A tape measure gives you a real number, not a neat 3–4–5 triangle. Suppose a frame's adjacent sides measure 1,197 mm and 903 mm. What should the diagonal read? What do you tell someone whose tape reads 1,502 mm?

Keep the calculation and display precision apart

Use the same unit for both sides and the measurement. Compute the target from the actual sides, then subtract it from the tape reading. Round the result for display only. A positive difference means the reading is longer than the target.

function checkDiagonal(aMm, bMm, measuredMm) {
  if (![aMm, bMm, measuredMm].every(n => Number.isFinite(n) && n > 0)) {
    throw new RangeError('Enter positive lengths in millimetres');
  }
  const targetMm = Math.hypot(aMm, bMm);
  return { targetMm, differenceMm: measuredMm - targetMm };
}

const first = checkDiagonal(1197, 903, 1502);
const second = checkDiagonal(1197, 903, 1498);
console.log(first.targetMm.toFixed(1));     // 1499.4
console.log(first.differenceMm.toFixed(1)); // 2.6
console.log(second.differenceMm.toFixed(1)); // -1.4

If you round the target to 1,499 mm first, the same measurements appear to be +3 mm and −1 mm. The tape never changed. The order of operations did.

Tell the user what to measure next

One reading alone does not tell you whether the opposite edges match or whether the tape was hooked on the same reference point. Measure both diagonals between the same inside or outside corner references. Compare both against the target. For this example the two tape readings also differ from each other by 4 mm. Keep that comparison distinct from either reading’s difference from the target.

A calculator can report the target, the direction and the amount of the difference. The project and the way it will be built determine what tolerance is acceptable. If an interface also accepts inches and feet, convert once to a common length unit before subtracting and label the unit on every result.

You can reproduce both readings, one at a time, in the Pro² Square Check browser calculator. The author account belongs to the developer of Pro². The browser calculator is the demonstration for this example.

來源:DEV Community · dev.to