Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int planeX, planeY;
- int radius;
- void setup() {
- size(640, 400);
- planeX = 320;
- planeY = 200;
- radius = 250;
- }
- void draw() {
- background(150, 150, 220);
- noFill();
- rectMode(CENTER);
- //Kreis um mouse und plane berechnen
- int kreisRadius = getDistance(mouseX, mouseY, planeX, planeY) * 2;
- int kreisMitteX = (mouseX + planeX) / 2;
- int kreisMitteY = (mouseY + planeY) / 2;
- ellipse(kreisMitteX, kreisMitteY, kreisRadius - (kreisRadius / 2), kreisRadius - (kreisRadius / 2));
- ellipse(mouseX, mouseY, radius - (radius/ 2), radius - (radius/ 2));
- //Punkte z1 und z2 berechnen
- int z1x, z1y;
- int z2x, z2y;
- //http://stackoverflow.com/questions/3349125/circle-circle-intersection-points
- int a = (pow(radius, 2) - pow(kreisRadius, 2) - pow(kreisRadius / 2, 2)) / kreisRadius;
- //int p2x = mouseX + a * (mouseX - planeX) / (kreisRadius);
- //int p2y = mouseY + a * (mouseY - planeY) / (kreisRadius);
- p2x = kreisMitteX;
- p2y = kreisMitteY;
- ellipse(p2x, p2y, 10, 10);
- int h = sqrt(pow(radius, 2) + pow(a, 2));
- z1x = p2x + h * (mouseY - planeY) / (kreisRadius / 2);
- z1y = p2y - h * (mouseX - planeX) / (kreisRadius / 2);
- z2x = p2x - h * (mouseY - planeY) / (kreisRadius / 2);
- z2y = p2y + h * (mouseX - planeX) / (kreisRadius / 2);
- ellipse(z1x, z1y, 10, 10);
- ellipse(z2x, z2y, 10, 10);
- fill(255, 255, 255);
- ellipse(mouseX, mouseY, 20, 20);
- rect(planeX, planeY, 20, 20);
- }
- int getDistance(int x1, int y1, int x2, int y2) {
- return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement