|
回复 1楼c724211922的帖子
帮你写了两个函数,测试没有问题。- //第一个:
- //用这个公式sqrl(x*x+y*y-2*x*y*cos(alfa*PI/180))直接算出来就行了
- //sqrl:开平方,alfa:度数,PI:3.1415926
- function double getotherside(double x,double y,double alfa)
- double rtn
- double PI = 3.1415926
- rtn = math.sqrt(x*x+y*y-2*x*y*math.cos(alfa*PI/180))
- return rtn
- endfunction
- //第二个:
- //先算出45°情况的边长:a=z*cos(45*PI/180)
- //从1开始,到a结束,看看是否符合
- function bool getenablearray(double z,int[][] &arr)
- int[][] idx = int[50][2]
- int count
- double PI = 3.1415926
- double ax = z*math.cos(45*PI/180)
- double i=1,j
- while(i<ax)
- j = math.sqrt(z*z-i*i)
- int ij = convert.doubletoint(j)
- if(ij*ij+i*i==z*z)
- idx[count][0]=convert.doubletoint(i)
- idx[count][1]=ij
- count = count+1
- endif
- i = i + 1
- endwhile
- if(count>0)
- arr = int[count][2]
- int k = 0
- while(k<count)
- arr[k][0]=idx[k][0]
- arr[k][1]=idx[k][1]
- k = k + 1
- endwhile
- return true
- endif
- return false
- endfunction
复制代码
|

|