Web Dev Solutions

Catalin Mititiuc

From aba937c4596c110f233e41f348d03a7ec8b02621 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Thu, 21 Mar 2024 22:23:58 -0700 Subject: WIP: firing arcs: fix cone angle calculation --- index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 722bb62..a12ebf5 100644 --- a/index.js +++ b/index.js @@ -115,14 +115,19 @@ rect.addEventListener('mousemove', e => { console.log('angle', angle, 'degrees', radToDeg(angle)); - let smlArcAngle = Math.atan(pointDistanceInInches / (6 * calcY)) * 2; + let smlArcAngle = Math.atan(pointDistanceInInches / (6 * calcY)); + let medArcAngle = Math.atan((pointDistanceInInches / 2) / calcY); + let lrgArcAngle = Math.atan((21 * pointDistanceInInches) / (6 * calcY)); + + let arcAngle = lrgArcAngle; + let distance = Math.sqrt((x2px - x1px)**2 + (y2px - y1px)**2); - let newY1 = y2px + (distance * Math.cos(angle)) * Math.atan(smlArcAngle / 2); - let newY2 = y2px - (distance * Math.cos(angle)) * Math.atan(smlArcAngle / 2); + let newY1 = y2px + (distance * Math.cos(angle)) * Math.tan(arcAngle); + let newY2 = y2px - (distance * Math.cos(angle)) * Math.tan(arcAngle); - let newX1 = x2px + (distance * Math.sin(angle)) * Math.atan(smlArcAngle / 2); - let newX2 = x2px - (distance * Math.sin(angle)) * Math.atan(smlArcAngle / 2); + let newX1 = x2px + (distance * Math.sin(angle)) * Math.tan(arcAngle); + let newX2 = x2px - (distance * Math.sin(angle)) * Math.tan(arcAngle); // p.setAttributeNS(null, 'points', `${newX},${newY} ${x1px},${y1px} ${newX},${newY}`); // p.setAttributeNS(null, 'points', `${x2px},${y2px} ${x1px},${y1px} ${x2px},${y2px}`); @@ -176,6 +181,10 @@ rect.addEventListener('mousemove', e => { } } + distance = Math.sqrt((x2 - x1)**2 + (y2 - y1)**2); + newY = y2 + (distance * Math.cos(angle)) * Math.tan(arcAngle); + newX = x2 + (distance * Math.sin(angle)) * Math.tan(arcAngle); + aim.setAttributeNS(null, 'x2', `${newX}in`); aim.setAttributeNS(null, 'y2', `${newY}in`); -- cgit v1.2.3