Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
vektor [2024/12/07 16:56] jango |
vektor [2024/12/07 17:32] (aktuell) jango [Vektor Visualisierung] |
||
---|---|---|---|
Zeile 174: | Zeile 174: | ||
<meta charset=" | <meta charset=" | ||
<meta name=" | <meta name=" | ||
- | < | + | < |
< | < | ||
body { margin: 0; font-family: | body { margin: 0; font-family: | ||
Zeile 184: | Zeile 184: | ||
z-index: 1; | z-index: 1; | ||
background: rgba(255, 255, 255, 0.7); | background: rgba(255, 255, 255, 0.7); | ||
- | padding: 10px; | + | 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: 10px; | ||
} | } | ||
- | .controls input { margin-bottom: | ||
</ | </ | ||
</ | </ | ||
< | < | ||
<div class=" | <div class=" | ||
- | < | + | |
- | <label for=" | + | <div class=" |
- | <input type=" | + | |
- | <label for=" | + | <label for=" |
- | <input type=" | + | <input type=" |
- | <label for=" | + | <label for=" |
- | <input type=" | + | <input type=" |
+ | <label for=" | ||
+ | <input type=" | ||
+ | <label for=" | ||
+ | <input type=" | ||
+ | <label for=" | ||
+ | <input type=" | ||
+ | <label for=" | ||
+ | <input type=" | ||
+ | <button onclick=" | ||
+ | </div> | ||
- | <label for=" | + | <!-- Vektor |
- | <input type="number" | + | <div class="section"> |
- | <label for=" | + | <h3> |
- | <input type="number" | + | <button onclick="toggleResultant()">Zeige Resultierende</ |
- | <label for="v2z">Vektor 2 (z): </label> | + | <button onclick="toggleDifference()">Zeige Differenz</button>< |
- | <input type="number" | + | <button onclick="toggleCrossProduct()">Zeige Kreuzprodukt</ |
+ | </div> | ||
- | <button onclick="updateVectors()"> | + | <!-- Rotation der Szene --> |
- | <button onclick="toggleResultant()"> | + | <div class="section"> |
- | <button onclick=" | + | < |
- | <button onclick=" | + | <label for=" |
- | + | <input type=" | |
- | <span id=" | + | <input type=" |
+ | |||
+ | | ||
+ | <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=" | ||
+ | | ||
+ | |||
+ | | ||
+ | <div class=" | ||
+ | | ||
+ | </div> | ||
</ | </ | ||
<script src=" | <script src=" | ||
- | <script src=" | + | <script src=" |
< | < | ||
const scene = new THREE.Scene(); | const scene = new THREE.Scene(); | ||
Zeile 230: | Zeile 293: | ||
scene.add(directionalLight); | scene.add(directionalLight); | ||
- | | + | |
+ | 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 v1 = new THREE.Vector3(1, | ||
let v2 = new THREE.Vector3(3, | let v2 = new THREE.Vector3(3, | ||
Zeile 236: | Zeile 310: | ||
let arrowV1, arrowV2, arrowResultant, | let arrowV1, arrowV2, arrowResultant, | ||
- | // Funktion zum Erstellen von Pfeilen | ||
function createArrow(vector, | function createArrow(vector, | ||
const arrowHelper = new THREE.ArrowHelper(vector.clone().normalize(), | const arrowHelper = new THREE.ArrowHelper(vector.clone().normalize(), | ||
Zeile 243: | Zeile 316: | ||
} | } | ||
- | | + | function |
- | | + | |
- | | + | |
- | // X-Achse | + | const xAxisGeometry = new THREE.BufferGeometry().setFromPoints([ |
- | const xAxisGeometry = new THREE.BufferGeometry().setFromPoints([ | + | |
new THREE.Vector3(0, | new THREE.Vector3(0, | ||
- | new THREE.Vector3(axisLength, 0, 0) | + | new THREE.Vector3(maxNum, 0, 0) |
]); | ]); | ||
const xAxisMaterial = new THREE.LineBasicMaterial({ color: 0xff0000 }); | const xAxisMaterial = new THREE.LineBasicMaterial({ color: 0xff0000 }); | ||
Zeile 255: | Zeile 327: | ||
scene.add(xAxis); | scene.add(xAxis); | ||
- | | + | const yAxisGeometry = new THREE.BufferGeometry().setFromPoints([ |
- | | + | |
new THREE.Vector3(0, | new THREE.Vector3(0, | ||
- | new THREE.Vector3(0, | + | new THREE.Vector3(0, |
]); | ]); | ||
const yAxisMaterial = new THREE.LineBasicMaterial({ color: 0x00ff00 }); | const yAxisMaterial = new THREE.LineBasicMaterial({ color: 0x00ff00 }); | ||
Zeile 264: | Zeile 335: | ||
scene.add(yAxis); | scene.add(yAxis); | ||
- | | + | const zAxisGeometry = new THREE.BufferGeometry().setFromPoints([ |
- | | + | |
new THREE.Vector3(0, | new THREE.Vector3(0, | ||
- | new THREE.Vector3(0, | + | new THREE.Vector3(0, |
]); | ]); | ||
const zAxisMaterial = new THREE.LineBasicMaterial({ color: 0x0000ff }); | const zAxisMaterial = new THREE.LineBasicMaterial({ color: 0x0000ff }); | ||
const zAxis = new THREE.Line(zAxisGeometry, | const zAxis = new THREE.Line(zAxisGeometry, | ||
scene.add(zAxis); | 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); | ||
+ | } | ||
} | } | ||
- | // Update der Vektoren | ||
function updateVectors() { | function updateVectors() { | ||
- | // Werte aus den Eingabefeldern holen | ||
v1.set( | v1.set( | ||
parseFloat(document.getElementById(' | parseFloat(document.getElementById(' | ||
Zeile 289: | Zeile 380: | ||
); | ); | ||
- | // Szene leeren | ||
scene.clear(); | scene.clear(); | ||
- | | + | |
- | createAxes(); | + | |
- | | + | arrowV1 = createArrow(v1, |
- | | + | arrowV2 = createArrow(v2, |
- | arrowV2 = createArrow(v2, | + | |
- | // Reset der resultierenden Vektorpfeile | ||
if (arrowResultant) scene.remove(arrowResultant); | if (arrowResultant) scene.remove(arrowResultant); | ||
if (arrowDifference) scene.remove(arrowDifference); | if (arrowDifference) scene.remove(arrowDifference); | ||
if (arrowCrossProduct) scene.remove(arrowCrossProduct); | if (arrowCrossProduct) scene.remove(arrowCrossProduct); | ||
- | // Zeige Vektor-Komponenten im Output | ||
displayVectorComponents(v1, | displayVectorComponents(v1, | ||
displayVectorComponents(v2, | displayVectorComponents(v2, | ||
Zeile 311: | Zeile 397: | ||
} | } | ||
- | // Resultierender Vektor (Addition) | ||
function toggleResultant() { | function toggleResultant() { | ||
if (arrowResultant) { | if (arrowResultant) { | ||
Zeile 317: | Zeile 402: | ||
arrowResultant = null; | arrowResultant = null; | ||
} else { | } else { | ||
- | arrowResultant = createArrow(v1.clone().add(v2), | + | arrowResultant = createArrow(v1.clone().add(v2), |
displayVectorComponents(v1.clone().add(v2), | displayVectorComponents(v1.clone().add(v2), | ||
renderer.render(scene, | renderer.render(scene, | ||
Zeile 323: | Zeile 408: | ||
} | } | ||
- | // Differenzvektor | ||
function toggleDifference() { | function toggleDifference() { | ||
if (arrowDifference) { | if (arrowDifference) { | ||
Zeile 329: | Zeile 413: | ||
arrowDifference = null; | arrowDifference = null; | ||
} else { | } else { | ||
- | arrowDifference = createArrow(v1.clone().sub(v2), | + | arrowDifference = createArrow(v1.clone().sub(v2), |
displayVectorComponents(v1.clone().sub(v2), | displayVectorComponents(v1.clone().sub(v2), | ||
renderer.render(scene, | renderer.render(scene, | ||
Zeile 335: | Zeile 419: | ||
} | } | ||
- | // Kreuzproduktvektor | ||
function toggleCrossProduct() { | function toggleCrossProduct() { | ||
if (arrowCrossProduct) { | if (arrowCrossProduct) { | ||
Zeile 341: | Zeile 424: | ||
arrowCrossProduct = null; | arrowCrossProduct = null; | ||
} else { | } else { | ||
- | arrowCrossProduct = createArrow(v1.clone().cross(v2), | + | arrowCrossProduct = createArrow(v1.clone().cross(v2), |
displayVectorComponents(v1.clone().cross(v2), | displayVectorComponents(v1.clone().cross(v2), | ||
renderer.render(scene, | renderer.render(scene, | ||
Zeile 347: | Zeile 430: | ||
} | } | ||
- | // Vektor-Komponenten im Output anzeigen | ||
function displayVectorComponents(vector, | function displayVectorComponents(vector, | ||
const output = document.getElementById(' | const output = document.getElementById(' | ||
Zeile 355: | Zeile 437: | ||
} | } | ||
- | | + | /* |
- | camera.position.z = 15; | + | camera.position.x = document.getElementById(" |
- | + | | |
- | // OrbitControls für interaktive Steuerung | + | camera.position.z |
- | | + | */ |
- | controls.enableDamping = true; // Sanfte Bewegung | + | |
- | | + | |
- | controls.screenSpacePanning = false; | + | |
- | + | ||
- | // Animationsschleife | + | |
function animate() { | function animate() { | ||
requestAnimationFrame(animate); | requestAnimationFrame(animate); | ||
- | // Update der Kontrolle | + | |
- | | + | scene.rotation.y = document.getElementById(' |
+ | | ||
renderer.render(scene, | renderer.render(scene, | ||
} | } | ||
- | // Initialisieren | + | |
- | | + | 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(); | animate(); | ||
+ | updateVectors(); | ||
+ | updateCamera(); | ||
+ | |||
+ | //for(var i = 0; i<5; i++) zoomOut(); | ||
</ | </ | ||
</ | </ |