计算几何

点:二维空间中的点采采用 (x, y) 来表示
线段:线段通常是有方向的,因此用矢量来表示
notion imagenotion image
判断三点是否在一条直线上:
p1, p2, p3 是否在同一条直线上,判断 直线 p1p3 和 p1p2 斜率是否相同,即:
但由于 计算上式会出现 除法中分母为 0 的风险,所以 改为判断 乘法:
def helper(points, i, j, k): # 判断 i j k 三点是否在一条直线上 p1, p2, p3 = points[i], points[j], points[k] return (p3[1]-p1[1]) * (p2[0]-p1[0]) == (p3[0]-p1[0]) * (p2[1]-p1[1])
矢量的运算
内积:
notion imagenotion image
notion imagenotion image
外积
notion imagenotion image
notion imagenotion image
notion imagenotion image
本质上 可判断斜率是一样的
 
计算两点之间的距离
notion imagenotion image
notion imagenotion image
上题,感觉用华东窗口更好,可以达到O(n)的复杂度
notion imagenotion image
notion imagenotion image
矢量的旋转
notion imagenotion image
用矩阵表示更好一点
判断一个点是否在矩形内
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
定义一个res 集合, 遍历 每根木工,将 res 中 与当亲木棒有交叉的 移除掉,再将当前木棒放进来。
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
需要加绝对值
 
三角形的质心
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image
notion imagenotion image

经典题目