Created
April 22, 2015 19:56
-
-
Save ilyeshammadi/6eda9c09ae4bb3979e83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.awt.*; | |
import static java.lang.Math.*; | |
/** | |
* Created by Ilyes Hammadi on 22/04/2015. | |
*/ | |
public class Cercle { | |
Point centre; | |
float rayon; | |
// constructor | |
public Cercle() { | |
this.centre.setLocation(0, 0); | |
this.rayon = 0; | |
} | |
public Cercle(Point centre, float rayon) { | |
this.centre = centre; | |
this.rayon = rayon; | |
} | |
public Cercle(Cercle cercle){ | |
this.centre = cercle.centre; | |
this.rayon = cercle.rayon; | |
} | |
// setters | |
public void setCentre(Point centre) { | |
this.centre = centre; | |
} | |
public void setRayon(float rayon) { | |
this.rayon = rayon; | |
} | |
// getters | |
public Point getCentre() { | |
return centre; | |
} | |
public float getRayon() { | |
return rayon; | |
} | |
// methods | |
public boolean isColision(Cercle cercle) { | |
return pow(this.centre.getX() - cercle.centre.getX(), 2) + pow(this.centre.getY() - cercle.centre.getY(), 2) < pow(this.rayon + cercle.rayon, 2); | |
} | |
// static methods | |
public static boolean isColision(Cercle c1, Cercle c2) { | |
return pow(c1.centre.getX() - c2.centre.getX(), 2) + pow(c1.centre.getY() - c2.centre.getY(), 2) < pow(c1.rayon + c2.rayon, 2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment