python求交点坐标_Python - 两圆相交求交点坐标

Python - 两圆相交求交点坐标

Max.Bai

2016-05-16

Python - 两圆相交求交点坐标

三轴机械臂求坐标问题,其实转化为平面问题就是两圆相交求交点问题,交点算出来就可以用反三角函数算出各个机械臂的夹角。

已知圆1, 半径R, 坐标(x, y)

圆2, 半径S, 坐标(a, b)

求两圆交点x3, y3   x4, y4。

算法一脚本:

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

import math

def sq(x):

return float(x * x)

# target point on table

tx = float(10)

ty = float(10)

# hight of table

h0 = float(5)

# length of arm

R = float(10)

S = float(8)

# arm point

x = float(0)

y = float(5)

# target point for arm

a = float(math.sqrt(sq(tx)+ sq(ty)))

b = h0

print "arm target:", a, b

d = math.sqrt(sq(math.fabs(a-x)) + sq(math.fabs(b-y)))

print "desitens:", d

if d > (R+S) or d < (math.fabs(R-S)):

print "This point can't be rached!"

#return -1

exit

if d == 0 and R==S :

print "Can't rach arm point!"

#return -2

exit

A = (sq(R) - sq(S) + sq(d)) / (2 * d)

h = math.sqrt(sq(R) - sq(A))

x2 = x + A * (a-x)/d

y2 = y + A * (b-y)/d

#print x2, y2

x3 = x2 - h * ( b - y ) / d

y3 = y2 + h * ( a - x ) / d

x4 = x2 + h * (b - y) / d

y4 = y2 - h * (a - x) / d

print "arm middle point:"

print x3, y3

print x4, y4

已知圆1, 半径L1, 坐标(0, L3)

圆2, 半径L2, 坐标(x, y)

求圆1交点与圆心连线和Y轴的夹角a1,

圆2交点与圆心连线和X轴的夹角a2。

算法二:

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

import math

L1 = float(10)

L2 = float(10)

L3 = float(5)

x = float(14.1421356237)

y = float(5)

def sq(x):

return x * x

A = float(-2 * x * L1)

B = float(2*(y-L3)*L1)

C = float(sq(L2) - sq(L1) - sq(x) -sq(y-L3))

a1 = float(2*math.atan((B-math.sqrt(sq(B)+sq(A)-sq(C)))/(A+C)))

A = float(2 * (y - L3) * L2)

B = float(2 * x * L2)

C = float(sq(L2) + sq(x) + sq(L3-y) -sq(L1))

a2 = float(2* math.atan((B-math.sqrt(sq(B)+sq(A)-sq(C)))/(A+C)))

print a1, a2

print a1*180/math.pi, a2*180/math.pi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值