资源简介
自己开发python的三边定位模块,包含
solve_quadratic_equation(a, b, c):解二次方程
triangle_area(x1,y1,x2,y2,x3,y3):计算三角形面积
triangle_perimeter(x1,y1,x2,y2,x3,y3):计算三角形周长
circle_intersect(r1,r2,x1,y1,x2,y2):计算两圆交点
locate(X,Y,R):利用两两相交的三个圆的6个交点,取合围边长最短的三个点的质心作为目标定位点
代码片段和文件信息
import math
combination_list = [(0 1 2) (0 1 3) (0 1 4) (0 1 5) (0 2 3) (0 2 4) (0 2 5) (0 3 4) (0 3 5) (0 4 5) (1 2 3) (1 2 4) (1 2 5) (1 3 4) (1 3 5) (1 4 5) (2 3 4) (2 3 5) (2 4 5) (3 4 5)];
def solve_quadratic_equation(a b c):
if a==0:
return ‘二次项不能为零!‘ ;
delta=b*b-4*a*c;
if delta>=0 and a!=0:
x1 = (-b+math.sqrt(delta))/(2*a);
x2 = (-b-math.sqrt(delta))/(2*a);
return [x1x2];
else:
return ‘方程无实数解!‘ ;
def triangle_area(x1y1x2y2x3y3):
return abs(x1*y2-x2*y1+x3*y1-x1*y3+x2*y3-x3*y2)/2;
def triangle_perimeter(x1y1x2y2x3y3):
a = math.sqrt((x1-x2)**2+(y1-y2)**2);
b = math.sqrt((x2-x3)**2+(y2-y3)**2);
c = math.sqrt((x3-x1)**2+(y3-y1)**2);
return a+b+c;
‘‘‘
(x1-x)^2+(y1-y)^2=r1^2----①
(x2-x)^2+(y2-y)^2=r2^2----②
①-②==>y=-(x1-x2)/(y1-y2)x+(x1^2-x2^2+y1^2-y2^2+r2^2-r1^2)/2(y1-y2)----③
或x=-(y1-y2)/(x1-x2)y+(y1^2-y2^2+x1^2-x2^2+r2^2-r1^2)/2(x1-x2)----④
当x1=/=x2,④代入①,否则③代入①。
‘‘‘
def circle_intersect(r1r2x1y1x2y2):
d = math.sqrt((x1-x2)**2+(y1-y2)**2);
if d>r1+r2:
return ‘两个圆无交点!‘;
elif x1!=x2:
k=(y1-y2)/(x1-x2);
D=(x1**2-x2**2+y1**2-y2**2+r2**2-r1**2)/(2*(x1-x2));
a=1+k**2;
b=(2*k*(x1-D)-2*y1);
c=y1**2+(x1-D)**2-r1**2;
- 上一篇:Python帮助手册CHM版
- 下一篇:OPENMV用作光流模组程序
评论
共有 条评论