Welcome to the github repository of the course Géométrie numérique 2017.
See course website for more details.
cd your/working/dir/
git clone https://github.com/GeoNumTP/GeoNum2017.git
cd GeoNum2017
python TP1/tp1.py
- Bézier curves | theory | code
- Bézier splines | theory | code
- B-splines | theory | code
- Subdivision curves | theory | code
- Lane-Riesenfeld | theory | code
- Bézier surfaces | theory | code
- B-spline surfaces | theory | code
- Subdivision B-surfaces | theory | code
- Triangle mesh subdivision | theory | code
- Learn Python in 10 minutes
- Python 2.7 tutorial
- Python at OverAPI
- NumPy quickstart tutorial
- NumPy cheatsheet
- Matplotlib.pyplot
If you have no prior experience with Python whatsoever, I suggest the tutorial Learn Python in 10 minutes by Stavros Korokithakis. For longer and more complete references, see the Fast Lane to Python by Norm Matloff and, of course, the official Python 2.7 tutorial.
NumPy is a Python package supporting N-dimensional arrays and linear algebra operations. We'll mostly use it to manipulate datapoints stored in matrices (two-dimensional arrays). If you're not familiar with numpy, have a look at this cheatsheet.
Here are some useful numpy commands; you can test them in the python
console.
>>> import numpy as np
# define a 50x3 matrix of zeros
>>> Z = np.zeros([50,3])
# define a 2x3 matrix
>>> A = np.array([[1,2,3],[4,5,6]])
>>> print A
[[1 2 3]
[4 5 6]]
# define a vector with 10 evenly-spaced values between 0 and 1
>>> t = np.linspace(0,1,10)
>>> print t
[ 0. 0.11111111 0.22222222 0.33333333 0.44444444 0.55555556
0.66666667 0.77777778 0.88888889 1. ]
# define a range
>>> i = np.arange(10) # same as np.arange(0,10)
>>> print i
[0 1 2 3 4 5 6 7 8 9]
>>> j = np.arange(5,45,10)
>>> print j
[ 5 15 25 35]
# get dimensions of a matrix
>>> S = A.shape
>>> print S[0] # number of rows in A
2
>>> print S[1] # number of cols in A
3
# access a specific row
>>> print A[0,:]
[1 2 3]
# access a specific col
>>> print A[:,1]
[2 5]
# slicing: access cols 0 to 1
>>> print A[:,0:2]
[[1 2]
[4 5]]
# slicing: access cols 1 to end
>>> print A[:,1:]
[[2 3]
[5 6]]
# reshape A to have 3 rows and 2 cols
>>> B = A.reshape(3,2)
>>> print B
[[1, 2],
[3, 4],
[5, 6]]
# reshape A to have 2 cols
# number of rows is determined automatically
>>> C = B.reshape(-1,3)
>>> print C
[[1 2 3]
[4 5 6]]
Matplotlib is a Python 2D plotting library - we'll use it to visualise 2D curves
via pyplot.
Example:
>>> import numpy as np
>>> import matplotlib.pyplot as plt
# generate random data
>>> A = np.random.rand(1000,2)
>>> x = A[:,0]
>>> y = A[:,1]
# plot blue circles
>>> plt.plot( x, y, 'bo')
# plot solid red lines
>>> plt.plot( x, y, 'r-')
# render and show the plot
>>> plt.show()
# plot dashed green lines and blue circles
>>> plt.plot(x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12)