我有 4 个点,它们非常接近一个平面 - 它是 1,4-二氢吡啶循环。
我需要计算从 C3 和 N1 到由 C1-C2-C4-C5 组成的平面的距离。计算距离是可以的,但拟合平面对我来说相当困难。
1,4-DHP 循环:
1,4-DHP循环,另一种说法:
from array import *
from numpy import *
from scipy import *
# coordinates (XYZ) of C1, C2, C4 and C5
x = [0.274791784, -1.001679346, -1.851320839, 0.365840754]
y = [-1.155674199, -1.215133985, 0.053119249, 1.162878076]
z = [1.216239624, 0.764265677, 0.956099579, 1.198231236]
# plane equation Ax + By + Cz = D
# non-fitted plane
abcd = [0.506645455682, -0.185724560275, -1.43998120646, 1.37626378129]
# creating distance variable
distance = zeros(4, float)
# calculating distance from point to plane
for i in range(4):
distance[i] = (x[i]*abcd[0]+y[i]*abcd[1]+z[i]*abcd[2]+abcd[3])/sqrt(abcd[0]**2 + abcd[1]**2 + abcd[2]**2)
print distance
# calculating squares
squares = distance**2
print squares
如何使总和(平方)最小化?我尝试过最小二乘,但它对我来说太有用了。