考虑到android java中的距离和Angular ,我试图从起点到终点画一条直线。我使用的公式是:
lineX = (float) (lastX + (30 * cos(orientationDegree)));
lineY = (float) (lastY + (30 * sin(orientationDegree)));
ondraw公司:
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
drawRotateImage(canvas);
for (Line l : listLine) {
canvas.drawLine(l.StartX, l.StartY, l.EndX, l.EndY, paint);
}
}
private void stepDetector () {
l = new Line();
l.setStartX(lastX);
l.setStartY(lastY);
l.setOrientationDegree(orientationDegree);
lineX = (float) (lastX + (30 * cos(orientationDegree)));
lineY = (float) (lastY + (30 * sin(orientationDegree)));
l.setEndX(lineX);
l.setEndY(lineY);
listLine.add(l);
System.out.println ("" + l.toString());
invalidate();
lastX = lineX;
lastY = lineY;
}
每行将保存在一个数组中 onDraw
是为了划清界限。然而,它似乎并不准确。方向是朝着任何不符合预期的方向。如果用户以特定Angular 笔直行走,则应画一条直线,而不是以不同Angular 。这似乎是由于android的坐标系统。你能告诉我如何使它准确吗?
谢谢。
暂无答案!
目前还没有任何答案,快来回答吧!