java - javafx position elements around a central point -


apologies, rubbishy asked question, totally flumped here best approach. believe there must inbuilt or common practice can't find , google has turned nothing of value.

i have javafx scene number of circles.

(named below illustrate effect i'm trying achieve)

circle earth= new circle(30, color.web("blue", 0.5));  circle moon = new circle(30, color.web("blue", 0.5)); circle moon = new circle(30, color.web("blue", 0.5)); circle moon = new circle(30, color.web("blue", 0.5)); 

all positioned:

setcenterx(300);  setcentery(300); 

on 600 600 scene.

i need moon objects placed around earth object. don't care where, long x distance moon , not touching.

i looped through each object, checked collision , using recursive function moved circle +10 on they coord.

this worked seemed doing plot objects on circular path. (looping through each object once object moved looping again check moving of object hadn't had knock on effect)

i have seen loads of tutorials so questions such related question show how plot rectangle on circular path. circle object doesn't seem have same methods.

any on how go appreciated

just position them @ equal angles around center.

pane pane = new pane();  double centerx = 300 ; double centery = 300 ; double radius = 30 ;  circle earth = new circle(centerx, centery, radius, color.web("blue", 0.5)); pane.getchildren().add(earth);  int nummoons = 3 ; double distance = 100 ;  (int = 0 ; < nummoons; i++) {     double angle = 2 * * math.pi / nummoons ;     double xoffset = distance * math.cos(angle);     double yoffset = distance * math.sin(angle);     double x = centerx + xoffset ;     double y = centery + yoffset ;     circle moon = new circle(x, y, radius, color.web("blue", 0.5));     pane.getchildren().add(moon); } 

or, put them @ (centerx + distance, centery) , apply different rotations:

pane pane = new pane();  double centerx = 300 ; double centery = 300 ; double radius = 30 ;  circle earth = new circle(centerx, centery, radius, color.web("blue", 0.5)); pane.getchildren().add(earth);  int nummoons = 3 ; double distance = 100 ;  (int = 0 ; < nummoons; i++) {     double angle = 360.0 * / nummoons ;      circle moon = new circle(centerx + distance, centery, radius, color.web("blue", 0.5));     rotate rotate = new rotate(angle, centerx, centery);     moon.gettransforms().add(rotate);     pane.getchildren().add(moon); } 

or, if want define fixed gap between them, it's not hard show angle increment (in radians) is

incrementangle = 2 * math.asin((2 * moonradius + gap) / (2 * distance) ); 

so can things like

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.transform.rotate; import javafx.stage.stage;  public class circlesaroundcircle extends application {      @override     public void start(stage primarystage) {         pane pane = new pane();          double centerx = 300 ;         double centery = 300 ;         double earthradius = 30 ;         double moonradius = 30 ;          circle earth = new circle(centerx, centery, earthradius, color.web("blue", 0.5));         pane.getchildren().add(earth);          int nummoons = 3 ;         double gap = 10 ;         double distance = 100 ;         double angleincrement = 2 * math.asin((2 * moonradius + gap) / (2  * distance) );          (int = 0 ; < nummoons; i++) {              double angle = math.todegrees(angleincrement * i) ;              circle moon = new circle(centerx + distance, centery, moonradius, color.web("blue", 0.5));             rotate rotate = new rotate(angle, centerx, centery);             moon.gettransforms().add(rotate);             pane.getchildren().add(moon);         }          circle orbit = new circle(centerx, centery, distance, color.transparent);         orbit.setstroke(color.black);         pane.getchildren().add(orbit);          scene scene = new scene(pane, 600, 600);         primarystage.setscene(scene);         primarystage.show();     }      public static void main(string[] args) {         launch(args);     } } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -