Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rectangular {
- double x, y;
- // Constructor
- Rectangular(){
- x = 0;
- y = 0;
- }
- Rectangular(double x, double y){
- this.x = x;
- this.y = y;
- }
- // Convert
- public Polar toPolar(){
- double r = Math.hypot(x, y);
- double argument = Math.atan2(y, x);
- if(x>=0 && y>=0){
- return new Polar(r, argument);
- }
- else if(x>=0 && y<0){
- return new Polar(r, -argument);
- }
- else if(x<0 && y>=0){
- return new Polar(r, Math.PI - argument);
- }
- else {
- return new Polar(r, Math.PI + argument);
- }
- }
- // Methods
- public static Rectangular multiplyRect(Rectangular rect1, Rectangular rect2){
- return new Rectangular(rect1.x*rect2.x - rect1.y*rect2.y, rect1.x*rect2.y + rect1.y*rect2.x);
- }
- public static Rectangular multiplyRectPol(Rectangular rect1, Polar pol2){
- Rectangular rect2 = pol2.toRectangular();
- return new Rectangular(rect1.x*rect2.x - rect1.y*rect2.y, rect1.x*rect2.y + rect1.y*rect2.x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement