EDA365电子工程师网
标题:
[求助]请问怎么计算弧线对应的圆心角???
[打印本页]
作者:
361553894
时间:
2016-4-27 09:31
标题:
[求助]请问怎么计算弧线对应的圆心角???
本帖最后由 361553894 于 2016-4-27 09:57 编辑
怎么获取objType为"arc" 的弧线的圆心角???
目前做法是
Angle = axlDistance(car(seg->startEnd), cadr(seg->startEnd))/axlDistance(car(seg->startEnd), seg->xy)*180.0/3.1415926
但是怎么分辨小于半圆还是大于半圆?
作者:
deargds
时间:
2016-4-27 11:03
试下这个函数,可以区分优弧
defun( GetARC_Angle (db)
prog((r xy start startX startY endX endY end len pi)
len = nil
pi = 3.1415926
when(db->objType == "arc"
r = db->radius
xy = db->xy
start = nth(0 db->startEnd)
end = nth(1 db->startEnd)
startX = xCoord(start)-xCoord(xy)
startY = yCoord(start)-yCoord(xy)
endX = xCoord(end)-xCoord(xy)
endY = yCoord(end)-yCoord(xy)
startR = GetPointRadian(startX startY)
endR = GetPointRadian(endX endY)
if(db->isClockwise then
if(startR>endR then
len = (startR-endR)*r
else
len = (2*3.1415926+startR-endR)*r
)
else
if(startR>endR then
len = (2*3.1415926+endR-startR)*r
else
len = (endR-startR)*r
)
)
)
return((len*180)/(3.1415926*r))
))
defun( GetPointRadian (x y)
prog((a pi)
pi = 3.1415926
cond(
(x==0
cond(
(y==0 a=0)
(y>0 a=pi/2.0)
(t a=3.0*pi/2)
)
)
(x>0
cond(
(y==0 a=0)
(y>0 a=atan(y/x))
(t a=2.0*pi+atan(y/x))
)
)
(t
cond(
(y==0 a=pi)
(y>0 a=pi+atan(y/x))
(t a=pi+atan(y/x))
)
)
)
return(a)
)
)
;deargds
复制代码
作者:
361553894
时间:
2016-5-14 09:47
deargds 发表于 2016-4-27 11:03
试下这个函数,可以区分优弧
procedure( wlGetSegAngle(@optional (seg nil))
prog( (angle angle1 angle2)
unless(seg
axlSetFindFilter(?enabled '("noall" "linesegs" "clinesegs") ?onButtons '("noall" "linesegs" "clinesegs"))
seg = car(axlGetSelSet(axlSingleSelectPoint()))
)
unless(seg return(nil))
when(seg->objType == "line"
angle = wlGetVectorAngle(car(seg->startEnd) cadr(seg->startEnd))
)
when(seg->objType == "arc"
angle1 = wlGetVectorAngle(seg->xy car(seg->startEnd))
angle2 = wlGetVectorAngle(seg->xy cadr(seg->startEnd))
angle = angle2 - angle1
if(seg->isClockwise then
when(angle > 0 angle = angle - 360)
else
when(angle < 0 angle = angle + 360)
)
)
return(angle)
))
procedure( wlGetVectorAngle(start end)
let( (slope angle pi)
pi = 3.1415926
slope = axlLineSlope(list(start end))
if(slope then
angle = atan(slope) * 180.0 / pi
when(car(end) < car(start)
angle = angle + 180.0
)
when(angle < 0 angle = angle + 360.0)
else
if(cadr(end) > cadr(start) then
angle = 90.0
else
angle = 270.0
)
)
angle
))
复制代码
这是我写的获取角度的函数,直线直接获取起点到终点的角度,顺时针弧线获取负的旋转角度,逆时针弧线获取正的旋转角度
欢迎光临 EDA365电子工程师网 (https://bbs.elecnest.cn/)
Powered by Discuz! X3.2