日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python判断点在矩形内_判断平面内矩形和圆是否有交点的python实现

發(fā)布時間:2025/3/11 python 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python判断点在矩形内_判断平面内矩形和圆是否有交点的python实现 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

#! /usr/bin/env python

# -*- coding: utf-8 -*-

'''

@filename : 平面坐標內(nèi)矩形與圓是否相交

@usage :

@authors : U{peterguo}

@copyright: tencent

@date : 2012.08.21

@version : 1.0.0.0

Modified History:

2012.08.21 創(chuàng)建

'''

import os

import sys

import re

import urllib2

import time

import datetime

import math

def usage():

'''

用法說明

'''

sys.exit(1)

def bPointInCircle(fPointX, fPointY, fCircleX, fCircleY, fRadius):

oPoint = complex(fPointX, fPointY)

oCircle = complex(fCircleX, fCircleY)

if abs(oPoint - oCircle) < fRadius:

return True

else:

return False

def bPointInRectangle(fPointX, fPointY, fRectTopLeftX, fRectTopLeftY, fRectBottomRightX, fRectBottomRightY):

if not (fRectTopLeftX <= fPointX <= fRectBottomRightX or fRectTopLeftX >= fPointX >= fRectBottomRightX):

return False

if not (fRectTopLeftY <= fPointY <= fRectBottomRightY or fRectTopLeftY >= fPointY >= fRectBottomRightY):

return False

return True

def bCircleIntersectRectangle(fRectTopLeftX=0, fRectTopLeftY=10, fRectBottomRightX=20, fRectBottomRightY=0, #矩形左上點和右下點坐標

fCircleX=0, fCircleY=0, #圓心

fRadius=10): #圓半徑

o1 = complex(fRectTopLeftX, fRectTopLeftY)

o4 = complex(fRectBottomRightX, fRectBottomRightY)

o2 = complex(fRectBottomRightX, fRectTopLeftY)

o3 = complex(fRectTopLeftX, fRectBottomRightY)

bO1 = bPointInCircle(fCircleX, fCircleY, o1.real, o1.imag, fRadius)

bO2 = bPointInCircle(fCircleX, fCircleY, o2.real, o2.imag, fRadius)

bO3 = bPointInCircle(fCircleX, fCircleY, o3.real, o3.imag, fRadius)

bO4 = bPointInCircle(fCircleX, fCircleY, o4.real, o4.imag, fRadius)

bABCD = bPointInRectangle(fCircleX, fCircleY, o1.real, o1.imag + fRadius, o2.real, o2.imag - fRadius)

bEFGH = bPointInRectangle(fCircleX, fCircleY, o3.real, o3.imag + fRadius, o4.real, o4.imag - fRadius)

bIJKL = bPointInRectangle(fCircleX, fCircleY, o1.real - fRadius, o1.imag, o3.real + fRadius, o3.imag)

bMNOP = bPointInRectangle(fCircleX, fCircleY, o2.real - fRadius, o2.imag, o4.real + fRadius, o4.imag)

#print bO1 , bO2 , bO3 , bO4 , bABCD , bEFGH , bIJKL , bMNOP

return bO1 or bO2 or bO3 or bO4 or bABCD or bEFGH or bIJKL or bMNOP

if __name__ == "__main__":

print "False", bPointInCircle(0,0, 100, 100, 100)

print "False", bPointInCircle(0,0, 100, 100, 10)

print "True", bPointInCircle(0,0, 0, 0, 10)

print "True", bPointInRectangle(0, 0, -1, -2, 3, 4)

print "False", bPointInRectangle(0, 0, 1, 2, 3, 4)

print "True", bCircleIntersectRectangle()

print "False", bCircleIntersectRectangle(2.0, 4.0, 4.5, 1.0, 1.0, 2.0, 1.0)

print "True", bCircleIntersectRectangle(2.0, 4.0, 4.5, 1.0, 1.0, 2.0, 2.0)

print "False", bCircleIntersectRectangle(2.0, 4.0, 4.5, 1.0, 100.0, 2.0, 2.0)

print "True", bCircleIntersectRectangle(2.0, 4.0, 4.5, 1.0, 3.0, 3.0, 1.0)

print "False", bCircleIntersectRectangle(2.0, 4.0, 4.5, 1.0, 3.0, 3.0, 0.5)

總結(jié)

以上是生活随笔為你收集整理的python判断点在矩形内_判断平面内矩形和圆是否有交点的python实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。