您的PolarPoint类表示极坐标(从原点开始的半径和从x轴逆时针开始的角度)的点,两者都是double类型。不要为任何操作转换为笛卡尔坐标(当然,xCoodinate和yCoordinate除外)。 rotate90操作必须返回一个新的PolarPoint。
import java.lang.Math;
public class PolarPoint implements Point{
private double radius;
private double angle;
public PolarPoint(double radius, double angle) {
this.radius = radius;
this.angle = angle;
}
public double angle()
{
return angle;
}
public double radius()
{
return radius;
}
public double xCoordinate()
{
return (radius * Math.cos(angle)) //Idk if its the right way
}
public double yCoordinate()
{
return (radius * Math.sin(angle)) //Idk if its the right way
}
public Point rotate90()
{
return angle() + 90.0 // Error
}
public double distanceFrom(Point other)
{
//Idk how to do this
}
答案 0 :(得分:2)
使用方法Math.cos(angle)
和Math.sin(angle)
时要小心,参数angle
必须是弧度,而不是度数,这就是为什么在rotate90
方法中添加90.0不会给你期望的行为。
如果要在辐射中添加90.0度,请添加Math.PI/2
。