kurse:efcomputergrafik:teil2:brainstorm

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
kurse:efcomputergrafik:teil2:brainstorm [2019/09/06 10:04]
Ivo Blöchliger [Brainstorm]
kurse:efcomputergrafik:teil2:brainstorm [2019/11/19 09:52]
Ivo Blöchliger
Line 1: Line 1:
 +====== Intro ======
 +  * meine Wenigkeit
 +  * Warum Bezier-Kurven?
 +
 +====== Ziele ======
 +  * Physikalisch halbwegs realistische Achterbahn mit Blender
 +  * Ansteuerung des Whiteboard-Plotters vom Tech-Lab. Siehe https://fginfo.ksbg.ch/~ivo/videos/tech-lab-whiteboard-plotter.mp4. Input: SVG-Datei aus Inkscape, Output: Folge von $(r_1,r_2)$-Koordinaten, die linear abgefahren werden, plus Kommandos zum Heben/Senken des Stifts. Einheit: mm.
 +
 +====== Programm ======
 +  * Software auf Schulcomputern: https://fginfo.ksbg.ch/dokuwiki/doku.php?id=lehrkraefte:blc:informatik:glf19:glf19#make_the_computer_zimmer_great_again
 +  * Demo mit Inkscape (https://inkscape.org/release/0.92.4/windows/64-bit/)
 +  * Geometrische Definition
 +    * Gerade, 3 Punkte, 4 Punkte
 +    * Programmierung, Animation
 +
 +
 ====== Brainstorm ====== ====== Brainstorm ======
   * Linearkombinationen, Konvexe Kombinationen, 2 Punkte, 3 Punkte, $n$ Punkte   * Linearkombinationen, Konvexe Kombinationen, 2 Punkte, 3 Punkte, $n$ Punkte
Line 19: Line 35:
   * https://blender.stackexchange.com/questions/6750/poly-bezier-curve-from-a-list-of-coordinates   * https://blender.stackexchange.com/questions/6750/poly-bezier-curve-from-a-list-of-coordinates
  
 +
 +===== Bezier Kurven =====
 +  * https://fginfo.ksbg.ch/~ivo/videos/blender2.8-Bezier-Kurven.mkv
 +**Zusammenfassung**: Add -> Curve -> Bezier
 +  * 'e' -> Extrude um neuen Punkt anzufügen.
 +  * 'gz' -> In z-Richtung verschieben.
 +  * Auf Koordinatenachsen klicken, für orthonormale Projektion
 +  * Rechtsklick 'Toggle Cyclic'
 +  * 
 +===== Manipulation in Python =====
 +
 +
 +==== Auslesen der Daten ====
 +<code python>
 +import bpy
 +
 +obj = bpy.data.objects['BezierCurve']
 +
 +if obj.type == 'CURVE':
 +    for subcurve in obj.data.splines:
 +        curvetype = subcurve.type
 +        if curvetype == 'BEZIER':
 +            print("curve is closed:", subcurve.use_cyclic_u)
 +            for bezpoint in subcurve.bezier_points:
 +                print('knot', bezpoint.co)
 +                print('handle_left', bezpoint.handle_left)
 +                print('handle_right', bezpoint.handle_right)
 +
 +</code>
 +
 +==== Generieren der Daten ====
 +  * https://blender.stackexchange.com/questions/6750/poly-bezier-curve-from-a-list-of-coordinates
 +  * https://docs.blender.org/api/current/bpy.ops.curve.html
 +
 +Working example, adapted to blender 2.8 from https://github.com/zeffii/BlenderPythonRecipes/wiki/Curves
 +<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, curvename, cList, origin=(0,0,0)):    
 +    curvedata = bpy.data.curves.new(name=curvename, type='CURVE'   
 +    curvedata.dimensions = '2D'    
 +    
 +    objectdata = bpy.data.objects.new(objname, curvedata)    
 +    objectdata.location = origin
 +
 +    bpy.context.scene.collection.children[0].objects.link(objectdata)
 +    
 +    polyline = curvedata.splines.new('BEZIER'   
 +    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 = 'FREE'
 +        point.handle_right_type = 'FREE'
 +
 +    polyline.use_cyclic_u = True    
 +    
 +MakeCurveQuarter("NameOfMyCurveObject", "NameOfMyCurve", coordinates)  
 +</code>
 +
 +==== Einbinden von eigenen Modulen ====
 +<code python>
 +# Eigene, selbstgeschriebene Bezier-Klasse
 +Bezier = bpy.data.texts["bezier.py"].as_module().Bezier
 +</code>
 +
 +==== Kamera animieren ====
 +<code python>
 +e = bpy.data.objects['Camera']
 +e.animation_data_clear()
 +
 +# Loop über die frames
 +    # Orthonormales system (y,-an,-vv) und Ursprung pp 
 +    # wobei -vv die Blickrichtung, -an nach unten zeigt und y nach rechts zeigt.
 +    # matrix_world = (rechts, unten, hinten)
 +    e.matrix_world = ( (y.x,y.y,y.z,1), (-an.x, -an.y, -an.z, 1),  (-vv.x,-vv.y,-vv.z,1),  (pp.x, pp.y, pp.z, 0))
 +    # Rotation und Translation "keyframen"
 +    e.keyframe_insert(data_path="rotation_euler", frame=frame)
 +    e.keyframe_insert(data_path="location", frame=frame)
 +    frame+=1
 +</code>
 +==== numpy ====
 +<code python>
 +import numpy as np
 +
 +a = np.array([[3,1], [1,2]])
 +b = np.array([9,8])
 +x = np.linalg.solve(a, b)
 +print(x)  # Das geht unter Linux ins Terminal, wo Blender gestartet wurde. Keine Ahnung wohin das sonst geht...
 +</code>
 +
 +===== Video kodieren =====
 +<code bash>
 +ffmpeg -r 30 -i %04d.png test.mkv
 +</code>
 +Z.B. https://fginfo.ksbg.ch/~ivo/videos/achterbahn-take1.mkv
  • kurse/efcomputergrafik/teil2/brainstorm.txt
  • Last modified: 2019/11/19 13:50
  • by Ivo Blöchliger