[snap] grip 根据3点获得圆心和半径

[复制链接]
梅雷工具箱发表于 2015-6-25 10:13:51 | 显示全部楼层 |阅读模式

$$ 根据3点获得圆心和半径
$$ (要求圆的xy平面上的3点z都为0)
gripsw / declrv  
number / num(4,3),r
number / resp,a,b,c,d,e,f,x,y

l10:
gpos/'梅雷提示!请选择参考点1。',num(1,1..3),resp
jump/l10:,end:,,,resp

l20:
gpos/'梅雷提示!请选择参考点2。',num(2,1..3),resp
jump/l10:,end:,,,resp

l30:
gpos/'梅雷提示!请选择参考点3。',num(3,1..3),resp
jump/l20:,end:,,,resp


ifthen/num(1,1..2)==num(3,1..2) and num(2,1..2)==num(3,1..2)
messg/'梅雷提示!3点不能共线。'
JUMP/L30:
endif

a=2*(num(2,1)-num(1,1))
b=2*(num(2,2)-num(1,2))
c=num(2,1)*num(2,1)+num(2,2)*num(2,2)-num(1,1)*num(1,1)-num(1,2)*num(1,2)
d=2*(num(3,1)-num(2,1))
e=2*(num(3,2)-num(2,2))
f=num(3,1)*num(3,1)+num(3,2)*num(3,2)-num(2,1)*num(2,1)-num(2,2)*num(2,2)
x=(b*f-e*c)/(b*d-e*a)
y=(d*c-a*f)/(b*d-e*a)
r=sqrtf((x-num(1,1))*(x-num(1,1))+(y-num(1,2))*(y-num(1,2)))

num(4,1)=x
num(4,2)=y
num(4,3)=0

print/'梅雷提示!以下分别为 圆心坐标 和圆半径'
print/num(4,1..3)
print/r

end:
halt





_____________________________________________________________________________ _

中磊UG二次开发教程 梅雷著 qq1821117007
学UG就上UG网 http://www.9sug.com/
就上UG网淘宝直营店
您需要登录后才可以回帖 登录 | 注册UG网 用百度帐号登录

本版积分规则