diff --git a/20151112/Makefile b/20151112/Makefile index 30b65292f10f724409cdcd2b922b2f7a6a4a26a9..c677a4775af715603cbe6c5a381f762f57f8bc07 100644 --- a/20151112/Makefile +++ b/20151112/Makefile @@ -1,6 +1,6 @@ SOURCES = opengl-magic.c textured-spheres.c INCLUDES = opengl-magic.h textured-spheres.h -LIBS = -lGL -lGLU -lglut +LIBS = -lm -lGL -lGLU -lglut %: %.c $(SOURCES) $(INCLUDES) gcc -Wall $< $(SOURCES) $(LIBS) -o $@ diff --git a/20151112/Makefile-7 b/20151112/Makefile-7 new file mode 100644 index 0000000000000000000000000000000000000000..30b65292f10f724409cdcd2b922b2f7a6a4a26a9 --- /dev/null +++ b/20151112/Makefile-7 @@ -0,0 +1,6 @@ +SOURCES = opengl-magic.c textured-spheres.c +INCLUDES = opengl-magic.h textured-spheres.h +LIBS = -lGL -lGLU -lglut + +%: %.c $(SOURCES) $(INCLUDES) + gcc -Wall $< $(SOURCES) $(LIBS) -o $@ diff --git a/20151112/hanoi-0.c b/20151112/hanoi-0.c new file mode 100644 index 0000000000000000000000000000000000000000..c52342de1f4bc4ae77e4e2cdd71636087085417d --- /dev/null +++ b/20151112/hanoi-0.c @@ -0,0 +1,25 @@ +#include <stdio.h> + +#define DISKS 3 + +int n[3], tower[3][DISKS]; + +void display (void) +{ + for (int i = 0; i < 3; i++) + { + printf ("tower %d: ", i); + for (int j = 0; j < n[i]; j++) + printf ("%2d", tower[i][j]); + printf ("\n"); + } + printf ("\n"); +} + +int main (void) +{ + n[0] = 0; + n[1] = 0; + n[2] = 0; + display (); +} diff --git a/20151112/hanoi-1.c b/20151112/hanoi-1.c new file mode 100644 index 0000000000000000000000000000000000000000..cc37c97aae80a1b9b5a84d0920061e33b7112756 --- /dev/null +++ b/20151112/hanoi-1.c @@ -0,0 +1,27 @@ +#include <stdio.h> + +#define DISKS 3 + +int n[3], tower[3][DISKS]; + +void display (void) +{ + for (int i = 0; i < 3; i++) + { + printf ("tower %d: ", i); + for (int j = 0; j < n[i]; j++) + printf ("%2d", tower[i][j]); + printf ("\n"); + } + printf ("\n"); +} + +int main (void) +{ + n[0] = DISKS; + for (int i = 0; i < DISKS; i++) + tower[0][i] = DISKS - 1 - i; + n[1] = 0; + n[2] = 0; + display (); +} diff --git a/20151112/hanoi-2.c b/20151112/hanoi-2.c new file mode 100644 index 0000000000000000000000000000000000000000..16805bc3624a97c8c5880104842a37e74c1cccac --- /dev/null +++ b/20151112/hanoi-2.c @@ -0,0 +1,36 @@ +#include <stdio.h> + +#define DISKS 3 + +int n[3], tower[3][DISKS]; + +void display (void) +{ + for (int i = 0; i < 3; i++) + { + printf ("tower %d: ", i); + for (int j = 0; j < n[i]; j++) + printf ("%2d", tower[i][j]); + printf ("\n"); + } + printf ("\n"); +} + +void hanoi (int src, int dst, int tmp, int disks) +{ + tower[dst][n[dst]] = tower[src][n[src] - 1]; + n[src]--; + n[dst]++; + display (); +} + +int main (void) +{ + n[0] = DISKS; + for (int i = 0; i < DISKS; i++) + tower[0][i] = DISKS - 1 - i; + n[1] = 0; + n[2] = 0; + display (); + hanoi (0, 2, 1, 1); +} diff --git a/20151112/hanoi-3.c b/20151112/hanoi-3.c new file mode 100644 index 0000000000000000000000000000000000000000..2e30305452997aa930314d68c6b63eff22552829 --- /dev/null +++ b/20151112/hanoi-3.c @@ -0,0 +1,40 @@ +#include <stdio.h> + +#define DISKS 3 + +int n[3], tower[3][DISKS]; + +void display (void) +{ + for (int i = 0; i < 3; i++) + { + printf ("tower %d: ", i); + for (int j = 0; j < n[i]; j++) + printf ("%2d", tower[i][j]); + printf ("\n"); + } + printf ("\n"); +} + +void hanoi (int src, int dst, int tmp, int disks) +{ + if (disks > 1) + hanoi (src, tmp, dst, disks - 1); + tower[dst][n[dst]] = tower[src][n[src] - 1]; + n[src]--; + n[dst]++; + display (); + if (disks > 1) + hanoi (tmp, dst, src, disks - 1); +} + +int main (void) +{ + n[0] = DISKS; + for (int i = 0; i < DISKS; i++) + tower[0][i] = DISKS - 1 - i; + n[1] = 0; + n[2] = 0; + display (); + hanoi (0, 2, 1, DISKS); +} diff --git a/20151112/kleinesMinusO.PNG b/20151112/kleinesMinusO.PNG new file mode 100644 index 0000000000000000000000000000000000000000..75af3f8dc246f32c466967b21bd0d38e21739ac5 Binary files /dev/null and b/20151112/kleinesMinusO.PNG differ diff --git a/20151112/opengl-magic.c b/20151112/opengl-magic.c index bcb0b73c7b6070fce08b22866282aa782f59e1bf..f8a991088ee19b889b31fd501648df6ce492723a 100644 --- a/20151112/opengl-magic.c +++ b/20151112/opengl-magic.c @@ -6,7 +6,7 @@ void init_opengl (int *argcp, char **argv, char *window_name) { glutInit (argcp, argv); - glutInitDisplayMode (GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH); + glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize (1024, 768); glutCreateWindow (window_name); glMatrixMode (GL_PROJECTION); diff --git a/20151112/pendulum-1.c b/20151112/pendulum-1.c new file mode 100644 index 0000000000000000000000000000000000000000..336ebb933758b88b4a96849dbe7857a0f62b602b --- /dev/null +++ b/20151112/pendulum-1.c @@ -0,0 +1,46 @@ +#include <GL/gl.h> +#include <GL/glu.h> +#include <GL/freeglut.h> +#include <math.h> +#include "opengl-magic.h" + +#define phi0 1.0 /* geg. Anfangswert */ +#define omega0 0.0 /* geg. Anfangswert */ +#define dt 0.05 +#define g 9.81 +#define l 1.0 + +double t = 0.0; +double phi = phi0; +double omega = omega0; + +void draw (void) +{ + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + set_material_color (0.8, 0.8, 1.0); + glPushMatrix (); + glRotatef (90, 1.0, 0.0, 0.0); + glTranslatef (0.0, 0.0, -0.75); + glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0); + glTranslatef (0.0, 0.0, -1.0); + glutSolidCylinder (0.01, l, 13, 1); + glutSolidSphere (0.1, 31, 10); + glPopMatrix (); + glFlush (); +} + +void timer_handler (int value) +{ + t += dt; + glutPostRedisplay (); + glutTimerFunc (50, timer_handler, 0); +} + +int main (int argc, char **argv) +{ + init_opengl (&argc, argv, "Pendulum"); + glutDisplayFunc (draw); + glutTimerFunc (50, timer_handler, 0); + glutMainLoop (); + return 0; +} diff --git a/20151112/pendulum-2.c b/20151112/pendulum-2.c new file mode 100644 index 0000000000000000000000000000000000000000..b8a37273e7cc07381033519994261c9be3152840 --- /dev/null +++ b/20151112/pendulum-2.c @@ -0,0 +1,48 @@ +#include <GL/gl.h> +#include <GL/glu.h> +#include <GL/freeglut.h> +#include <math.h> +#include "opengl-magic.h" + +#define phi0 1.0 /* geg. Anfangswert */ +#define omega0 0.0 /* geg. Anfangswert */ +#define dt 0.05 +#define g 9.81 +#define l 1.0 + +double t = 0.0; +double phi = phi0; +double omega = omega0; + +void draw (void) +{ + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + set_material_color (0.8, 0.8, 1.0); + glPushMatrix (); + glRotatef (90, 1.0, 0.0, 0.0); + glTranslatef (0.0, 0.0, -0.75); + glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0); + glTranslatef (0.0, 0.0, -1.0); + glutSolidCylinder (0.01, l, 13, 1); + glutSolidSphere (0.1, 31, 10); + glPopMatrix (); + glFlush (); +} + +void timer_handler (int value) +{ + t += dt; + phi += dt * omega; + omega += dt * (-g / l) * sin (phi); + glutPostRedisplay (); + glutTimerFunc (50, timer_handler, 0); +} + +int main (int argc, char **argv) +{ + init_opengl (&argc, argv, "Pendulum"); + glutDisplayFunc (draw); + glutTimerFunc (50, timer_handler, 0); + glutMainLoop (); + return 0; +} diff --git a/20151112/pendulum-3.c b/20151112/pendulum-3.c new file mode 100644 index 0000000000000000000000000000000000000000..628a1fcd54166511bb6a31bcc67a68e36601aa42 --- /dev/null +++ b/20151112/pendulum-3.c @@ -0,0 +1,48 @@ +#include <GL/gl.h> +#include <GL/glu.h> +#include <GL/freeglut.h> +#include <math.h> +#include "opengl-magic.h" + +#define phi0 1.0 /* geg. Anfangswert */ +#define omega0 0.0 /* geg. Anfangswert */ +#define dt 0.05 +#define g 9.81 +#define l 1.0 + +double t = 0.0; +double phi = phi0; +double omega = omega0; + +void draw (void) +{ + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + set_material_color (1.0, 1.0, 0.8); + glPushMatrix (); + glRotatef (90, 1.0, 0.0, 0.0); + glTranslatef (0.0, 0.0, -0.75); + glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0); + glTranslatef (0.0, 0.0, -1.0); + glutSolidCylinder (0.01, l, 13, 1); + glutSolidSphere (0.1, 31, 10); + glPopMatrix (); + glFlush (); +} + +void timer_handler (int value) +{ + t += dt; + phi += dt * omega; + omega += dt * (-g / l) * phi; + glutPostRedisplay (); + glutTimerFunc (50, timer_handler, 0); +} + +int main (int argc, char **argv) +{ + init_opengl (&argc, argv, "Pendulum"); + glutDisplayFunc (draw); + glutTimerFunc (50, timer_handler, 0); + glutMainLoop (); + return 0; +} diff --git a/20151112/pendulum-4.c b/20151112/pendulum-4.c new file mode 100644 index 0000000000000000000000000000000000000000..6746242656713872e52666ae1d48f61c58fc4326 --- /dev/null +++ b/20151112/pendulum-4.c @@ -0,0 +1,68 @@ +#include <GL/gl.h> +#include <GL/glu.h> +#include <GL/freeglut.h> +#include <math.h> +#include "opengl-magic.h" + +#define phi0 0.5 /* geg. Anfangswert */ +#define omega0 0.0 /* geg. Anfangswert */ +#define dt 0.05 +#define g 9.81 +#define l 1.0 + +double t = 0.0; +double phi_with_sin = phi0; +double omega_with_sin= omega0; +double phi_without_sin = phi0; +double omega_without_sin= omega0; + +void draw_pendulum (double phi) +{ + glPushMatrix (); + glRotatef (90, 1.0, 0.0, 0.0); + glTranslatef (0.0, 0.0, -0.75); + glRotatef (180.0 + phi / M_PI * 180.0, 0.0, 1.0, 0.0); + glTranslatef (0.0, 0.0, -1.0); + glutSolidCylinder (0.01, 1.0, 13, 1); + glutSolidSphere (0.1, 31, 10); + glPopMatrix (); + glutSwapBuffers (); +} + +void draw (void) +{ + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + set_material_color (0.8, 0.8, 1.0); + draw_pendulum (phi_with_sin); + set_material_color (1.0, 0.8, 0.8); + draw_pendulum (phi_without_sin); + set_material_color (0.8, 1.0, 0.8); + double A = phi0; + double B = 0.5 * M_PI; /* 90° */ + double phi_analytic = A * sin (sqrt (g / l) * t + B); + draw_pendulum (phi_analytic); + glFlush (); +} + +void timer_handler (int value) +{ + t += dt; + phi_with_sin += dt * omega_with_sin; /* geg. Differentialgleichung */ + omega_with_sin += - dt * g / l * sin (phi_with_sin); /* geg. Differentialgleichung */ + /* _ohne_ Kleinwinkelnäherung */ + phi_without_sin += dt * omega_without_sin; /* geg. Differentialgleichung */ + omega_without_sin += - dt * g / l * phi_without_sin; /* geg. Differentialgleichung */ + /* _mit_ Kleinwinkelnäherung */ + glutPostRedisplay (); + glutTimerFunc (50, timer_handler, 0); +} + +int main (int argc, char **argv) +{ + init_opengl (&argc, argv, "Pendulum"); + glutDisplayFunc (draw); + glutTimerFunc (50, timer_handler, 0); + glutPostRedisplay (); + glutMainLoop (); + return 0; +} diff --git a/20151116/ainf-2015ws-p2.pdf b/20151116/ainf-2015ws-p2.pdf new file mode 100644 index 0000000000000000000000000000000000000000..6689e5f30ef809d63ce30ae97205a76152910a9d Binary files /dev/null and b/20151116/ainf-2015ws-p2.pdf differ diff --git a/20151116/ainf-2015ws-p2.tex b/20151116/ainf-2015ws-p2.tex new file mode 100644 index 0000000000000000000000000000000000000000..365cc981636a311d96fa7b5589c251d8da2dc1b6 --- /dev/null +++ b/20151116/ainf-2015ws-p2.tex @@ -0,0 +1,114 @@ +% ainf-2015ws-p2.pdf - Labor Notes on Fundamentals in Computer Architecture +% Copyright (C) 2014, 2015 Peter Gerwinski +% +% This document is free software: you can redistribute it and/or +% modify it either under the terms of the Creative Commons +% Attribution-ShareAlike 3.0 License, or under the terms of the +% GNU General Public License as published by the Free Software +% Foundation, either version 3 of the License, or (at your option) +% any later version. +% +% This document is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this document. If not, see <http://www.gnu.org/licenses/>. +% +% You should have received a copy of the Creative Commons +% Attribution-ShareAlike 3.0 Unported License along with this +% document. If not, see <http://creativecommons.org/licenses/>. + +\documentclass[a4paper]{article} + +\usepackage{pgscript} +\usepackage{multicol} +\usepackage{sfmath} + +\sloppy +\pagestyle{empty} +\newcommand{\sep}{~$\cdot$~} +\newcommand{\mylicense}{CC-by-sa (Version 3.0) oder GNU GPL (Version 3 oder höher)} + +\begin{document} + + \makebox(0,0)[tl]{\includegraphics[scale=0.57]{logo-hochschule-bochum-cvh-text.pdf}}\hfill + \makebox(0,0)[tr]{\includegraphics[scale=0.5]{logo-hochschule-bochum.pdf}} + \par\bigskip\bigskip + \begin{center} + \Large\textbf{Praktikumsversuch 2: Umlaufbahnen} + \par\medskip + \normalsize Angewandte Informatik\sep + Wintersemester 2015/16\sep + Prof.~Dr.~Peter Gerwinski + \end{center} + + Aufgabe: Schreiben Sie ein C-Programm, das die Umlaufbahn eines Satelliten + im Gravitationsfeld eines Zentralgestirns simuliert und in 3d-Grafik darstellt. + + \begin{multicols}{2} + + \begin{itemize} + \item + Ein Körper im Gravitationsfeld eines Zentralgestirns + erfährt eine Kraft in Richtung auf dessen Zentrum + mit dem Betrag: + \begin{equation} + F = \frac{m\cdot M\cdot G}{r^2} + \end{equation} + Hierbei ist $m$ die Masse des Satelliten, + $M$ die des Zentralgestirns, + $r$ der Abstand des Satelliten vom Zentrum und + $G$ eine Konstante (Gravitationskonstante). + \item + Die Gravitationskraft beschleunigt den Satelliten gemäß: + \begin{equation} + \vec{F} = m\cdot \vec{a} + \end{equation} + \item + Mit geeignetem Anfangsort und geeigneter Anfangsgeschwindigkeit + beschreibt der Satellit eine elliptische Umlaufbahn um das Zentralgestirn. + \item + Hinweis 1: Es genügt, das System in der $(x,y)$-\break Ebene zu betrachten + und die $z$-Koordinate konstant auf $0$ zu setzen. + \item + Für die Simulation betrachten wir das System in kurzen Zeitintervallen $dt$ + und berechnen die Änderungen des Ortes $\vec{r} = (x,y)$ + und der Geschwindigkeit $\vec{v} = (v_x,v_y)$ des Satelliten + mit Hilfe des expliziten Eulerschen Polygonzugverfahrens. + \item + Hinweis 2: Für die Zerlegung der Kraft $\vec{F}\/$ + in $x$- und $y$-Komponenten benötigen Sie nur die Grundrechenarten + und insbesondere \emph{keine\/} trigonometrischen Funktionen. + \end{itemize} + + \bigskip + + \qquad\qquad\emph{Viel Erfolg!} + + \vfill\strut + + \end{multicols} + + \vfill + + \begingroup + + \small + + \setlength{\leftskip}{3cm} + + Stand: 15.\ November 2015 + +% Soweit nicht anders angegeben:\\ + Copyright \copyright\ 2014, 2015\quad Peter Gerwinski\\ + Lizenz: \mylicense + + Sie können diese Praktikumsunterlagen + einschließlich Quelltext und sonstiger Lehrmaterialien + unter \url{https://gitlab.cvh-server.de/pgerwinski/ainf.git} herunterladen. + + \endgroup + +\end{document} diff --git a/20151116/logo-hochschule-bochum-cvh-text.pdf b/20151116/logo-hochschule-bochum-cvh-text.pdf new file mode 120000 index 0000000000000000000000000000000000000000..a05946126bc0ce6a2818740da2893f59eb0c659c --- /dev/null +++ b/20151116/logo-hochschule-bochum-cvh-text.pdf @@ -0,0 +1 @@ +../common/logo-hochschule-bochum-cvh-text.pdf \ No newline at end of file diff --git a/20151116/logo-hochschule-bochum.pdf b/20151116/logo-hochschule-bochum.pdf new file mode 120000 index 0000000000000000000000000000000000000000..b6b9491e370e499c9276918182cdb82cb311bcd1 --- /dev/null +++ b/20151116/logo-hochschule-bochum.pdf @@ -0,0 +1 @@ +../common/logo-hochschule-bochum.pdf \ No newline at end of file diff --git a/20151116/pgscript.sty b/20151116/pgscript.sty new file mode 120000 index 0000000000000000000000000000000000000000..95c888478c99ea7fda0fd11ccf669ae91be7178b --- /dev/null +++ b/20151116/pgscript.sty @@ -0,0 +1 @@ +../common/pgscript.sty \ No newline at end of file diff --git a/common/pgscript.sty b/common/pgscript.sty index 1de1a990ad440123dad1e25a0fdc421932587687..6d637289def3ba40bc0b5bf20e9f8f2d955301d8 100644 --- a/common/pgscript.sty +++ b/common/pgscript.sty @@ -31,8 +31,10 @@ \renewcommand*\familydefault{\sfdefault} \usepackage{graphicx} \usepackage{pstricks} +\usepackage{ifluatex} % Repair kerning: Automatically insert "\kern{-0.15em}" between "//" % (in URLs). +\ifluatex \directlua{ local glyph = node.id ("glyph") local function my_kerning (head) @@ -55,6 +57,7 @@ end luatexbase.add_to_callback ("kerning", my_kerning, "URL kerning") } +\fi \definecolor{blendedblue}{rgb}{0.2,0.2,0.7} \definecolor{darkgreen}{rgb}{0.0,0.3,0.0} diff --git a/script/ainf-2015ws.pdf b/script/ainf-2015ws.pdf index b7e19e27413582fe24027d48646449fa044eb75c..5ae01a914bb45e9528f7180ce453c74322a6f534 100644 Binary files a/script/ainf-2015ws.pdf and b/script/ainf-2015ws.pdf differ