"#dimension of our problem (here 3 as our curve is 3D)\n",
"dim = 3\n",
...
...
@@ -155,7 +155,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 36,
"metadata": {},
"outputs": [
{
...
...
@@ -191,7 +191,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 37,
"metadata": {},
"outputs": [
{
...
...
@@ -219,7 +219,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -247,7 +247,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -295,7 +295,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 40,
"metadata": {},
"outputs": [
{
...
...
@@ -335,7 +335,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 41,
"metadata": {},
"outputs": [
{
...
...
@@ -376,7 +376,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -400,7 +400,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 43,
"metadata": {},
"outputs": [
{
...
...
@@ -424,7 +424,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 44,
"metadata": {},
"outputs": [
{
...
...
@@ -461,7 +461,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
...
...
@@ -482,7 +482,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 46,
"metadata": {},
"outputs": [
{
...
...
@@ -509,7 +509,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 47,
"metadata": {},
"outputs": [
{
...
...
@@ -543,7 +543,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 48,
"metadata": {},
"outputs": [
{
...
...
@@ -575,7 +575,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 49,
"metadata": {},
"outputs": [
{
...
...
@@ -614,7 +614,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 50,
"metadata": {},
"outputs": [
{
...
...
@@ -669,7 +669,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 51,
"metadata": {},
"outputs": [
{
...
...
@@ -714,7 +714,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 52,
"metadata": {},
"outputs": [
{
...
...
@@ -778,27 +778,6 @@
"ax.plot_surface(xx, yy, z, alpha=0.2)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
...
...
%% Cell type:markdown id: tags:
# Curve optimization with the curves library
%% Cell type:markdown id: tags:
The [curve library](https://github.com/loco-3d/curves) is a header-only C++ library (also binded in python) that allows you
to create curves, in arbitrary dimensions (2, 3, n).
Originally, the library focused on spline curves, but it has now been extended to generic polynomials, cubic hermite splines, Bezier curves and more.
A nice upcoming extension is the ability to design curves in the Special Euclidian group SE3.
However in this tutorial we are going to focus on a rather unique trait of the library, which is the ability to work with variable control points. Rather than being given a constant value, the control points can be expressed as the linear combination of one or several variables. The main advantage of this representation is that variable curves
can be automatically derivated or integrated without any effort.
The other interest of variable curves is the ability to easily formulate optimization problems, which will be the focus of this tutorial. We will use the python bindings of the curve library to go through the steps of formulating and solving an optimization problem.
B has 3 rows and 12 columns. Because the fitting curve is of degree 3, it has 4 control points of dimension 3, which gives a variable of size 12. The row number also matches the dimension of the problem.
Then A is zero everywhere, expect for the first 3 columns that contain the identity. This is expected as the start of a Bezier curve is equal to the first control point.
If we evaluate variableBezier at t = 0.2 for instance, we get a more complex expression:
With variableBezier, we can easily define a least square problem to reconstruct the original curve.
We just have to formulate a cost function that, for each sample in ptsTime minimizes the distance between the evaluation of variableBezier and the sampled point. We define it as follows:
%% Cell type:code id: tags:
``` python
#least square form of ||Ax-b||**2
defto_least_square(A,b):
returndot(A.T,A),-dot(A.T,b)
defgenCost(variableBezier,ptsTime):
#first evaluate variableBezier for each time sampled