Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
|
vektor [2024/12/07 13:04] jango [Cross product] |
vektor [2024/12/07 17:32] (aktuell) jango [Vektor Visualisierung] |
||
|---|---|---|---|
| Zeile 165: | Zeile 165: | ||
| https:// | https:// | ||
| + | |||
| + | =====Vektor Visualisierung===== | ||
| + | |||
| + | < | ||
| + | < | ||
| + | <html lang=" | ||
| + | < | ||
| + | <meta charset=" | ||
| + | <meta name=" | ||
| + | < | ||
| + | < | ||
| + | body { margin: 0; font-family: | ||
| + | canvas { display: block; } | ||
| + | .controls { | ||
| + | position: absolute; | ||
| + | top: 10px; | ||
| + | left: 10px; | ||
| + | z-index: 1; | ||
| + | background: rgba(255, 255, 255, 0.7); | ||
| + | padding: 15px; | ||
| + | width: 240px; | ||
| + | height: 90%; | ||
| + | overflow-y: auto; | ||
| + | } | ||
| + | .section { | ||
| + | margin-bottom: | ||
| + | } | ||
| + | .section h3 { | ||
| + | margin-top: 0; | ||
| + | } | ||
| + | .section input, .section button { | ||
| + | width: 100%; | ||
| + | margin-bottom: | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | <div class=" | ||
| + | <!-- Vektor Eingabe --> | ||
| + | <div class=" | ||
| + | < | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | <button onclick=" | ||
| + | </ | ||
| + | |||
| + | <!-- Vektor Operationen --> | ||
| + | <div class=" | ||
| + | < | ||
| + | <button onclick=" | ||
| + | <button onclick=" | ||
| + | <button onclick=" | ||
| + | </ | ||
| + | |||
| + | <!-- Rotation der Szene --> | ||
| + | <div class=" | ||
| + | < | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | <input type=" | ||
| + | |||
| + | <label for=" | ||
| + | <input type=" | ||
| + | <input type=" | ||
| + | |||
| + | <label for=" | ||
| + | <input type=" | ||
| + | <input type=" | ||
| + | </ | ||
| + | |||
| + | <!-- Kamera Position und Rotation --> | ||
| + | <div class=" | ||
| + | < | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | |||
| + | <label for=" | ||
| + | <input type=" | ||
| + | |||
| + | <label for=" | ||
| + | <input type=" | ||
| + | |||
| + | <label for=" | ||
| + | <input type=" | ||
| + | |||
| + | <label for=" | ||
| + | <input type=" | ||
| + | |||
| + | <label for=" | ||
| + | <input type=" | ||
| + | |||
| + | <button onclick=" | ||
| + | <button onclick=" | ||
| + | </ | ||
| + | |||
| + | <!-- Ausgabe --> | ||
| + | <div class=" | ||
| + | <span id=" | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | <script src=" | ||
| + | <script src=" | ||
| + | |||
| + | < | ||
| + | const scene = new THREE.Scene(); | ||
| + | const camera = new THREE.PerspectiveCamera(75, | ||
| + | const renderer = new THREE.WebGLRenderer(); | ||
| + | renderer.setSize(window.innerWidth, | ||
| + | document.body.appendChild(renderer.domElement); | ||
| + | |||
| + | const light = new THREE.AmbientLight(0x404040, | ||
| + | scene.add(light); | ||
| + | |||
| + | const directionalLight = new THREE.DirectionalLight(0xffffff, | ||
| + | directionalLight.position.set(5, | ||
| + | scene.add(directionalLight); | ||
| + | |||
| + | function zoomIn() { | ||
| + | if (camera.position.z > 1) { | ||
| + | camera.position.z -= 1; | ||
| + | renderer.render(scene, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function zoomOut() { | ||
| + | camera.position.z += 1; | ||
| + | renderer.render(scene, | ||
| + | } | ||
| + | |||
| + | let v1 = new THREE.Vector3(1, | ||
| + | let v2 = new THREE.Vector3(3, | ||
| + | |||
| + | let arrowV1, arrowV2, arrowResultant, | ||
| + | |||
| + | function createArrow(vector, | ||
| + | const arrowHelper = new THREE.ArrowHelper(vector.clone().normalize(), | ||
| + | scene.add(arrowHelper); | ||
| + | return arrowHelper; | ||
| + | } | ||
| + | |||
| + | function createAxisAndScale() { | ||
| + | var maxNum = 9999; | ||
| + | |||
| + | const xAxisGeometry = new THREE.BufferGeometry().setFromPoints([ | ||
| + | new THREE.Vector3(0, | ||
| + | new THREE.Vector3(maxNum, | ||
| + | ]); | ||
| + | const xAxisMaterial = new THREE.LineBasicMaterial({ color: 0xff0000 }); | ||
| + | const xAxis = new THREE.Line(xAxisGeometry, | ||
| + | scene.add(xAxis); | ||
| + | |||
| + | const yAxisGeometry = new THREE.BufferGeometry().setFromPoints([ | ||
| + | new THREE.Vector3(0, | ||
| + | new THREE.Vector3(0, | ||
| + | ]); | ||
| + | const yAxisMaterial = new THREE.LineBasicMaterial({ color: 0x00ff00 }); | ||
| + | const yAxis = new THREE.Line(yAxisGeometry, | ||
| + | scene.add(yAxis); | ||
| + | |||
| + | const zAxisGeometry = new THREE.BufferGeometry().setFromPoints([ | ||
| + | new THREE.Vector3(0, | ||
| + | new THREE.Vector3(0, | ||
| + | ]); | ||
| + | const zAxisMaterial = new THREE.LineBasicMaterial({ color: 0x0000ff }); | ||
| + | const zAxis = new THREE.Line(zAxisGeometry, | ||
| + | scene.add(zAxis); | ||
| + | |||
| + | for (let i = 1; i <= maxNum; i++) { | ||
| + | const xMarker = new THREE.Mesh( | ||
| + | new THREE.SphereGeometry(0.1), | ||
| + | new THREE.MeshBasicMaterial({ color: 0xff0000 }) | ||
| + | ); | ||
| + | xMarker.position.set(i, | ||
| + | scene.add(xMarker); | ||
| + | |||
| + | const yMarker = new THREE.Mesh( | ||
| + | new THREE.SphereGeometry(0.1), | ||
| + | new THREE.MeshBasicMaterial({ color: 0x00ff00 }) | ||
| + | ); | ||
| + | yMarker.position.set(0, | ||
| + | scene.add(yMarker); | ||
| + | |||
| + | const zMarker = new THREE.Mesh( | ||
| + | new THREE.SphereGeometry(0.1), | ||
| + | new THREE.MeshBasicMaterial({ color: 0x0000ff }) | ||
| + | ); | ||
| + | zMarker.position.set(0, | ||
| + | scene.add(zMarker); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function updateVectors() { | ||
| + | v1.set( | ||
| + | parseFloat(document.getElementById(' | ||
| + | parseFloat(document.getElementById(' | ||
| + | parseFloat(document.getElementById(' | ||
| + | ); | ||
| + | |||
| + | v2.set( | ||
| + | parseFloat(document.getElementById(' | ||
| + | parseFloat(document.getElementById(' | ||
| + | parseFloat(document.getElementById(' | ||
| + | ); | ||
| + | |||
| + | scene.clear(); | ||
| + | |||
| + | createAxisAndScale(); | ||
| + | |||
| + | arrowV1 = createArrow(v1, | ||
| + | arrowV2 = createArrow(v2, | ||
| + | |||
| + | if (arrowResultant) scene.remove(arrowResultant); | ||
| + | if (arrowDifference) scene.remove(arrowDifference); | ||
| + | if (arrowCrossProduct) scene.remove(arrowCrossProduct); | ||
| + | |||
| + | displayVectorComponents(v1, | ||
| + | displayVectorComponents(v2, | ||
| + | |||
| + | renderer.render(scene, | ||
| + | } | ||
| + | |||
| + | function toggleResultant() { | ||
| + | if (arrowResultant) { | ||
| + | scene.remove(arrowResultant); | ||
| + | arrowResultant = null; | ||
| + | } else { | ||
| + | arrowResultant = createArrow(v1.clone().add(v2), | ||
| + | displayVectorComponents(v1.clone().add(v2), | ||
| + | renderer.render(scene, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function toggleDifference() { | ||
| + | if (arrowDifference) { | ||
| + | scene.remove(arrowDifference); | ||
| + | arrowDifference = null; | ||
| + | } else { | ||
| + | arrowDifference = createArrow(v1.clone().sub(v2), | ||
| + | displayVectorComponents(v1.clone().sub(v2), | ||
| + | renderer.render(scene, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function toggleCrossProduct() { | ||
| + | if (arrowCrossProduct) { | ||
| + | scene.remove(arrowCrossProduct); | ||
| + | arrowCrossProduct = null; | ||
| + | } else { | ||
| + | arrowCrossProduct = createArrow(v1.clone().cross(v2), | ||
| + | displayVectorComponents(v1.clone().cross(v2), | ||
| + | renderer.render(scene, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function displayVectorComponents(vector, | ||
| + | const output = document.getElementById(' | ||
| + | const outputText = `${label} - x: ${vector.x.toFixed(2)}, | ||
| + | output.textContent = outputText; | ||
| + | console.log(outputText); | ||
| + | } | ||
| + | |||
| + | /* | ||
| + | camera.position.x = document.getElementById(" | ||
| + | camera.position.y = document.getElementById(" | ||
| + | camera.position.z = document.getElementById(" | ||
| + | */ | ||
| + | |||
| + | function animate() { | ||
| + | requestAnimationFrame(animate); | ||
| + | |||
| + | scene.rotation.x = document.getElementById(' | ||
| + | scene.rotation.y = document.getElementById(' | ||
| + | scene.rotation.z = document.getElementById(' | ||
| + | |||
| + | renderer.render(scene, | ||
| + | } | ||
| + | |||
| + | function updateCamera() { | ||
| + | camera.position.set( | ||
| + | parseFloat(document.getElementById(' | ||
| + | parseFloat(document.getElementById(' | ||
| + | parseFloat(document.getElementById(' | ||
| + | ); | ||
| + | |||
| + | camera.rotation.set( | ||
| + | parseFloat(document.getElementById(' | ||
| + | parseFloat(document.getElementById(' | ||
| + | parseFloat(document.getElementById(' | ||
| + | ); | ||
| + | |||
| + | renderer.render(scene, | ||
| + | } | ||
| + | |||
| + | window.addEventListener(' | ||
| + | renderer.setSize(window.innerWidth, | ||
| + | camera.aspect = window.innerWidth / window.innerHeight; | ||
| + | camera.updateProjectionMatrix(); | ||
| + | }); | ||
| + | |||
| + | document.getElementById(' | ||
| + | scene.rotation.x = this.value * Math.PI / 180; | ||
| + | document.getElementById(' | ||
| + | }); | ||
| + | |||
| + | document.getElementById(' | ||
| + | scene.rotation.y = this.value * Math.PI / 180; | ||
| + | document.getElementById(' | ||
| + | }); | ||
| + | |||
| + | document.getElementById(' | ||
| + | scene.rotation.z = this.value * Math.PI / 180; | ||
| + | document.getElementById(' | ||
| + | }); | ||
| + | |||
| + | document.getElementById(' | ||
| + | const value = parseFloat(this.value); | ||
| + | scene.rotation.x = value * Math.PI / 180; | ||
| + | document.getElementById(' | ||
| + | }); | ||
| + | |||
| + | document.getElementById(' | ||
| + | const value = parseFloat(this.value); | ||
| + | scene.rotation.y = value * Math.PI / 180; | ||
| + | document.getElementById(' | ||
| + | }); | ||
| + | |||
| + | document.getElementById(' | ||
| + | const value = parseFloat(this.value); | ||
| + | scene.rotation.z = value * Math.PI / 180; | ||
| + | document.getElementById(' | ||
| + | }); | ||
| + | |||
| + | document.getElementById(' | ||
| + | document.getElementById(' | ||
| + | document.getElementById(' | ||
| + | document.getElementById(' | ||
| + | document.getElementById(' | ||
| + | document.getElementById(' | ||
| + | |||
| + | animate(); | ||
| + | updateVectors(); | ||
| + | updateCamera(); | ||
| + | |||
| + | //for(var i = 0; i<5; i++) zoomOut(); | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| =====Links===== | =====Links===== | ||