【点】笛卡尔坐标与齐次坐标

齐次坐标就是用n+1维来代表N维坐标,这样做的目的是方便高效。把齐次坐标转化为笛卡尔坐标的方法是前面n-1个坐标分量分别除以最后一个分量即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import numpy as np

# 笛卡尔坐标点
point = np.array([5, 5])
# 转化为齐次坐标, point2=point3=point4
point2 = np.insert(point, len(point), values=1)
point3 = point2*0.3
point4 = point2*5

# 齐次坐标还原为笛卡尔坐标点
def homogeneous_to_cartesian(input_point):
if input_point[-1] > 0:
input_point = input_point / input_point[-1]
output_point = np.delete(input_point, len(input_point)-1)
return output_point

print(homogeneous_to_cartesian(point2))
print(homogeneous_to_cartesian(point3))
print(homogeneous_to_cartesian(point4))
0%