Changed around line 1
+ function calculateDotProduct() {
+ const ax = parseFloat(document.getElementById('ax').value);
+ const ay = parseFloat(document.getElementById('ay').value);
+ const az = parseFloat(document.getElementById('az').value);
+ const bx = parseFloat(document.getElementById('bx').value);
+ const by = parseFloat(document.getElementById('by').value);
+ const bz = parseFloat(document.getElementById('bz').value);
+
+ const dotProduct = ax*bx + ay*by + az*bz;
+
+ document.getElementById('dotResult').textContent = dotProduct.toFixed(2);
+ document.getElementById('calculation').innerHTML =
+ `(${ax}×${bx}) + (${ay}×${by}) + (${az}×${bz}) = `;
+
+ updateVisualization(ax, ay, az, bx, by, bz);
+ }
+
+ function updateVisualization(ax, ay, az, bx, by, bz) {
+ const canvas = document.getElementById('vectorCanvas');
+ const ctx = canvas.getContext('2d');
+ const scale = 30;
+
+ canvas.width = canvas.offsetWidth;
+ canvas.height = canvas.offsetHeight;
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ // Coordinate system
+ ctx.beginPath();
+ ctx.moveTo(0, canvas.height/2);
+ ctx.lineTo(canvas.width, canvas.height/2);
+ ctx.moveTo(canvas.width/2, 0);
+ ctx.lineTo(canvas.width/2, canvas.height);
+ ctx.strokeStyle = '#e2e8f0';
+ ctx.stroke();
+
+ // Draw vectors
+ function drawVector(x, y, z, color) {
+ const scaleFactor = 0.8;
+ const sx = canvas.width/2 + x*scale*scaleFactor;
+ const sy = canvas.height/2 - y*scale*scaleFactor;
+
+ ctx.beginPath();
+ ctx.moveTo(canvas.width/2, canvas.height/2);
+ ctx.lineTo(sx, sy);
+ ctx.strokeStyle = color;
+ ctx.lineWidth = 3;
+ ctx.stroke();
+
+ // Arrowhead
+ const angle = Math.atan2(sy - canvas.height/2, sx - canvas.width/2);
+ ctx.beginPath();
+ ctx.moveTo(sx, sy);
+ ctx.lineTo(sx - 10*Math.cos(angle - Math.PI/6), sy - 10*Math.sin(angle - Math.PI/6));
+ ctx.moveTo(sx, sy);
+ ctx.lineTo(sx - 10*Math.cos(angle + Math.PI/6), sy - 10*Math.sin(angle + Math.PI/6));
+ ctx.stroke();
+ }
+
+ drawVector(ax, ay, az, '#2563eb');
+ drawVector(bx, by, bz, '#f59e0b');
+ }
+
+ document.querySelectorAll('input').forEach(input => {
+ input.addEventListener('input', function() {
+ if (this.type === 'range') {
+ const numberInput = this.parentElement.querySelector('.number-input');
+ numberInput.value = this.value;
+ } else {
+ const rangeInput = this.parentElement.querySelector('input[type="range"]');
+ rangeInput.value = this.value;
+ }
+ calculateDotProduct();
+ });
+ });
+
+ // Initial calculation
+ calculateDotProduct();
+ window.addEventListener('resize', calculateDotProduct);