Please help me write mehtod Point rotate90() in java import java.lang.*; class P
ID: 3706753 • Letter: P
Question
Please help me write mehtod Point rotate90() in java
import java.lang.*;
class Point
{
private final double x;
private final double y;
public Point(double x, double y)
{
this.x =x;
this.y = y;
}
public double getX()
{
return this.x;
}
public double getY()
{
return this.y;
}
public double getRadius()
{
double rad = Math.sqrt(Math.pow(this.getX(), 2) + Math.pow(this.getY(), 2));
return rad;
}
public double getAngle()
{
double angle = Math.atan2(this.getY(),this.getX());
return angle;
}
public Point rotate90()
{
//Help here PLEASE!
return new Point(-y, x); //THis does not work b/c it only can rotate it once and is for 45 degree angle points
}
}
Explanation / Answer
import java.lang.*; class Point { private final double x; private final double y; public Point(double x, double y) { this.x =x; this.y = y; } public double getX() { return this.x; } public double getY() { return this.y; } public double getRadius() { double rad = Math.sqrt(Math.pow(this.getX(), 2) + Math.pow(this.getY(), 2)); return rad; } public double getAngle() { double angle = Math.atan2(this.getY(),this.getX()); return angle; } public Point rotate90() { //Help here PLEASE! //This is clock wise 90 degree rotation return new Point(y, -x); //THis does not work b/c it only can rotate it once and is for 45 degree angle points } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.