WIP: firing arc cone angle does not change while rotating about pivot point
This commit is contained in:
parent
37901a3813
commit
941b51e93a
52
index.js
52
index.js
@ -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);
|
if (width < 0 && height > 0) {
|
||||||
let inverseSlope = -1 / slope;
|
// 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('angle', angle, 'degrees', radToDeg(angle));
|
||||||
console.log('inverse slope', inverseSlope);
|
|
||||||
|
|
||||||
let smlArcAngle = Math.atan(pointDistanceInInches / (6 * calcY)) * 2;
|
let smlArcAngle = Math.atan(pointDistanceInInches / (6 * calcY)) * 2;
|
||||||
let distance = Math.sqrt((x2px - x1px)**2 + (y2px - y1px)**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', `${newX},${newY} ${x1px},${y1px} ${newX},${newY}`);
|
||||||
// p.setAttributeNS(null, 'points', `${x2px},${y2px} ${x1px},${y1px} ${x2px},${y2px}`);
|
// 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) {
|
if (x2 - x1 > 0 && y2 - y1 > 0) {
|
||||||
let yWhenXisMax = yIntercept(maxX);
|
let yWhenXisMax = yIntercept(maxX);
|
||||||
@ -165,19 +179,19 @@ rect.addEventListener('mousemove', e => {
|
|||||||
aim.setAttributeNS(null, 'x2', `${newX}in`);
|
aim.setAttributeNS(null, 'x2', `${newX}in`);
|
||||||
aim.setAttributeNS(null, 'y2', `${newY}in`);
|
aim.setAttributeNS(null, 'y2', `${newY}in`);
|
||||||
|
|
||||||
let width = aim.x2.baseVal.value - aim.x1.baseVal.value;
|
// let width = aim.x2.baseVal.value - aim.x1.baseVal.value;
|
||||||
let height = -(aim.y2.baseVal.value - aim.y1.baseVal.value);
|
// let height = -(aim.y2.baseVal.value - aim.y1.baseVal.value);
|
||||||
let angle = Math.abs(radToDeg(Math.atan(height / width)));
|
// let angle = Math.abs(radToDeg(Math.atan(height / width)));
|
||||||
|
|
||||||
if (width < 0 && height > 0) {
|
// if (width < 0 && height > 0) {
|
||||||
angle = 180 - angle;
|
// angle = 180 - angle;
|
||||||
} else if (width < 0 && height < 0) {
|
// } else if (width < 0 && height < 0) {
|
||||||
angle = 180 + angle;
|
// angle = 180 + angle;
|
||||||
} else if (width > 0 && height < 0) {
|
// } else if (width > 0 && height < 0) {
|
||||||
angle = 360 - angle;
|
// angle = 360 - angle;
|
||||||
}
|
// }
|
||||||
|
|
||||||
console.log(`${toFixed(angle)}\u00B0`);
|
// console.log(`${toFixed(angle)}\u00B0`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user