VB极坐标
请问VB中有没有什么方法可以实现极坐标与直角坐标转换的?或者直接用极坐标控制当前位置可以吗?比如说我有一系列的点的直角坐标数值,想把它转成极坐标该怎么弄啊?谢谢!
参考答案:由于转极坐标比较复杂,劝你还是转成柱坐标更实用一些。设a为一个n行2列的数组,第一列为x坐标第二列为y坐标。b为相应的极坐标数组,则:
const pi=3.1415926535897932384626433832795
for i=1 to n step 1
if a(i,1)<>0 and a(i,2)>0 then
b(i,1)=acos(a(i,1)/(a(i,1)^2+a(i,2)^2)^0.5)
b(i,2)=(a(i,1)^2+a(i,2)^2)^0.5
elseif a(i,1)=0 and a(i,2)>0 then
b(i,1)=pi/2
b(i,2)=a(i,2)
elseif a(i,1)=0 and a(i,2)<0 then
b(i,1)=pi*3/2
b(i,2)=-a(i,2)
elseif a(i,1)<>0 and a(i,2)<0 then
b(i,1)=acos(a(i,1)/(a(i,1)^2+a(i,2)^2)^0.5)+pi
b(i,2)=(a(i,1)^2+a(i,2)^2)^0.5
elseif a(i,2)=0 and a(i,1)>0 then
b(i,1)=0
b(i,2)=a(i,1)
elseif a(i,2)=0 and a(i,1)<0 then
b(i,1)=pi
b(i,2)=-a(i,1)
end if
next i