我目前正在构建一个小型罗盘应用程序,我画了南北线 使用简单的圆方程:x = a + r Cos(t)和y = b + r Sin(t)其中t =方向或方向(角度)。更多信息在Wiki
到目前为止我已经得到了南北线。这是我的工作
//canvas.drawLine(startX, startY, stopX, stopY, paint)
//Drawing North
canvas.drawLine(cxCompass, cyCompass,
(float)(cxCompass + radiusCompass * Math.sin((double)(-direction) * 3.14/180)),
(float)(cyCompass - radiusCompass * Math.cos((double)(-direction) * 3.14/180)),
paint);
//Drawing South
canvas.drawLine(cxCompass, cyCompass,
(float)(cxCompass - radiusCompass * Math.sin((double)(-direction) * 3.14/180)),
(float)(cyCompass + radiusCompass * Math.cos((double)(-direction) * 3.14/180)),
paint);
我的问题:我不知道我们如何获得东西线?
CxCompass,CyCompass:圆心的坐标
答案 0 :(得分:0)
通过添加90度修复了该问题。 我很乐意分享它
//Drawing west
canvas.drawLine(cxCompass, cyCompass,
(float)(cxCompass + radiusCompass * Math.sin((double)(-direction-90) * 3.14/180)),
(float)(cyCompass - radiusCompass * Math.cos((double)(-direction-90) * 3.14/180)),
paint);
//Drawing east
canvas.drawLine(cxCompass, cyCompass,
(float)(cxCompass - radiusCompass * Math.sin((double)(-direction-90) * 3.14/180)),
(float)(cyCompass + radiusCompass * Math.cos((double)(-direction-90) * 3.14/180)),
paint);