我想知道除了距离公式之外,还有没有其他方法来计算等边三角形的第三点?。我正在浏览下面的代码片段,它在两点之间进行相似性转换。我不明白他们是怎么计算第三点的
def similarityTransform(inPoints, outPoints):
s60 = math.sin(60*math.pi/180)
c60 = math.cos(60*math.pi/180)
inPts = np.copy(inPoints).tolist()
outPts = np.copy(outPoints).tolist()
# The third point is calculated so that the three points make an equilateral triangle
xin = c60*(inPts[0][0] - inPts[1][0]) - s60*(inPts[0][1] - inPts[1][1]) + inPts[1][0]
yin = s60*(inPts[0][0] - inPts[1][0]) + c60*(inPts[0][1] - inPts[1][1]) + inPts[1][1]
inPts.append([np.int(xin), np.int(yin)])
xout = c60*(outPts[0][0] - outPts[1][0]) - s60*(outPts[0][1] - outPts[1][1]) + outPts[1][0]
yout = s60*(outPts[0][0] - outPts[1][0]) + c60*(outPts[0][1] - outPts[1][1]) + outPts[1][1]
outPts.append([np.int(xout), np.int(yout)])
# Now we can use estimateRigidTransform for calculating the similarity transform.
tform = cv2.estimateAffinePartial2D(np.array([inPts]), np.array([outPts]))
return tform[0]
为什么我们需要计算第三个点,因为在opencv中,estimateAffinePartial2D
需要三个点来计算相似性矩阵。我们只有两点
目前没有回答
相关问题 更多 >
编程相关推荐