Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Polar {
- double r;
- double arg;
- // Constructor
- Polar(){
- r = 0;
- arg = 0;
- }
- Polar(double r, double arg){
- if(r ==0){
- System.out.println("Polar coordinates cannot be defined when x = 0 and y =0.");
- return;
- }
- else{
- this.r = r;
- this.arg = arg;
- }
- }
- // Convert
- public Rectangular toRectangular(){
- return new Rectangular(r * Math.cos(arg), r * Math.sin(arg));
- }
- // Methods
- public static Polar multiplyPol(Polar pol1, Polar pol2){
- return new Polar(pol1.r * pol2.r, pol1.arg + pol2.arg);
- }
- public static Polar multiplyPolRect(Polar pol1, Rectangular rect2){
- Polar pol2 = rect2.toPolar();
- return new Polar(pol1.r * pol2.r, pol1.arg + pol2.arg);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement