I need help showing the shape or plane that best fits these coordinates in 3D. I have already found the plane of best fit using least squares method on python. Now I want to see if there is a more exact curve, perhaps one that curves and I want the program to output the equation if possible. I would like to compare these numbers to these z outputs.The other z outputs
If it is easier to ask for the relationship between these two z outputs that is something else I would like to know. But I would want the mathematical relationship between the two or how the two planes compare. If you need more information please ask! I have attached code I used already to find the flat plane of best fit.
This is some of the coordinates
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
'''''
xs=[
0,1,2,3,4,5,6,7,8,9,
10,11,12,13,14,15,16,
17,18,19,20,21,22,23,
24,25,26,27,28,29,30,
31,32,33,34,35,36,37,
38,39,40,41,42,43,44,
45,46,47,48,49,50,51,
52,53,54,55,56,57,58,
59,60,61,62,63,64,65,
66,67,68,69,70,71,72,
73,74,75,76,77,78,79,
80,81,82,83,84,85,86,
87,88,89,90,91,92,93,94,
0,1,2,3,4,5,6,7,8,9,
10,11,12,13,14,15,16,
17,18,19,20,21,22,23,
24,25,26,27,28,29,30,
31,32,33,34,35,36,37,
38,39,40,41,42,43,44,
45,46,47,48,49,50,51,
52,53,54,55,56,57,58,
59,60,61,62,63,64,65,
66,67,68,69,70,71,72,
73,74,75,76,77,78,79,
80,81,82,83,84,85,86,
87,88,89,90,91,92,93,94,
0,1,2,3,4,5,6,7,8,9,
10,11,12,13,14,15,16,
17,18,19,20,21,22,23,
24,25,26,27,28,29,30,
31,32,33,34,35,36,37,
38,39,40,41,42,43,44,
45,46,47,48,49,50,51,
52,53,54,55,56,57,58,
59,60,61,62,63,64,65,
66,67,68,69,70,71,72,
73,74,75,76,77,78,79,
80,81,82,83,84,85,86,
87,88,89,90,91,92,93,94,
0,1,2,3,4,5,6,7,8,9,
10,11,12,13,14,15,16,
17,18,19,20,21,22,23,
24,25,26,27,28,29,30,
31,32,33,34,35,36,37,
38,39,40,41,42,43,44,
45,46,47,48,49,50,51,
52,53,54,55,56,57,58,
59,60,61,62,63,64,65,
66,67,68,69,70,71,72,
73,74,75,76,77,78,79,
80,81,82,83,84,85,86,
87,88,89,90,91,92,93,94,
0,1,2,3,4,5,6,7,8,9,
10,11,12,13,14,15,16,
17,18,19,20,21,22,23,
24,25,26,27,28,29,30,
31,32,33,34,35,36,37,
38,39,40,41,42,43,44,
45,46,47,48,49,50,51,
52,53,54,55,56,57,58,
59,60,61,62,63,64,65,
66,67,68,69,70,71,72,
73,74,75,76,77,78,79,
80,81,82,83,84,85,86,
87,88,89,90,91,92,93,94,
0,1,2,3,4,5,6,7,8,9,
10,11,12,13,14,15,16,
17,18,19,20,21,22,23,
24,25,26,27,28,29,30,
31,32,33,34,35,36,37,
38,39,40,41,42,43,44,
45,46,47,48,49,50,51,
52,53,54,55,56,57,58,
59,60,61,62,63,64,65,
66,67,68,69,70,71,72,
73,74,75,76,77,78,79,
80,81,82,83,84,85,86,
87,88,89,90,91,92,93,94
]
'''''
#right wheel track Dmeter
'''''
ys = [0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,
2,2,2,2,2,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,
4,4,4,4,4,
]
'''
'''''
zs = [
#right D-meter
0.725/12,0.057833333,0.045,0.036666667,0.031916667,0.029083333,0.0295,0.0315,0.025166667,
0.025083333,0.027166667,0.03,0.036833333,0.041083333,0.050166667,0.060416667,0.058416667,0.054833333,
0.053916667,0.049666667,0.0415,0.030083333,0.023083333,0.017416667,0.015666667,0.0125,0.014166667,
0.014333333,0.01525,0.018583333,0.006833333,0.001083333,-0.006833333,-0.012166667,-0.016416667,-0.019166667,
-0.015916667,-0.01475,-0.008916667,-0.012083333,-0.013083333,-0.012333333,-0.002916667,0.007166667,0.003416667,
-0.00475,-0.009,-0.01175,-0.013166667,-0.013583333,-0.01175,-0.011833333,-0.009333333,-0.008166667,
-0.005,-0.004416667,-0.004916667,-0.005833333,-0.014416667,-0.019666667,-0.020916667,-0.02475,-0.02675,
-0.027,-0.026916667,-0.027333333,-0.0255,-0.026,-0.02025,-0.014833333,-0.0095,-0.004916667,
-0.014916667, -0.024166667,-0.027666667,-0.029916667,-0.029833333,-0.029,-0.0255,-0.020166667,-0.013,
-0.012083333,-0.00775,-0.002416667,0.004666667,0.014,0.003166667,-0.008166667,-0.0175,-0.0275,
-0.0305,-0.031333333,-0.02925,-0.02625,-.295/12,
#right Face
0.0579166666666667,0.0554166666666667,0.0426666666666667,0.0344166666666667,0.02975,0.0269166666666667,0.0274166666666667,0.0295,0.02325,
0.02325,0.0254166666666667,0.0283333333333333,0.03525,0.0395833333333333,0.0486666666666667,0.059,0.0570833333333333,0.0535833333333333,
0.05275,0.0485833333333333,0.0405,0.0291666666666667,0.0221666666666667,0.0165833333333333,0.0149166666666667,0.0118333333333333,0.0135833333333333,
0.0138333333333333,0.0148333333333333,0.01825,0.00658333333333333,0.000833333333333333,-0.007,-0.01225,-0.0164166666666667,-0.0190833333333333,
-0.01575,-0.0145,-0.00858333333333333,-0.01175,-0.0126666666666667,-0.0118333333333333,-0.00233333333333333,0.00783333333333333,0.00416666666666667,
-0.00391666666666667,-0.00808333333333333,-0.01075,-0.0121666666666667,-0.0125,-0.0105833333333333,-0.0105833333333333,-0.008,-0.00675,
-0.0035,-0.00283333333333333,-0.00333333333333333,-0.00416666666666667,-0.0126666666666667,-0.0178333333333333,-0.019,-0.02275,-0.0246666666666667,
-0.0248333333333333,-0.0246666666666667,-0.0250833333333333,-0.0231666666666667,-0.0235833333333333,-0.01775,-0.01225,-0.00683333333333333,-0.00216666666666667,
-0.0120833333333333,-0.0213333333333333,-0.02475,-0.0269166666666667,-0.02675,-0.0258333333333333,-0.02225,-0.0168333333333333,-0.00958333333333333,
-0.00858333333333333,-0.00425,0.00116666666666667,0.00833333333333333,0.01775,0.007,-0.00425,-0.0135,-0.0234166666666667,
-0.0264166666666667,-0.0271666666666667,-0.025,-0.0219166666666667,-0.0201666666666667,
#center D-meter
0.0571666666666667,0.0601666666666667,0.0479166666666667,0.0368333333333333,0.0284166666666667,0.0235,0.02125,0.0229166666666667,0.0235,
0.0236666666666667,0.0280833333333333,0.0325,0.0340833333333333,0.0398333333333333, 0.0494166666666667,0.057,0.056,0.0559166666666667,
0.0525833333333333,0.0468333333333333,0.0389166666666667,0.02725,0.0179166666666667,0.0118333333333333,0.012,0.0105833333333333,0.0119166666666667,
0.0150833333333333,0.0200833333333333,0.0205,0.00858333333333333,8.33333333333333E-05,-0.00558333333333333,-0.01125,-0.01625,-0.0189166666666667,
-0.0180833333333333,-0.01675,-0.0119166666666667,-0.0116666666666667,-0.0101666666666667,-0.00941666666666667,-0.00425,0.000833333333333333,-0.0025,
-0.00616666666666667,-0.00991666666666667,-0.00958333333333333,-0.01075,-0.0119166666666667,-0.0115833333333333,-0.013,-0.0116666666666667,-0.01,
-0.006,-0.00791666666666667,-0.00875,-0.0085,-0.0170833333333333,-0.02,-0.0201666666666667,-0.0225833333333333,-0.0225833333333333,
-0.02525,-0.02325,-0.02375,-0.0228333333333333,-0.0221666666666667,-0.0185833333333333,-0.0153333333333333,-0.00925,-0.00791666666666667,
-0.0204166666666667,-0.02925,-0.0326666666666667,-0.03575,-0.034,-0.0305833333333333,-0.0243333333333333,-0.0201666666666667,-0.0144166666666667,
-0.0105,-0.00658333333333333,-0.00133333333333333,0.00675,0.0139166666666667, 0.001, -0.011, -0.023, -0.0318333333333333,
-0.0346666666666667,-0.0375,-0.0331666666666667,-0.027,-0.0233333333333333,
#Face Center
0.053,0.0560833333333333,0.0439166666666667,0.0328333333333333,0.0245,0.0196666666666667,0.0174166666666667,0.0191666666666667,0.0198333333333333,
0.02,0.0245,0.029,0.0306666666666667,0.0364166666666667,0.0460833333333333,0.05375,0.05275,0.05275,
0.0495,0.04375,0.0359166666666667,0.0243333333333333,0.015,0.009,0.00925,0.00783333333333333,0.00925,
0.0125,0.0175833333333333,0.018,0.00616666666666667,-0.00225,-0.00791666666666667,-0.0135,-0.0184166666666667,-0.0210833333333333,
-0.0201666666666667,-0.01875,-0.0139166666666667,-0.0135833333333333,-0.012,-0.01125,-0.006,-0.000833333333333333,-0.00416666666666667,
-0.00775,-0.0114166666666667,-0.011,-0.0121666666666667,-0.01325,-0.0128333333333333,-0.01425,-0.0128333333333333,-0.0110833333333333,
-0.00708333333333333,-0.00891666666666667,-0.00966666666666667,-0.00941666666666667,-0.0179166666666667,-0.02075,-0.0209166666666667,-0.02325,-0.0231666666666667,
-0.02575,-0.02375,-0.0241666666666667,-0.0231666666666667,-0.0225,-0.0188333333333333,-0.0155,-0.00941666666666667,-0.008,
-0.0204166666666667,-0.02925,-0.0325833333333333,-0.0355833333333333,-0.0338333333333333,-0.0303333333333333,-0.024,-0.0198333333333333,-0.014,
-0.01,-0.006,-0.00075,0.00741666666666667,0.0146666666666667,0.00175,-0.0101666666666667,-0.0220833333333333,-0.0309166666666667,
-0.0336666666666667,-0.0364166666666667,-0.0320833333333333,-0.0258333333333333,-0.0220833333333333,
#Left D-Meter
0.048166667,0.053,0.047583333,0.034333333,0.025666667,0.019416667,0.02025,0.01625,0.017333333,
0.0195,0.017166667,0.01575,0.015833333,0.02075,0.02825,0.039583333,0.046583333,0.04425,
0.0415,0.036,0.032833333,0.023,0.011083333,0.006166667,0.007083333,0.006916667,0.008833333,
0.014333333,0.01675,0.018166667,0.008666667,-0.002916667,-0.013166667,-0.014833333,-0.01925,-0.0215,
-0.025416667,-0.023333333,-0.019666667,-0.012916667,-0.0145,-0.015416667,-0.012916667,-0.008416667,-0.005,
-0.005583333,-0.005,-0.007583333,-0.011833333,-0.012666667,-0.010666667,-0.010166667,-0.0095,-0.009083333,
-0.00975,-0.007666667,-0.009833333,-0.01,-0.014416667,-0.01825,-0.019,-0.018416667,-0.02,
-0.0225,-0.022583333,-0.022833333,-0.019083333,-0.016333333,-0.014333333,-0.009,-0.00475,0.000416667,
-0.0055,-0.020583333,-0.028,-0.032083333,-0.029166667,-0.027,-0.024416667,-0.021666667,-0.017166667,
-0.013,-0.009,-0.008333333,-0.000916667,0.00975,0.009833333,-0.001166667,-0.0115,-0.025083333,
-0.033833333,-0.037166667,-0.0335,-0.02725,-0.021916667,
#Face Left
0.0530833333333333,0.0578333333333333,0.0523333333333333,0.039,0.03025,0.0239166666666667,0.0246666666666667,0.0205833333333333,0.0215833333333333,
0.02375,0.0213333333333333,0.0198333333333333,0.0198333333333333,0.0246666666666667,0.0320833333333333,0.0433333333333333,0.05025,0.0479166666666667,
0.0450833333333333,0.0395,0.03625,0.0263333333333333,0.0143333333333333,0.00933333333333333,0.0101666666666667,0.00991666666666667,0.0118333333333333,
0.01725,0.0195833333333333,0.0209166666666667,0.0113333333333333,-0.000333333333333333,-0.0106666666666667,-0.0124166666666667,-0.0168333333333333,-0.0191666666666667,
-0.0231666666666667,-0.0211666666666667,-0.0175833333333333,-0.0109166666666667,-0.0125833333333333,-0.0135833333333333,-0.0111666666666667,-0.00666666666666667,-0.00333333333333333,
-0.004,-0.0035,-0.00616666666666667,-0.0105,-0.0114166666666667,-0.0095,-0.009,-0.00841666666666667,-0.00808333333333333,
-0.00883333333333333,-0.00683333333333333,-0.00908333333333333,-0.00933333333333333,-0.0138333333333333,-0.01775,-0.0185,-0.018,-0.0196666666666667,
-0.02225,-0.0224166666666667,-0.02275,-0.0190833333333333,-0.0164166666666667,-0.0144166666666667,-0.00916666666666667,-0.005,-8.33333333333333E-05,
-0.00591666666666667,-0.0210833333333333,-0.0285833333333333,-0.03275,-0.0299166666666667,-0.02775,-0.02525,-0.0225833333333333,-0.0181666666666667,
-0.0140833333333333,-0.0101666666666667,-0.00958333333333333,-0.00225,0.00833333333333333,0.00841666666666667,-0.00266666666666667,-0.0130833333333333,-0.02675,
-0.0355833333333333,-0.039,-0.0354166666666667,-0.02925,-0.0239166666666667
]
'''
# plot raw data
plt.figure()
ax = plt.subplot(111, projection='3d')
ax.scatter(xs, ys, zs, color='b')
#do fit
tmp_A = []
tmp_b = []
for i in range(len(xs)):
tmp_A.append([xs[i], ys[i], 1])
tmp_b.append(zs[i])
b = np.matrix(tmp_b).T
A = np.matrix(tmp_A)
#Or use Scipy
from scipy.linalg import lstsq
fit, residual, rnk, errors = lstsq(A, b)
print("solution: %f x + %f y + %f = z" % (fit[0], fit[1], fit[2]))
print("errors: \n", errors)
print("residual:", residual)
# plot plane
xlim = ax.get_xlim()
ylim = ax.get_ylim()
X,Y = np.meshgrid(np.arange(xlim[0], xlim[1]),
np.arange(ylim[0], ylim[1]))
Z = np.zeros(X.shape)
for r in range(X.shape[0]):
for c in range(X.shape[1]):
Z[r,c] = fit[0] * X[r,c] + fit[1] * Y[r,c] + fit[2]
ax.plot_wireframe(X,Y,Z, color='k')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()

