WIP: firing arc cone angle does not change while rotating about pivot point

This commit is contained in:
Catalin Mititiuc 2024-03-21 16:42:22 -07:00
parent 2159804c11
commit 7da963cd8e

View File

@ -98,23 +98,37 @@ rect.addEventListener('mousemove', e => {
}
}
let width = x2px - x1px;
let height = -(y2px - y1px);
let angle = Math.abs(Math.atan(height / width));
let slope = (y2px - y1px) / (x2px - x1px);
let inverseSlope = -1 / slope;
if (width < 0 && height > 0) {
// angle = 180 - angle;
angle = Math.PI - angle;
} else if (width < 0 && height < 0) {
// angle = 180 + angle;
angle = Math.PI + angle;
} else if (width > 0 && height < 0) {
// angle = 360 - angle;
angle = 2 * Math.PI - angle;
}
console.log('slope', slope);
console.log('inverse slope', inverseSlope);
console.log('angle', angle, 'degrees', radToDeg(angle));
let smlArcAngle = Math.atan(pointDistanceInInches / (6 * calcY)) * 2;
let distance = Math.sqrt((x2px - x1px)**2 + (y2px - y1px)**2);
let newY1 = y2px + distance * Math.atan(smlArcAngle / 2);
let newY2 = y2px - distance * Math.atan(smlArcAngle / 2);
let newY1 = y2px + (distance * Math.cos(angle)) * Math.atan(smlArcAngle / 2);
let newY2 = y2px - (distance * Math.cos(angle)) * Math.atan(smlArcAngle / 2);
let newX1 = x2px + (distance * Math.sin(angle)) * Math.atan(smlArcAngle / 2);
let newX2 = x2px - (distance * Math.sin(angle)) * Math.atan(smlArcAngle / 2);
// p.setAttributeNS(null, 'points', `${newX},${newY} ${x1px},${y1px} ${newX},${newY}`);
// p.setAttributeNS(null, 'points', `${x2px},${y2px} ${x1px},${y1px} ${x2px},${y2px}`);
p.setAttributeNS(null, 'points', `${x2px},${newY1} ${x1px},${y1px} ${x2px},${newY2}`);
p.setAttributeNS(null, 'points', `${newX1},${newY1} ${x1px},${y1px} ${newX2},${newY2}`);
console.log(p);
// console.log(p);
if (x2 - x1 > 0 && y2 - y1 > 0) {
let yWhenXisMax = yIntercept(maxX);
@ -165,19 +179,19 @@ rect.addEventListener('mousemove', e => {
aim.setAttributeNS(null, 'x2', `${newX}in`);
aim.setAttributeNS(null, 'y2', `${newY}in`);
let width = aim.x2.baseVal.value - aim.x1.baseVal.value;
let height = -(aim.y2.baseVal.value - aim.y1.baseVal.value);
let angle = Math.abs(radToDeg(Math.atan(height / width)));
// let width = aim.x2.baseVal.value - aim.x1.baseVal.value;
// let height = -(aim.y2.baseVal.value - aim.y1.baseVal.value);
// let angle = Math.abs(radToDeg(Math.atan(height / width)));
if (width < 0 && height > 0) {
angle = 180 - angle;
} else if (width < 0 && height < 0) {
angle = 180 + angle;
} else if (width > 0 && height < 0) {
angle = 360 - angle;
}
// if (width < 0 && height > 0) {
// angle = 180 - angle;
// } else if (width < 0 && height < 0) {
// angle = 180 + angle;
// } else if (width > 0 && height < 0) {
// angle = 360 - angle;
// }
console.log(`${toFixed(angle)}\u00B0`);
// console.log(`${toFixed(angle)}\u00B0`);
}
});