判断向量和点的位置关系

        写代码经常遇到判断向量和点的位置关系,做一个简单的记录,方便后面使用。

一、定义结构体

二、定义判断函数

def judgeDirection(startPoint, endPoint, P):
    
    tmp = (startPoint.y - endPoint.y)*P.x + (endPoint.x - startPoint.x)*P.y + startPoint.x*endPoint.y - endPoint.x*startPoint.y
    if tmp < 0:
        print("the point at the right of vector!")
    else:
        print("the point at the left of vertor")

  三、测试

  • 情形一

  • 情形二

原文地址:https://www.cnblogs.com/xiaxuexiaoab/p/12614811.html