1 Replies - 117 Views - Last Post: 06 December 2017 - 04:37 AM Rate Topic: -----

#1 cbellew22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-November 17

Need help with circles

Posted 05 December 2017 - 08:58 PM

Alright so what I am supposed to do is check and see if a circle overlaps another one and make it red if it does. I am having trouble finding out if they overlap. What I think I should be doing is checking to see if the radius is bigger than the distances between the two circles... here is my code
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
import java.util.ArrayList;

public class ShowCirclesOverlapping extends Application {
   private final int MAX_RADIUS = 20;
   private final int MIN_RADIUS = 5;
   private final int PANE_SIZE = 500;
   int i = 0;
   @Override // Override the start method in the Application class
   public void start(Stage primaryStage) {
      // Create a pane to hold the circle 
      Pane pane = new Pane();
      
   
      ArrayList<OutlineCircle> dots = new ArrayList<>();
     // create 20 circles add to the arraylist dots
     for (i=0; i < 20; i++) {
         dots.add(getCircle());
         }    
                
     // add code here to color circles outline to red if it overlaps a circle   
     
         
      // add circles to pane
      for(OutlineCircle c:dots)
         pane.getChildren().add(c);
      
      
      // Create a scene and place it in the stage
      Scene scene = new Scene(pane, PANE_SIZE, PANE_SIZE);
      primaryStage.setTitle("ShowCircles"); // Set the stage title
      primaryStage.setScene(scene); // Place the scene in the stage
      primaryStage.show(); // Display the stage
   }
   

   //
   // method to create a circle
   //
   private OutlineCircle getCircle(){
      OutlineCircle aCircle = new OutlineCircle();
      // set radius to a random size between MIN_RADIUS and MAX_RADIUS
      int radius = (int)(Math.random()*(MAX_RADIUS-MIN_RADIUS))+MIN_RADIUS;
      // set circle in a random place on the pane
      aCircle.setCenterX((int)(Math.random()*PANE_SIZE));
      aCircle.setCenterY((int)(Math.random()*PANE_SIZE));
      aCircle.setRadius(radius);            
      return aCircle;
      }
}


import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;

public class OutlineCircle extends Circle{

   public OutlineCircle(){
   
   super.setFill(Color.TRANSPARENT);
   super.setStroke(Color.GREEN);
   }
   
   
   public boolean overlaps(OutlineCircle c){
      boolean result = false;
      
      for (i=0; dots.length-1; i++){
         if (getCenterX() != getCenterX()){
            (circle.getRadius() + circle.getRadius() < circle.getCenterX());
            }
            
         if (getCenterY() != getCenterY()){
            (circle.getRadius() + Circle.getRadius() < circle.getCenterY());
            }
      
      
      return result;
   }
  }
}


Please help,
thanks

I also forgot to mention that the errors are coming from lines 74-81. These are in separate file too

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with circles

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3486
  • View blog
  • Posts: 15,763
  • Joined: 20-September 08

Re: Need help with circles

Posted 06 December 2017 - 04:37 AM

Have a look at this: https://stackoverflo...in-the-same-pla

In future please post each compilation unit in its OWN code tags
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1