Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.geometry.Point2D;
- public class Kreis {
- public static void main(String[] Args) {
- double m1x = 3;
- double m1y = 5;
- double r1 = 5;
- double m2x = -1;
- double m2y = 1;
- double r2 = 1;
- Point2D[] s = berechneSchnittpunkt(m1x, m1y, r1, m2x, m2y, r2);
- for (int i = 0; i < s.length; i++) {
- System.out.println(s[i]);
- }
- }
- private static Point2D[] berechneSchnittpunkt( double m1x, double m1y, double r1, double m2x, double m2y, double r2){
- double dx = m1x - m2x;
- double dy = m1y - m2y;
- double d = Math.sqrt(dx*dx + dy*dy);
- System.out.println("Abstand: " + d);
- double q = (r1 * r1 - r2 * r2 - d*d) / (-2*d);
- System.out.println("q= " + q);
- double h2 = r2*r2 - q*q;
- if(h2>= 0){
- double h = Math.sqrt(h2);
- double fx = m2x + q*dx/d;
- double fy = m2y + q*dy/d;
- double s1x = fx - h * dy / d;
- double s1y = fy + h * dx / d;
- double s2x = fx + h * dy / d;
- double s2y = fy - h * dx / d;
- if(h2==0){
- return new Point2D[]{new Point2D(s1x, s1y)};
- }
- return new Point2D[]{new Point2D(s1x, s1y), new Point2D(s2x, s2y)};
- }
- return new Point2D[0];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement