Advertisement
Guest User

Untitled

a guest
Jul 4th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. int planeX, planeY;
  2. int radius;
  3.  
  4. void setup() {
  5.   size(640, 400);
  6.  
  7.   planeX = 320;
  8.   planeY = 200;
  9.  
  10.   radius = 250;
  11. }
  12.  
  13. void draw() {
  14.   background(150, 150, 220);
  15.  
  16.   noFill();
  17.  
  18.   rectMode(CENTER);
  19.  
  20.   //Kreis um mouse und plane berechnen
  21.   int kreisRadius = getDistance(mouseX, mouseY, planeX, planeY) * 2;
  22.   int kreisMitteX = (mouseX + planeX) / 2;
  23.   int kreisMitteY = (mouseY + planeY) / 2;  
  24.  
  25.   ellipse(kreisMitteX, kreisMitteY, kreisRadius - (kreisRadius / 2), kreisRadius - (kreisRadius / 2));
  26.  
  27.   ellipse(mouseX, mouseY, radius - (radius/ 2), radius - (radius/ 2));
  28.  
  29.   //Punkte z1 und z2 berechnen
  30.   int z1x, z1y;
  31.   int z2x, z2y;
  32.  
  33.   //http://stackoverflow.com/questions/3349125/circle-circle-intersection-points
  34.   int a = (pow(radius, 2) - pow(kreisRadius, 2) - pow(kreisRadius / 2, 2)) / kreisRadius;
  35.  
  36.   //int p2x = mouseX + a * (mouseX - planeX) / (kreisRadius);
  37.   //int p2y = mouseY + a * (mouseY - planeY) / (kreisRadius);
  38.  
  39.   p2x = kreisMitteX;
  40.   p2y = kreisMitteY;
  41.  
  42.   ellipse(p2x, p2y, 10, 10);
  43.  
  44.   int h = sqrt(pow(radius, 2) + pow(a, 2));
  45.  
  46.   z1x = p2x + h * (mouseY - planeY) / (kreisRadius / 2);
  47.   z1y = p2y - h * (mouseX - planeX) / (kreisRadius / 2);
  48.  
  49.   z2x = p2x - h * (mouseY - planeY) / (kreisRadius / 2);
  50.   z2y = p2y + h * (mouseX - planeX) / (kreisRadius / 2);
  51.  
  52.   ellipse(z1x, z1y, 10, 10);
  53.  
  54.   ellipse(z2x, z2y, 10, 10);
  55.  
  56.   fill(255, 255, 255);
  57.  
  58.   ellipse(mouseX, mouseY, 20, 20);
  59.  
  60.   rect(planeX,  planeY,  20,  20);
  61. }
  62.  
  63. int getDistance(int x1, int y1, int x2, int y2) {
  64.   return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement