Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| kurse:efcomputergrafik:teil2:brainstorm [2019/11/17 13:41] – [numpy] Ivo Blöchliger | kurse:efcomputergrafik:teil2:brainstorm [2019/11/19 12:50] (current) – [Intro] Ivo Blöchliger | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Intro ====== | ||
| + | * meine Wenigkeit | ||
| + | * mein mickgriges Namensgedächtnis | ||
| + | * Warum Bezier-Kurven? | ||
| + | ====== Ziele ====== | ||
| + | * Physikalisch halbwegs realistische Achterbahn mit Blender | ||
| + | * Ansteuerung des Whiteboard-Plotters vom Tech-Lab. Siehe https:// | ||
| + | |||
| + | ====== Programm ====== | ||
| + | * Software auf Schulcomputern: | ||
| + | * Demo mit Inkscape (https:// | ||
| + | * Geometrische Definition | ||
| + | * Gerade, 3 Punkte, 4 Punkte | ||
| + | * Programmierung, | ||
| + | |||
| + | |||
| + | ====== Brainstorm ====== | ||
| + | * Linearkombinationen, | ||
| + | * Kubische Interpolation: | ||
| + | * Kubische Bezier-Kurven | ||
| + | * Darstellung in SVG-Dateien | ||
| + | * Casteljau' | ||
| + | * Länge einer Bezierkurve, | ||
| + | * ? | ||
| + | * ?Rationale Bezierkurven? | ||
| + | * ?Kubische Splines? https:// | ||
| + | * https:// | ||
| + | * ? | ||
| + | * Ableitungen von Kurven, Geschwindigkeit, | ||
| + | * ? | ||
| + | * ?Der ideale Looping? | ||
| + | |||
| + | ====== Blender stuff ====== | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | ===== Bezier Kurven ===== | ||
| + | * https:// | ||
| + | **Zusammenfassung**: | ||
| + | * ' | ||
| + | * ' | ||
| + | * Auf Koordinatenachsen klicken, für orthonormale Projektion | ||
| + | * Rechtsklick ' | ||
| + | * | ||
| + | ===== Manipulation in Python ===== | ||
| + | |||
| + | |||
| + | ==== Auslesen der Daten ==== | ||
| + | <code python> | ||
| + | import bpy | ||
| + | |||
| + | obj = bpy.data.objects[' | ||
| + | |||
| + | if obj.type == ' | ||
| + | for subcurve in obj.data.splines: | ||
| + | curvetype = subcurve.type | ||
| + | if curvetype == ' | ||
| + | print(" | ||
| + | for bezpoint in subcurve.bezier_points: | ||
| + | print(' | ||
| + | print(' | ||
| + | print(' | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Generieren der Daten ==== | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | Working example, adapted to blender 2.8 from https:// | ||
| + | <code python> | ||
| + | import bpy | ||
| + | from mathutils import Vector | ||
| + | |||
| + | |||
| + | coordinates = [ | ||
| + | ((-1, 0, 0), (-0.7, 0, 0), (-1, 0.5521, 0)), | ||
| + | ((0, 1, 0), (-0.5521, 1, 0), (0, 0.7, 0)), | ||
| + | ((0, 0, 0), (0, 0.3, 0), (-0.3, 0, 0)) | ||
| + | ] | ||
| + | |||
| + | | ||
| + | def MakeCurveQuarter(objname, | ||
| + | curvedata = bpy.data.curves.new(name=curvename, | ||
| + | curvedata.dimensions = ' | ||
| + | | ||
| + | objectdata = bpy.data.objects.new(objname, | ||
| + | objectdata.location = origin | ||
| + | |||
| + | bpy.context.scene.collection.children[0].objects.link(objectdata) | ||
| + | | ||
| + | polyline = curvedata.splines.new(' | ||
| + | polyline.bezier_points.add(len(cList)-1) | ||
| + | |||
| + | for idx, (knot, h1, h2) in enumerate(cList): | ||
| + | point = polyline.bezier_points[idx] | ||
| + | point.co = knot | ||
| + | point.handle_left = h1 | ||
| + | point.handle_right = h2 | ||
| + | point.handle_left_type = ' | ||
| + | point.handle_right_type = ' | ||
| + | |||
| + | polyline.use_cyclic_u = True | ||
| + | | ||
| + | MakeCurveQuarter(" | ||
| + | </ | ||
| + | |||
| + | ==== Einbinden von eigenen Modulen ==== | ||
| + | <code python> | ||
| + | # Eigene, selbstgeschriebene Bezier-Klasse | ||
| + | Bezier = bpy.data.texts[" | ||
| + | </ | ||
| + | |||
| + | ==== Kamera animieren ==== | ||
| + | <code python> | ||
| + | e = bpy.data.objects[' | ||
| + | e.animation_data_clear() | ||
| + | |||
| + | # Loop über die frames | ||
| + | # Orthonormales system (y,-an,-vv) und Ursprung pp | ||
| + | # wobei -vv die Blickrichtung, | ||
| + | # matrix_world = (rechts, unten, hinten) | ||
| + | e.matrix_world = ( (y.x, | ||
| + | # Rotation und Translation " | ||
| + | e.keyframe_insert(data_path=" | ||
| + | e.keyframe_insert(data_path=" | ||
| + | frame+=1 | ||
| + | </ | ||
| + | ==== numpy ==== | ||
| + | <code python> | ||
| + | import numpy as np | ||
| + | |||
| + | a = np.array([[3, | ||
| + | b = np.array([9, | ||
| + | x = np.linalg.solve(a, | ||
| + | print(x) | ||
| + | </ | ||
| + | |||
| + | ===== Video kodieren ===== | ||
| + | <code bash> | ||
| + | ffmpeg -r 30 -i %04d.png test.mkv | ||
| + | </ | ||
| + | Z.B. https:// | ||