Skip to content
Snippets Groups Projects
Commit 69a3fd55 authored by Wellidontcare's avatar Wellidontcare
Browse files

add line intersect and line scan camera

parent d90a2fc1
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:opposed-illness tags:
``` python
import numpy as np
import matplotlib.pyplot as plt
from scipy import optimize
```
%% Cell type:code id:preceding-intention tags:
``` python
R = 5
x = R*np.sin(np.linspace(-np.pi, np.pi)) + 5
x += np.random.random(size=x.shape)
y = R*np.cos(np.linspace(-np.pi, np.pi)) - 3
y += np.random.random(size=y.shape)
```
%% Cell type:code id:automatic-bunch tags:
``` python
def residual(a):
return np.sum((x - a[0])**2 + (y - a[1])**2 - a[2]**2)
```
%% Cell type:code id:polish-domain tags:
``` python
solution = optimize.least_squares(residual, np.array([1, 10, 100])).x
#solution2 = optimize.newton(residual, np.array([1, 1, 1])).x
```
%% Cell type:code id:sixth-remainder tags:
``` python
result = []
for dx in np.linspace(-8, 0):
for dy in np.linspace(0, 8):
for dR in np.linspace(0, 10):
result.append(residual(np.array([dx, dy, dR])))
```
%% Cell type:code id:specified-smoke tags:
``` python
fig, ax = plt.subplots()
plt.plot(x, y, 'o')
plt.axis("equal")
x_m, y_m, R = solution
circle = plt.Circle([x_m, y_m], R, fill=False)
ax.add_artist(circle)
plt.grid(True)
```
%% Output
%% Cell type:code id:lucky-plaza tags:
``` python
```
%% Cell type:code id:democratic-breath tags:
``` python
%matplotlib notebook
res = np.array(result)
func = np.abs(np.array(res.reshape(50, 50, 50)))
plt.figure(1)
plt.imshow(func[:, :, 10])
fig = plt.figure(2)
xx, yy = np.mgrid[-8:0:50j, 8:0:50j]
Z = func[:, :, 10]
my_col = plt.cm.jet(Z / np.max(Z))
ax = fig.add_subplot(projection='3d')
ax.plot_surface(xx, yy, func[:, :, 10], facecolors=my_col)
```
%% Output
<mpl_toolkits.mplot3d.art3d.Poly3DCollection at 0x7fcd7467b100>
%% Cell type:code id:heated-mixture tags:
``` python
t = -5
m = 3
x = np.array([1, 2, 3, 5, 6])
y = np.array([7, 10, 17, 20, 19])
plt.figure(3)
plt.plot(x, y, 'o')
plt.xlim((-5, 10))
plt.ylim((0, 30))
a, b = np.polyfit(x, y, deg=1)
print(a, b)
plt.plot(x, a*x + b)
plt.grid(True)
```
%% Output
2.5465116279069773 5.9418604651162825
%% Cell type:code id:distinguished-testimony tags:
``` python
N = len(x)
sum_x = np.sum(x)
sum_y = np.sum(y)
x_2 = np.sum(x**2)
sum_x2 = sum_x**2
sum_xy = np.sum(x*y)
a = (N*(sum_xy) - (sum_x * sum_y)) / (N*(x_2) - sum_x2)
print(a)
```
%% Output
2.546511627906977
%% Cell type:code id:hidden-publicity tags:
``` python
m = -0.5
b = 2.3
```
......
%% Cell type:code id:necessary-twenty tags:
``` python
import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
```
%% Cell type:code id:political-johnson tags:
``` python
m1, m2, t1, t2, x = sp.symbols("m1, m2, t1, t2, x")
# a1, b1, c1, y1, a2, b2, c2, y2 = sp.symbols("a1, b1, c1, y1, a2, b2, c2, y2")
```
%% Cell type:code id:naval-daniel tags:
``` python
y1 = m1 *x + t1
y2 = m2 *x + t2
x_solve = sp.solveset(sp.Eq(y1, y2), x).args[0]
y_solve = m1 * x_solve + t1
display(x_solve)
display(y_solve)
```
%% Output
$\displaystyle - \frac{t_{1} - t_{2}}{m_{1} - m_{2}}$
$\displaystyle - \frac{m_{1} \left(t_{1} - t_{2}\right)}{m_{1} - m_{2}} + t_{1}$
%% Cell type:code id:solar-mercury tags:
``` python
def find_intersect()
```
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment