Files
ESP32-WijiBoard/test_render.js
T
PROFERIS - Mi³osz Stocki 242df22ba6 kienamtics
2026-07-08 14:53:47 +02:00

48 lines
1.3 KiB
JavaScript

const fs = require('fs');
const d2 = 12.9;
const l1 = 85;
const l2 = 110;
function stepsToRad(steps) {
return (steps / 2048) * 2 * Math.PI;
}
function render(steps1, steps2) {
const t1 = stepsToRad(steps1);
const t2 = stepsToRad(steps2);
const e1x = -d2 + l1 * Math.cos(t1);
const e1y = l1 * Math.sin(t1);
const e2x = d2 + l1 * Math.cos(t2);
const e2y = l1 * Math.sin(t2);
const dx = e2x - e1x;
const dy = e2y - e1y;
const dist = Math.sqrt(dx*dx + dy*dy);
let endX = 0, endY = 0;
if (dist <= 2*l2 && dist >= 1e-6) {
const a = dist / 2;
const h = Math.sqrt(l2*l2 - a*a);
const mx = (e1x + e2x) / 2;
const my = (e1y + e2y) / 2;
const px1 = mx + h * (dy / dist);
const py1 = my + h * (-dx / dist);
const px2 = mx - h * (dy / dist);
const py2 = my - h * (-dx / dist);
if (py1 >= py2) { endX = px1; endY = py1; }
else { endX = px2; endY = py2; }
}
console.log(`steps1=${steps1}, steps2=${steps2}`);
console.log(`t1=${(t1*180/Math.PI).toFixed(1)}°, t2=${(t2*180/Math.PI).toFixed(1)}°`);
console.log(`e1=(${e1x.toFixed(1)}, ${e1y.toFixed(1)})`);
console.log(`e2=(${e2x.toFixed(1)}, ${e2y.toFixed(1)})`);
console.log(`end=(${endX.toFixed(1)}, ${endY.toFixed(1)})`);
}
render(854, 41);
render(-41, 967);