Python Test If Point is in Rectangle

后端 未结 2 1003
日久生厌
日久生厌 2021-01-13 08:55

I am new to python and still learning the ropes but I am hoping someone with more experience can help me out.

I am trying to write a python script that:

2条回答
  •  礼貌的吻别
    2021-01-13 09:40

    It is better to write a separate function to do the job. Here's my function. You can just copy it if you want

    def pointInRect(point,rect):
        x1, y1, w, h = rect
        x2, y2 = x1+w, y1+h
        x, y = point
        if (x1 < x and x < x2):
            if (y1 < y and y < y2):
                return True
        return False
    

提交回复
热议问题