Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
vektor [2024/12/07 17:06] jango [Vektor Visualisierung] |
vektor [2024/12/07 17:32] (aktuell) jango [Vektor Visualisierung] |
||
---|---|---|---|
Zeile 178: | Zeile 178: | ||
body { margin: 0; font-family: | body { margin: 0; font-family: | ||
canvas { display: block; } | canvas { display: block; } | ||
- | .controls { position: absolute; top: 10px; left: 10px; z-index: 1; background: rgba(255, 255, 255, 0.7); padding: | + | .controls { |
- | .controls input { margin-bottom: | + | |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | width: 240px; | ||
+ | height: 90%; | ||
+ | overflow-y: auto; | ||
+ | | ||
+ | .section | ||
+ | | ||
+ | } | ||
+ | .section h3 { | ||
+ | margin-top: 0; | ||
+ | } | ||
+ | .section input, .section button { | ||
+ | | ||
+ | margin-bottom: | ||
+ | | ||
</ | </ | ||
</ | </ | ||
< | < | ||
<div class=" | <div class=" | ||
- | < | + | <!-- Vektor Eingabe --> |
- | <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="v2x"> | + | |
- | <input type="number" | + | <div class="section"> |
- | <label for="v2y">Vektor 2 (y): </label> | + | <h3> |
- | <input type=" | + | <button onclick="toggleResultant()">Zeige Resultierende</ |
- | <label for="v2z">Vektor 2 (z): </label> | + | <button onclick="toggleDifference()">Zeige Differenz</button>< |
- | <input type=" | + | <button onclick="toggleCrossProduct()">Zeige Kreuzprodukt</button><br> |
+ | | ||
- | <button onclick="updateVectors()">Vektoren aktualisieren</button><br> | + | |
- | <button onclick="toggleResultant()">Zeige Resultierende</button>< | + | <div class="section"> |
- | <button onclick="toggleDifference()">Zeige Differenz</ | + | |
- | <button onclick="toggleCrossProduct()">Zeige Kreuzprodukt</ | + | <label for="rotateX">Rotation X (rot):</label> |
+ | <input type="range" id=" | ||
+ | <input type="number" | ||
- | < | + | |
- | <label for="rotateX"> | + | <input type=" |
- | <input type=" | + | <input type=" |
- | <input type=" | + | |
- | <label for=" | + | |
- | <input type=" | + | <input type=" |
- | <input type=" | + | <input type=" |
- | + | </div> | |
- | <label for=" | + | |
- | <input type=" | + | |
- | <input type=" | + | |
- | + | ||
- | < | + | |
- | <label for=" | + | |
- | <input type=" | + | |
- | <label for="cameraY"> | + | <!-- Kamera Position und Rotation --> |
- | <input type=" | + | <div class=" |
+ | < | ||
+ | | ||
+ | <input type=" | ||
- | <label for="cameraZ"> | + | |
- | <input type=" | + | <input type=" |
- | <label for="cameraRotateX"> | + | |
- | <input type=" | + | <input type=" |
- | <label for="cameraRotateY"> | + | |
- | <input type=" | + | <input type=" |
- | <label for="cameraRotateZ"> | + | |
- | <input type=" | + | <input type=" |
- | <button onclick="zoomIn()">Zoom In</button>< | + | |
- | <button onclick="zoomOut()">Zoom Out</ | + | <input type="number" |
- | <span id="output"></ | + | |
- | </ | + | <button onclick=" |
+ | </ | ||
+ | <!-- Ausgabe --> | ||
+ | <div class=" | ||
+ | <span id=" | ||
+ | </ | ||
+ | </ | ||
<script src=" | <script src=" | ||
- | <script src=" | + | |
< | < | ||
Zeile 259: | Zeile 292: | ||
directionalLight.position.set(5, | directionalLight.position.set(5, | ||
scene.add(directionalLight); | scene.add(directionalLight); | ||
- | |||
- | // Funktion zum Vergrößern der Szene (Zoom In) | ||
- | function zoomIn() { | ||
- | if (camera.position.z > 1) { | ||
- | camera.position.z -= 1; // Kamera näher an die Szene heranholen | ||
- | renderer.render(scene, | ||
- | } | ||
- | } | ||
- | // Funktion zum Verkleinern der Szene (Zoom Out) | + | function zoomIn() { |
- | function zoomOut() { | + | if (camera.position.z > 1) { |
- | camera.position.z += 1; // Kamera weiter von der Szene entfernen | + | camera.position.z -= 1; |
- | renderer.render(scene, | + | renderer.render(scene, |
- | } | + | } |
+ | } | ||
+ | |||
+ | function zoomOut() { | ||
+ | camera.position.z += 1; | ||
+ | renderer.render(scene, | ||
+ | } | ||
- | // Vektoren | ||
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 280: | Zeile 310: | ||
let arrowV1, arrowV2, arrowResultant, | let arrowV1, arrowV2, arrowResultant, | ||
- | // Erstelle Vektorpfeile | ||
function createArrow(vector, | function createArrow(vector, | ||
const arrowHelper = new THREE.ArrowHelper(vector.clone().normalize(), | const arrowHelper = new THREE.ArrowHelper(vector.clone().normalize(), | ||
Zeile 287: | Zeile 316: | ||
} | } | ||
- | // Funktion zum Erstellen von Achsen und Skalenmarkierungen | ||
function createAxisAndScale() { | function createAxisAndScale() { | ||
- | | + | var maxNum = 9999; |
- | var maxNum = 9999; | + | |
- | + | ||
- | // X-Achse | + | |
const xAxisGeometry = new THREE.BufferGeometry().setFromPoints([ | const xAxisGeometry = new THREE.BufferGeometry().setFromPoints([ | ||
new THREE.Vector3(0, | new THREE.Vector3(0, | ||
Zeile 301: | Zeile 327: | ||
scene.add(xAxis); | scene.add(xAxis); | ||
- | // Y-Achse | ||
const yAxisGeometry = new THREE.BufferGeometry().setFromPoints([ | const yAxisGeometry = new THREE.BufferGeometry().setFromPoints([ | ||
new THREE.Vector3(0, | new THREE.Vector3(0, | ||
Zeile 310: | Zeile 335: | ||
scene.add(yAxis); | scene.add(yAxis); | ||
- | // Z-Achse | ||
const zAxisGeometry = new THREE.BufferGeometry().setFromPoints([ | const zAxisGeometry = new THREE.BufferGeometry().setFromPoints([ | ||
new THREE.Vector3(0, | new THREE.Vector3(0, | ||
Zeile 319: | Zeile 343: | ||
scene.add(zAxis); | scene.add(zAxis); | ||
- | // Skalenmarkierungen entlang der Achsen | ||
for (let i = 1; i <= maxNum; i++) { | for (let i = 1; i <= maxNum; i++) { | ||
- | // X-Markierungen | ||
const xMarker = new THREE.Mesh( | const xMarker = new THREE.Mesh( | ||
new THREE.SphereGeometry(0.1), | new THREE.SphereGeometry(0.1), | ||
Zeile 329: | Zeile 351: | ||
scene.add(xMarker); | scene.add(xMarker); | ||
- | // Y-Markierungen | ||
const yMarker = new THREE.Mesh( | const yMarker = new THREE.Mesh( | ||
new THREE.SphereGeometry(0.1), | new THREE.SphereGeometry(0.1), | ||
Zeile 337: | Zeile 358: | ||
scene.add(yMarker); | scene.add(yMarker); | ||
- | // Z-Markierungen | ||
const zMarker = new THREE.Mesh( | const zMarker = new THREE.Mesh( | ||
new THREE.SphereGeometry(0.1), | new THREE.SphereGeometry(0.1), | ||
Zeile 347: | Zeile 367: | ||
} | } | ||
- | // Update Vektoren und Pfeile | ||
function updateVectors() { | function updateVectors() { | ||
- | // Neue Werte aus den Eingabefeldern holen | ||
v1.set( | v1.set( | ||
parseFloat(document.getElementById(' | parseFloat(document.getElementById(' | ||
Zeile 362: | Zeile 380: | ||
); | ); | ||
- | // Szene leeren | ||
scene.clear(); | scene.clear(); | ||
- | // Achsen und Skalenmarkierungen erstellen | ||
createAxisAndScale(); | createAxisAndScale(); | ||
- | | + | 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 und Konsole | ||
displayVectorComponents(v1, | displayVectorComponents(v1, | ||
displayVectorComponents(v2, | displayVectorComponents(v2, | ||
Zeile 384: | Zeile 397: | ||
} | } | ||
- | // Ergebnisvektor (Resultant) | ||
function toggleResultant() { | function toggleResultant() { | ||
if (arrowResultant) { | if (arrowResultant) { | ||
Zeile 390: | Zeile 402: | ||
arrowResultant = null; | arrowResultant = null; | ||
} else { | } else { | ||
- | arrowResultant = createArrow(v1.clone().add(v2), | + | arrowResultant = createArrow(v1.clone().add(v2), |
- | // Zeige Resultierenden Vektor | + | |
displayVectorComponents(v1.clone().add(v2), | displayVectorComponents(v1.clone().add(v2), | ||
renderer.render(scene, | renderer.render(scene, | ||
Zeile 397: | Zeile 408: | ||
} | } | ||
- | // Differenzvektor | ||
function toggleDifference() { | function toggleDifference() { | ||
if (arrowDifference) { | if (arrowDifference) { | ||
Zeile 403: | Zeile 413: | ||
arrowDifference = null; | arrowDifference = null; | ||
} else { | } else { | ||
- | arrowDifference = createArrow(v1.clone().sub(v2), | + | arrowDifference = createArrow(v1.clone().sub(v2), |
- | // Zeige Differenz Vektor | + | |
displayVectorComponents(v1.clone().sub(v2), | displayVectorComponents(v1.clone().sub(v2), | ||
renderer.render(scene, | renderer.render(scene, | ||
Zeile 410: | Zeile 419: | ||
} | } | ||
- | // Kreuzproduktvektor | ||
function toggleCrossProduct() { | function toggleCrossProduct() { | ||
if (arrowCrossProduct) { | if (arrowCrossProduct) { | ||
Zeile 416: | Zeile 424: | ||
arrowCrossProduct = null; | arrowCrossProduct = null; | ||
} else { | } else { | ||
- | arrowCrossProduct = createArrow(v1.clone().cross(v2), | + | arrowCrossProduct = createArrow(v1.clone().cross(v2), |
- | // Zeige Kreuzprodukt Vektor | + | |
displayVectorComponents(v1.clone().cross(v2), | displayVectorComponents(v1.clone().cross(v2), | ||
renderer.render(scene, | renderer.render(scene, | ||
Zeile 423: | Zeile 430: | ||
} | } | ||
- | // Zeige Vektor-Komponenten im Output und Konsole | ||
function displayVectorComponents(vector, | function displayVectorComponents(vector, | ||
const output = document.getElementById(' | const output = document.getElementById(' | ||
- | const outputText = label + " - x:" + vector.x.toFixed(2) + ", y:" + vector.y.toFixed(2) + ", z:" + vector.x.toFixed(2); | + | const outputText = `${label} - x: ${vector.x.toFixed(2)}, |
output.textContent = outputText; | output.textContent = outputText; | ||
console.log(outputText); | console.log(outputText); | ||
} | } | ||
- | | + | /* |
- | camera.position.z = 15; | + | camera.position.x = document.getElementById(" |
- | + | | |
- | // Animationsschleife | + | camera.position.z = document.getElementById(" |
+ | */ | ||
+ | |||
function animate() { | function animate() { | ||
requestAnimationFrame(animate); | requestAnimationFrame(animate); | ||
- | // Rotation der Szene basierend auf den Slider-Werten | ||
scene.rotation.x = document.getElementById(' | scene.rotation.x = document.getElementById(' | ||
scene.rotation.y = document.getElementById(' | scene.rotation.y = document.getElementById(' | ||
Zeile 445: | Zeile 452: | ||
renderer.render(scene, | renderer.render(scene, | ||
} | } | ||
- | + | ||
- | // Kamera-Position und -Rotation aktualisieren | + | |
function updateCamera() { | function updateCamera() { | ||
- | // Position der Kamera aktualisieren | ||
camera.position.set( | camera.position.set( | ||
parseFloat(document.getElementById(' | parseFloat(document.getElementById(' | ||
Zeile 455: | Zeile 460: | ||
); | ); | ||
- | // Rotation der Kamera aktualisieren | ||
camera.rotation.set( | camera.rotation.set( | ||
parseFloat(document.getElementById(' | parseFloat(document.getElementById(' | ||
Zeile 465: | Zeile 469: | ||
} | } | ||
- | // Anpassung bei Fenstergrößenänderung | ||
window.addEventListener(' | window.addEventListener(' | ||
renderer.setSize(window.innerWidth, | renderer.setSize(window.innerWidth, | ||
Zeile 471: | Zeile 474: | ||
camera.updateProjectionMatrix(); | camera.updateProjectionMatrix(); | ||
}); | }); | ||
- | + | ||
- | // Update der Rotation basierend auf den Slider-Werten | + | |
document.getElementById(' | document.getElementById(' | ||
scene.rotation.x = this.value * Math.PI / 180; | scene.rotation.x = this.value * Math.PI / 180; | ||
Zeile 488: | Zeile 490: | ||
}); | }); | ||
- | // Update der Rotation basierend auf den Eingabefeldern | ||
document.getElementById(' | document.getElementById(' | ||
const value = parseFloat(this.value); | const value = parseFloat(this.value); | ||
Zeile 507: | Zeile 508: | ||
}); | }); | ||
- | |||
- | // Event-Listener für Kamera-Position | ||
document.getElementById(' | document.getElementById(' | ||
document.getElementById(' | document.getElementById(' | ||
document.getElementById(' | document.getElementById(' | ||
- | |||
- | // Event-Listener für Kamera-Rotation | ||
document.getElementById(' | document.getElementById(' | ||
document.getElementById(' | document.getElementById(' | ||
document.getElementById(' | document.getElementById(' | ||
- | | + | |
updateVectors(); | updateVectors(); | ||
- | animate(); | + | updateCamera(); |
+ | |||
+ | //for(var i = 0; i<5; i++) zoomOut(); | ||
</ | </ | ||
</ | </ |