SlideShare a Scribd company logo
1 of 8
Download to read offline
Create a java project that:
- Draw a circle with three random initial points on the circle.
- Link the points to form a triangle.
- Print the angles values in the triangle.
- Use the mouse to drag a point along the perimeter of the circle. As you drag it, the triangle and
angles are redisplayed dynamically.
Here is the formula to compute angles:
A = acos((a * a - b * b - c * c) / (-2 * b * c))
B = acos((b * b - a * a - c * c) / (-2 * a * c))
C = acos((c * c - b * b - a * a) / (-2 * a * b))
Solution
@Suppresswarnings("WeakerAccess")
public class DragPoints extends Application {
@Override
public void start(Stage primaryStage) {
final PointPane pane = new PointPane(640, 480);
pane.setStyle("-fx-background-color: wheat;");
Label label = new Label("Click and drag the points.");
BorderPane borderPane = new BorderPane(pane);
BorderPane.setAlignment(label, Pos.CENTER);
label.setPadding(new Insets(5));
borderPane.setBottom(label);
Scene scene = new Scene(borderPane);
primaryStage.setTitle("Exercise15_21");
primaryStage.setScene(scene);
primaryStage.show();
}
private class PointPane extends Pane {
final Circle circle = new Circle();
final Vertex[] v = new Vertex[3];
final int strokeWidth = 2;
final Color circleStroke = Color.GRAY, legStroke = Color.BLACK;
@SuppressWarnings("SameParameterValue")
PointPane(double w, double h) {
this.setPrefSize(w, h);
this.setWidth(w);
this.setHeight(h);
circle.setStroke(circleStroke);
circle.setFill(Color.TRANSPARENT);
circle.setStrokeWidth(strokeWidth);
circle.radiusProperty().bind(this.heightProperty().multiply(0.4));
circle.centerXProperty().bind(this.widthProperty().divide(2));
circle.centerYProperty().bind(this.heightProperty().divide(2));
this.getChildren().add(circle);
for (int i = 0; i < v.length; i++) {
v[i] = new Vertex(circle, 2 * Math.PI / v.length * (i + Math.random()));
v[i].radiusProperty().bind(circle.radiusProperty().divide(10));
v[i].setPosition();
v[i].setStroke(new Color(i == 0 ? 1 : 0, i == 1 ? 1 : 0, i == 2 ? 1 : 0, 1));
v[i].setFill(Color.TRANSPARENT);
v[i].setStrokeWidth(strokeWidth);
this.getChildren().add(v[i]);
v[i].setOnMouseDragged(new EventHandler() {
@Override
public void handle(MouseEvent event) {
int i;
for (i = 0; i < v.length; i++)
if (v[i] == event.getSource())
break;
v[i].setAngle(event.getX(), event.getY());
moveUpdate((Vertex) event.getSource());
}
});
}
for (int i = 0; i < v.length; i++) {
int j = i + 1 < v.length ? i + 1 : 0;
int k = j + 1 < v.length ? j + 1 : 0;
v[i].bindLeg(v[j], v[k]);
v[i].leg.setStroke(legStroke);
v[i].leg.setStrokeWidth(strokeWidth);
this.getChildren().add(v[i].leg);
this.getChildren().add(v[i].text);
}
for(DoubleProperty p: new DoubleProperty[]
{circle.radiusProperty(), circle.centerXProperty(), circle.centerYProperty()})
p.addListener(new ResizeListener());
moveUpdate(v[0]);
}
void moveUpdate(Vertex vert) {
vert.setPosition();
double[] legLength = new double[3];
for (int i = 0; i < v.length; i++)
legLength[i] = v[i].getLegLength();
for (int i = 0; i < v.length; i++) {
int j = i + 1 < v.length ? i + 1 : 0;
int k = j + 1 < v.length ? j + 1 : 0;
double a = legLength[i], b = legLength[j], c = legLength[k];
double d = Math.toDegrees(Math.acos((a * a - b * b - c * c) / (-2 * b * c)));
v[i].setText(d);
}
}
private class ResizeListener implements ChangeListener {
@Override
public void changed(ObservableValue observableValue, Number oldWidth, Number
newWidth) {
for (Vertex aV : v) {
aV.setPosition();
}
}
}
}
private class Vertex extends Circle {
final Circle circle;
final Line leg;
final Text text;
double centerAngle;
Vertex(Circle circle, double centerAngle) {
this.circle = circle;
this.setAngle(centerAngle);
this.leg = new Line();
this.text = new Text();
this.text.setFont(Font.font(20));
this.text.setStroke(Color.BLACK);
this.text.setTextAlignment(TextAlignment.CENTER);
this.text.xProperty().bind(this.centerXProperty().add(25));
this.text.yProperty().bind(this.centerYProperty().subtract(10));
}
double getCenterAngle() {return this.centerAngle;}
void setPosition() {
this.setCenterX(circle.getCenterX() + circle.getRadius() *
Math.cos(this.getCenterAngle()));
this.setCenterY(circle.getCenterY() + circle.getRadius() *
Math.sin(this.getCenterAngle()));
}
void setAngle(double centerAngle) {
this.centerAngle = centerAngle;
}
void setAngle(double x, double y) {
this.setAngle(Math.atan2(y - circle.getCenterY(), x - circle.getCenterX()));
}
void bindLeg(Vertex v1, Vertex v2) {
leg.startXProperty().bind(v1.centerXProperty());
leg.startYProperty().bind(v1.centerYProperty());
leg.endXProperty().bind(v2.centerXProperty());
leg.endYProperty().bind(v2.centerYProperty());
}
double getLegLength() {
return Math.sqrt(Math.pow(leg.getStartX()-leg.getEndX(),2) +
Math.pow(leg.getStartY()-leg.getEndY(),2));
}
void setText(double angle) {
this.text.setText(String.format("%.0fu00B0", angle));
}
}
}
@Suppresswarnings("WeakerAccess")
public class DragPoints extends Application {
@Override
public void start(Stage primaryStage) {
final PointPane pane = new PointPane(640, 480);
pane.setStyle("-fx-background-color: wheat;");
Label label = new Label("Click and drag the points.");
BorderPane borderPane = new BorderPane(pane);
BorderPane.setAlignment(label, Pos.CENTER);
label.setPadding(new Insets(5));
borderPane.setBottom(label);
Scene scene = new Scene(borderPane);
primaryStage.setTitle("Exercise15_21");
primaryStage.setScene(scene);
primaryStage.show();
}
private class PointPane extends Pane {
final Circle circle = new Circle();
final Vertex[] v = new Vertex[3];
final int strokeWidth = 2;
final Color circleStroke = Color.GRAY, legStroke = Color.BLACK;
@SuppressWarnings("SameParameterValue")
PointPane(double w, double h) {
this.setPrefSize(w, h);
this.setWidth(w);
this.setHeight(h);
circle.setStroke(circleStroke);
circle.setFill(Color.TRANSPARENT);
circle.setStrokeWidth(strokeWidth);
circle.radiusProperty().bind(this.heightProperty().multiply(0.4));
circle.centerXProperty().bind(this.widthProperty().divide(2));
circle.centerYProperty().bind(this.heightProperty().divide(2));
this.getChildren().add(circle);
for (int i = 0; i < v.length; i++) {
v[i] = new Vertex(circle, 2 * Math.PI / v.length * (i + Math.random()));
v[i].radiusProperty().bind(circle.radiusProperty().divide(10));
v[i].setPosition();
v[i].setStroke(new Color(i == 0 ? 1 : 0, i == 1 ? 1 : 0, i == 2 ? 1 : 0, 1));
v[i].setFill(Color.TRANSPARENT);
v[i].setStrokeWidth(strokeWidth);
this.getChildren().add(v[i]);
v[i].setOnMouseDragged(new EventHandler() {
@Override
public void handle(MouseEvent event) {
int i;
for (i = 0; i < v.length; i++)
if (v[i] == event.getSource())
break;
v[i].setAngle(event.getX(), event.getY());
moveUpdate((Vertex) event.getSource());
}
});
}
for (int i = 0; i < v.length; i++) {
int j = i + 1 < v.length ? i + 1 : 0;
int k = j + 1 < v.length ? j + 1 : 0;
v[i].bindLeg(v[j], v[k]);
v[i].leg.setStroke(legStroke);
v[i].leg.setStrokeWidth(strokeWidth);
this.getChildren().add(v[i].leg);
this.getChildren().add(v[i].text);
}
for(DoubleProperty p: new DoubleProperty[]
{circle.radiusProperty(), circle.centerXProperty(), circle.centerYProperty()})
p.addListener(new ResizeListener());
moveUpdate(v[0]);
}
void moveUpdate(Vertex vert) {
vert.setPosition();
double[] legLength = new double[3];
for (int i = 0; i < v.length; i++)
legLength[i] = v[i].getLegLength();
for (int i = 0; i < v.length; i++) {
int j = i + 1 < v.length ? i + 1 : 0;
int k = j + 1 < v.length ? j + 1 : 0;
double a = legLength[i], b = legLength[j], c = legLength[k];
double d = Math.toDegrees(Math.acos((a * a - b * b - c * c) / (-2 * b * c)));
v[i].setText(d);
}
}
private class ResizeListener implements ChangeListener {
@Override
public void changed(ObservableValue observableValue, Number oldWidth, Number
newWidth) {
for (Vertex aV : v) {
aV.setPosition();
}
}
}
}
private class Vertex extends Circle {
final Circle circle;
final Line leg;
final Text text;
double centerAngle;
Vertex(Circle circle, double centerAngle) {
this.circle = circle;
this.setAngle(centerAngle);
this.leg = new Line();
this.text = new Text();
this.text.setFont(Font.font(20));
this.text.setStroke(Color.BLACK);
this.text.setTextAlignment(TextAlignment.CENTER);
this.text.xProperty().bind(this.centerXProperty().add(25));
this.text.yProperty().bind(this.centerYProperty().subtract(10));
}
double getCenterAngle() {return this.centerAngle;}
void setPosition() {
this.setCenterX(circle.getCenterX() + circle.getRadius() *
Math.cos(this.getCenterAngle()));
this.setCenterY(circle.getCenterY() + circle.getRadius() *
Math.sin(this.getCenterAngle()));
}
void setAngle(double centerAngle) {
this.centerAngle = centerAngle;
}
void setAngle(double x, double y) {
this.setAngle(Math.atan2(y - circle.getCenterY(), x - circle.getCenterX()));
}
void bindLeg(Vertex v1, Vertex v2) {
leg.startXProperty().bind(v1.centerXProperty());
leg.startYProperty().bind(v1.centerYProperty());
leg.endXProperty().bind(v2.centerXProperty());
leg.endYProperty().bind(v2.centerYProperty());
}
double getLegLength() {
return Math.sqrt(Math.pow(leg.getStartX()-leg.getEndX(),2) +
Math.pow(leg.getStartY()-leg.getEndY(),2));
}
void setText(double angle) {
this.text.setText(String.format("%.0fu00B0", angle));
}
}
}

More Related Content

Similar to Create a java project that - Draw a circle with three random init.pdf

Creating an Uber Clone - Part IV.pdf
Creating an Uber Clone - Part IV.pdfCreating an Uber Clone - Part IV.pdf
Creating an Uber Clone - Part IV.pdfShaiAlmog1
 
I need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdfI need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdfallurafashions98
 
Please implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdfPlease implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdffms12345
 
How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017Szymon Matejczyk
 
Raspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFXRaspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFXStephen Chin
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bPhilip Schwarz
 
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184Mahmoud Samir Fayed
 
ImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdfImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdfgopalk44
 
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONFun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONTomomi Imura
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For GoogleEleanor McHugh
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)zahid-mian
 
Creating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdfCreating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdfShaiAlmog1
 
Functional Systems @ Twitter
Functional Systems @ TwitterFunctional Systems @ Twitter
Functional Systems @ TwitterC4Media
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++vidyamittal
 
Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01Getachew Ganfur
 

Similar to Create a java project that - Draw a circle with three random init.pdf (20)

662305 11
662305 11662305 11
662305 11
 
Creating an Uber Clone - Part IV.pdf
Creating an Uber Clone - Part IV.pdfCreating an Uber Clone - Part IV.pdf
Creating an Uber Clone - Part IV.pdf
 
I need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdfI need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdf
 
Proga 0622
Proga 0622Proga 0622
Proga 0622
 
Please implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdfPlease implement in Java. comments would be appreciated 5.pdf
Please implement in Java. comments would be appreciated 5.pdf
 
How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017How to extend map? Or why we need collections redesign? - Scalar 2017
How to extend map? Or why we need collections redesign? - Scalar 2017
 
Raspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFXRaspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFX
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
 
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184
 
ImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdfImplementDijkstra’s algorithm using the graph class you implemente.pdf
ImplementDijkstra’s algorithm using the graph class you implemente.pdf
 
662305 LAB13
662305 LAB13662305 LAB13
662305 LAB13
 
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONFun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
 
Introduction to d3js (and SVG)
Introduction to d3js (and SVG)Introduction to d3js (and SVG)
Introduction to d3js (and SVG)
 
Creating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdfCreating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdf
 
Functional Systems @ Twitter
Functional Systems @ TwitterFunctional Systems @ Twitter
Functional Systems @ Twitter
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
 
Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01Cppt 101102014428-phpapp01
Cppt 101102014428-phpapp01
 
Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
 

More from arihantmobileselepun

How are the epimysium and tendons relatedA. The epimysium surroun.pdf
How are the epimysium and tendons relatedA. The epimysium surroun.pdfHow are the epimysium and tendons relatedA. The epimysium surroun.pdf
How are the epimysium and tendons relatedA. The epimysium surroun.pdfarihantmobileselepun
 
How does DNA differ from RNAA. RNA uses only purinesB. RNA uses.pdf
How does DNA differ from RNAA. RNA uses only purinesB. RNA uses.pdfHow does DNA differ from RNAA. RNA uses only purinesB. RNA uses.pdf
How does DNA differ from RNAA. RNA uses only purinesB. RNA uses.pdfarihantmobileselepun
 
Gerard throws a discus distances of 10 meters, 14.5 meters, 14.8 met.pdf
Gerard throws a discus distances of 10 meters, 14.5 meters, 14.8 met.pdfGerard throws a discus distances of 10 meters, 14.5 meters, 14.8 met.pdf
Gerard throws a discus distances of 10 meters, 14.5 meters, 14.8 met.pdfarihantmobileselepun
 
For Printing and personal use ONLY. DO NOT Hand in this copy of the a.pdf
For Printing and personal use ONLY. DO NOT Hand in this copy of the a.pdfFor Printing and personal use ONLY. DO NOT Hand in this copy of the a.pdf
For Printing and personal use ONLY. DO NOT Hand in this copy of the a.pdfarihantmobileselepun
 
Find and provide a link to a multi-year capital plan from any Illino.pdf
Find and provide a link to a multi-year capital plan from any Illino.pdfFind and provide a link to a multi-year capital plan from any Illino.pdf
Find and provide a link to a multi-year capital plan from any Illino.pdfarihantmobileselepun
 
A geneticist is working with a new bacteriophage called phage Y3 that.pdf
A geneticist is working with a new bacteriophage called phage Y3 that.pdfA geneticist is working with a new bacteriophage called phage Y3 that.pdf
A geneticist is working with a new bacteriophage called phage Y3 that.pdfarihantmobileselepun
 
Assume that the four living species in the figure below evolved from.pdf
Assume that the four living species in the figure below evolved from.pdfAssume that the four living species in the figure below evolved from.pdf
Assume that the four living species in the figure below evolved from.pdfarihantmobileselepun
 
Declining BalanceThe cost of the asset $10,000.00 The salvage v.pdf
Declining BalanceThe cost of the asset $10,000.00 The salvage v.pdfDeclining BalanceThe cost of the asset $10,000.00 The salvage v.pdf
Declining BalanceThe cost of the asset $10,000.00 The salvage v.pdfarihantmobileselepun
 
aphase The spindle contracts and the sister chromatids are separated.pdf
aphase The spindle contracts and the sister chromatids are separated.pdfaphase The spindle contracts and the sister chromatids are separated.pdf
aphase The spindle contracts and the sister chromatids are separated.pdfarihantmobileselepun
 
A population of wild deer mice includes individuals with long or sho.pdf
A population of wild deer mice includes individuals with long or sho.pdfA population of wild deer mice includes individuals with long or sho.pdf
A population of wild deer mice includes individuals with long or sho.pdfarihantmobileselepun
 
Who is it important that the lymphatic system operate separately f.pdf
Who is it important that the lymphatic system operate separately f.pdfWho is it important that the lymphatic system operate separately f.pdf
Who is it important that the lymphatic system operate separately f.pdfarihantmobileselepun
 
Provide a full explanation to the below question.1. Summarize the .pdf
Provide a full explanation to the below question.1. Summarize the .pdfProvide a full explanation to the below question.1. Summarize the .pdf
Provide a full explanation to the below question.1. Summarize the .pdfarihantmobileselepun
 
Write a program to generate the entire calendar for one year. The pr.pdf
Write a program to generate the entire calendar for one year. The pr.pdfWrite a program to generate the entire calendar for one year. The pr.pdf
Write a program to generate the entire calendar for one year. The pr.pdfarihantmobileselepun
 
Write the interval notation for the set of numbers graphed. Solu.pdf
Write the interval notation for the set of numbers graphed.  Solu.pdfWrite the interval notation for the set of numbers graphed.  Solu.pdf
Write the interval notation for the set of numbers graphed. Solu.pdfarihantmobileselepun
 
Hyenas are diploid organisms, and their gametes contain 20 chromosome.pdf
Hyenas are diploid organisms, and their gametes contain 20 chromosome.pdfHyenas are diploid organisms, and their gametes contain 20 chromosome.pdf
Hyenas are diploid organisms, and their gametes contain 20 chromosome.pdfarihantmobileselepun
 
Why doesnt hemoglobin have any intermediate conformations between .pdf
Why doesnt hemoglobin have any intermediate conformations between .pdfWhy doesnt hemoglobin have any intermediate conformations between .pdf
Why doesnt hemoglobin have any intermediate conformations between .pdfarihantmobileselepun
 
4. What is gyanandromorphy How does this happenSolutionAnswe.pdf
4. What is gyanandromorphy How does this happenSolutionAnswe.pdf4. What is gyanandromorphy How does this happenSolutionAnswe.pdf
4. What is gyanandromorphy How does this happenSolutionAnswe.pdfarihantmobileselepun
 
Which of the following requires the mitochondria to create contact po.pdf
Which of the following requires the mitochondria to create contact po.pdfWhich of the following requires the mitochondria to create contact po.pdf
Which of the following requires the mitochondria to create contact po.pdfarihantmobileselepun
 
why nitrogen fixation is so importantSolutionNitrogen fixation.pdf
why nitrogen fixation is so importantSolutionNitrogen fixation.pdfwhy nitrogen fixation is so importantSolutionNitrogen fixation.pdf
why nitrogen fixation is so importantSolutionNitrogen fixation.pdfarihantmobileselepun
 
what will happen to the photon if two photons enter the same atom si.pdf
what will happen to the photon if two photons enter the same atom si.pdfwhat will happen to the photon if two photons enter the same atom si.pdf
what will happen to the photon if two photons enter the same atom si.pdfarihantmobileselepun
 

More from arihantmobileselepun (20)

How are the epimysium and tendons relatedA. The epimysium surroun.pdf
How are the epimysium and tendons relatedA. The epimysium surroun.pdfHow are the epimysium and tendons relatedA. The epimysium surroun.pdf
How are the epimysium and tendons relatedA. The epimysium surroun.pdf
 
How does DNA differ from RNAA. RNA uses only purinesB. RNA uses.pdf
How does DNA differ from RNAA. RNA uses only purinesB. RNA uses.pdfHow does DNA differ from RNAA. RNA uses only purinesB. RNA uses.pdf
How does DNA differ from RNAA. RNA uses only purinesB. RNA uses.pdf
 
Gerard throws a discus distances of 10 meters, 14.5 meters, 14.8 met.pdf
Gerard throws a discus distances of 10 meters, 14.5 meters, 14.8 met.pdfGerard throws a discus distances of 10 meters, 14.5 meters, 14.8 met.pdf
Gerard throws a discus distances of 10 meters, 14.5 meters, 14.8 met.pdf
 
For Printing and personal use ONLY. DO NOT Hand in this copy of the a.pdf
For Printing and personal use ONLY. DO NOT Hand in this copy of the a.pdfFor Printing and personal use ONLY. DO NOT Hand in this copy of the a.pdf
For Printing and personal use ONLY. DO NOT Hand in this copy of the a.pdf
 
Find and provide a link to a multi-year capital plan from any Illino.pdf
Find and provide a link to a multi-year capital plan from any Illino.pdfFind and provide a link to a multi-year capital plan from any Illino.pdf
Find and provide a link to a multi-year capital plan from any Illino.pdf
 
A geneticist is working with a new bacteriophage called phage Y3 that.pdf
A geneticist is working with a new bacteriophage called phage Y3 that.pdfA geneticist is working with a new bacteriophage called phage Y3 that.pdf
A geneticist is working with a new bacteriophage called phage Y3 that.pdf
 
Assume that the four living species in the figure below evolved from.pdf
Assume that the four living species in the figure below evolved from.pdfAssume that the four living species in the figure below evolved from.pdf
Assume that the four living species in the figure below evolved from.pdf
 
Declining BalanceThe cost of the asset $10,000.00 The salvage v.pdf
Declining BalanceThe cost of the asset $10,000.00 The salvage v.pdfDeclining BalanceThe cost of the asset $10,000.00 The salvage v.pdf
Declining BalanceThe cost of the asset $10,000.00 The salvage v.pdf
 
aphase The spindle contracts and the sister chromatids are separated.pdf
aphase The spindle contracts and the sister chromatids are separated.pdfaphase The spindle contracts and the sister chromatids are separated.pdf
aphase The spindle contracts and the sister chromatids are separated.pdf
 
A population of wild deer mice includes individuals with long or sho.pdf
A population of wild deer mice includes individuals with long or sho.pdfA population of wild deer mice includes individuals with long or sho.pdf
A population of wild deer mice includes individuals with long or sho.pdf
 
Who is it important that the lymphatic system operate separately f.pdf
Who is it important that the lymphatic system operate separately f.pdfWho is it important that the lymphatic system operate separately f.pdf
Who is it important that the lymphatic system operate separately f.pdf
 
Provide a full explanation to the below question.1. Summarize the .pdf
Provide a full explanation to the below question.1. Summarize the .pdfProvide a full explanation to the below question.1. Summarize the .pdf
Provide a full explanation to the below question.1. Summarize the .pdf
 
Write a program to generate the entire calendar for one year. The pr.pdf
Write a program to generate the entire calendar for one year. The pr.pdfWrite a program to generate the entire calendar for one year. The pr.pdf
Write a program to generate the entire calendar for one year. The pr.pdf
 
Write the interval notation for the set of numbers graphed. Solu.pdf
Write the interval notation for the set of numbers graphed.  Solu.pdfWrite the interval notation for the set of numbers graphed.  Solu.pdf
Write the interval notation for the set of numbers graphed. Solu.pdf
 
Hyenas are diploid organisms, and their gametes contain 20 chromosome.pdf
Hyenas are diploid organisms, and their gametes contain 20 chromosome.pdfHyenas are diploid organisms, and their gametes contain 20 chromosome.pdf
Hyenas are diploid organisms, and their gametes contain 20 chromosome.pdf
 
Why doesnt hemoglobin have any intermediate conformations between .pdf
Why doesnt hemoglobin have any intermediate conformations between .pdfWhy doesnt hemoglobin have any intermediate conformations between .pdf
Why doesnt hemoglobin have any intermediate conformations between .pdf
 
4. What is gyanandromorphy How does this happenSolutionAnswe.pdf
4. What is gyanandromorphy How does this happenSolutionAnswe.pdf4. What is gyanandromorphy How does this happenSolutionAnswe.pdf
4. What is gyanandromorphy How does this happenSolutionAnswe.pdf
 
Which of the following requires the mitochondria to create contact po.pdf
Which of the following requires the mitochondria to create contact po.pdfWhich of the following requires the mitochondria to create contact po.pdf
Which of the following requires the mitochondria to create contact po.pdf
 
why nitrogen fixation is so importantSolutionNitrogen fixation.pdf
why nitrogen fixation is so importantSolutionNitrogen fixation.pdfwhy nitrogen fixation is so importantSolutionNitrogen fixation.pdf
why nitrogen fixation is so importantSolutionNitrogen fixation.pdf
 
what will happen to the photon if two photons enter the same atom si.pdf
what will happen to the photon if two photons enter the same atom si.pdfwhat will happen to the photon if two photons enter the same atom si.pdf
what will happen to the photon if two photons enter the same atom si.pdf
 

Recently uploaded

Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 

Recently uploaded (20)

Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 

Create a java project that - Draw a circle with three random init.pdf

  • 1. Create a java project that: - Draw a circle with three random initial points on the circle. - Link the points to form a triangle. - Print the angles values in the triangle. - Use the mouse to drag a point along the perimeter of the circle. As you drag it, the triangle and angles are redisplayed dynamically. Here is the formula to compute angles: A = acos((a * a - b * b - c * c) / (-2 * b * c)) B = acos((b * b - a * a - c * c) / (-2 * a * c)) C = acos((c * c - b * b - a * a) / (-2 * a * b)) Solution @Suppresswarnings("WeakerAccess") public class DragPoints extends Application { @Override public void start(Stage primaryStage) { final PointPane pane = new PointPane(640, 480); pane.setStyle("-fx-background-color: wheat;"); Label label = new Label("Click and drag the points."); BorderPane borderPane = new BorderPane(pane); BorderPane.setAlignment(label, Pos.CENTER); label.setPadding(new Insets(5)); borderPane.setBottom(label); Scene scene = new Scene(borderPane); primaryStage.setTitle("Exercise15_21"); primaryStage.setScene(scene); primaryStage.show(); } private class PointPane extends Pane { final Circle circle = new Circle(); final Vertex[] v = new Vertex[3]; final int strokeWidth = 2; final Color circleStroke = Color.GRAY, legStroke = Color.BLACK; @SuppressWarnings("SameParameterValue")
  • 2. PointPane(double w, double h) { this.setPrefSize(w, h); this.setWidth(w); this.setHeight(h); circle.setStroke(circleStroke); circle.setFill(Color.TRANSPARENT); circle.setStrokeWidth(strokeWidth); circle.radiusProperty().bind(this.heightProperty().multiply(0.4)); circle.centerXProperty().bind(this.widthProperty().divide(2)); circle.centerYProperty().bind(this.heightProperty().divide(2)); this.getChildren().add(circle); for (int i = 0; i < v.length; i++) { v[i] = new Vertex(circle, 2 * Math.PI / v.length * (i + Math.random())); v[i].radiusProperty().bind(circle.radiusProperty().divide(10)); v[i].setPosition(); v[i].setStroke(new Color(i == 0 ? 1 : 0, i == 1 ? 1 : 0, i == 2 ? 1 : 0, 1)); v[i].setFill(Color.TRANSPARENT); v[i].setStrokeWidth(strokeWidth); this.getChildren().add(v[i]); v[i].setOnMouseDragged(new EventHandler() { @Override public void handle(MouseEvent event) { int i; for (i = 0; i < v.length; i++) if (v[i] == event.getSource()) break; v[i].setAngle(event.getX(), event.getY()); moveUpdate((Vertex) event.getSource()); } }); } for (int i = 0; i < v.length; i++) { int j = i + 1 < v.length ? i + 1 : 0; int k = j + 1 < v.length ? j + 1 : 0; v[i].bindLeg(v[j], v[k]); v[i].leg.setStroke(legStroke);
  • 3. v[i].leg.setStrokeWidth(strokeWidth); this.getChildren().add(v[i].leg); this.getChildren().add(v[i].text); } for(DoubleProperty p: new DoubleProperty[] {circle.radiusProperty(), circle.centerXProperty(), circle.centerYProperty()}) p.addListener(new ResizeListener()); moveUpdate(v[0]); } void moveUpdate(Vertex vert) { vert.setPosition(); double[] legLength = new double[3]; for (int i = 0; i < v.length; i++) legLength[i] = v[i].getLegLength(); for (int i = 0; i < v.length; i++) { int j = i + 1 < v.length ? i + 1 : 0; int k = j + 1 < v.length ? j + 1 : 0; double a = legLength[i], b = legLength[j], c = legLength[k]; double d = Math.toDegrees(Math.acos((a * a - b * b - c * c) / (-2 * b * c))); v[i].setText(d); } } private class ResizeListener implements ChangeListener { @Override public void changed(ObservableValue observableValue, Number oldWidth, Number newWidth) { for (Vertex aV : v) { aV.setPosition(); } } } } private class Vertex extends Circle { final Circle circle; final Line leg;
  • 4. final Text text; double centerAngle; Vertex(Circle circle, double centerAngle) { this.circle = circle; this.setAngle(centerAngle); this.leg = new Line(); this.text = new Text(); this.text.setFont(Font.font(20)); this.text.setStroke(Color.BLACK); this.text.setTextAlignment(TextAlignment.CENTER); this.text.xProperty().bind(this.centerXProperty().add(25)); this.text.yProperty().bind(this.centerYProperty().subtract(10)); } double getCenterAngle() {return this.centerAngle;} void setPosition() { this.setCenterX(circle.getCenterX() + circle.getRadius() * Math.cos(this.getCenterAngle())); this.setCenterY(circle.getCenterY() + circle.getRadius() * Math.sin(this.getCenterAngle())); } void setAngle(double centerAngle) { this.centerAngle = centerAngle; } void setAngle(double x, double y) { this.setAngle(Math.atan2(y - circle.getCenterY(), x - circle.getCenterX())); } void bindLeg(Vertex v1, Vertex v2) { leg.startXProperty().bind(v1.centerXProperty()); leg.startYProperty().bind(v1.centerYProperty()); leg.endXProperty().bind(v2.centerXProperty()); leg.endYProperty().bind(v2.centerYProperty()); } double getLegLength() { return Math.sqrt(Math.pow(leg.getStartX()-leg.getEndX(),2) + Math.pow(leg.getStartY()-leg.getEndY(),2)); }
  • 5. void setText(double angle) { this.text.setText(String.format("%.0fu00B0", angle)); } } } @Suppresswarnings("WeakerAccess") public class DragPoints extends Application { @Override public void start(Stage primaryStage) { final PointPane pane = new PointPane(640, 480); pane.setStyle("-fx-background-color: wheat;"); Label label = new Label("Click and drag the points."); BorderPane borderPane = new BorderPane(pane); BorderPane.setAlignment(label, Pos.CENTER); label.setPadding(new Insets(5)); borderPane.setBottom(label); Scene scene = new Scene(borderPane); primaryStage.setTitle("Exercise15_21"); primaryStage.setScene(scene); primaryStage.show(); } private class PointPane extends Pane { final Circle circle = new Circle(); final Vertex[] v = new Vertex[3]; final int strokeWidth = 2; final Color circleStroke = Color.GRAY, legStroke = Color.BLACK; @SuppressWarnings("SameParameterValue") PointPane(double w, double h) { this.setPrefSize(w, h); this.setWidth(w); this.setHeight(h); circle.setStroke(circleStroke); circle.setFill(Color.TRANSPARENT); circle.setStrokeWidth(strokeWidth); circle.radiusProperty().bind(this.heightProperty().multiply(0.4)); circle.centerXProperty().bind(this.widthProperty().divide(2));
  • 6. circle.centerYProperty().bind(this.heightProperty().divide(2)); this.getChildren().add(circle); for (int i = 0; i < v.length; i++) { v[i] = new Vertex(circle, 2 * Math.PI / v.length * (i + Math.random())); v[i].radiusProperty().bind(circle.radiusProperty().divide(10)); v[i].setPosition(); v[i].setStroke(new Color(i == 0 ? 1 : 0, i == 1 ? 1 : 0, i == 2 ? 1 : 0, 1)); v[i].setFill(Color.TRANSPARENT); v[i].setStrokeWidth(strokeWidth); this.getChildren().add(v[i]); v[i].setOnMouseDragged(new EventHandler() { @Override public void handle(MouseEvent event) { int i; for (i = 0; i < v.length; i++) if (v[i] == event.getSource()) break; v[i].setAngle(event.getX(), event.getY()); moveUpdate((Vertex) event.getSource()); } }); } for (int i = 0; i < v.length; i++) { int j = i + 1 < v.length ? i + 1 : 0; int k = j + 1 < v.length ? j + 1 : 0; v[i].bindLeg(v[j], v[k]); v[i].leg.setStroke(legStroke); v[i].leg.setStrokeWidth(strokeWidth); this.getChildren().add(v[i].leg); this.getChildren().add(v[i].text); } for(DoubleProperty p: new DoubleProperty[] {circle.radiusProperty(), circle.centerXProperty(), circle.centerYProperty()}) p.addListener(new ResizeListener()); moveUpdate(v[0]);
  • 7. } void moveUpdate(Vertex vert) { vert.setPosition(); double[] legLength = new double[3]; for (int i = 0; i < v.length; i++) legLength[i] = v[i].getLegLength(); for (int i = 0; i < v.length; i++) { int j = i + 1 < v.length ? i + 1 : 0; int k = j + 1 < v.length ? j + 1 : 0; double a = legLength[i], b = legLength[j], c = legLength[k]; double d = Math.toDegrees(Math.acos((a * a - b * b - c * c) / (-2 * b * c))); v[i].setText(d); } } private class ResizeListener implements ChangeListener { @Override public void changed(ObservableValue observableValue, Number oldWidth, Number newWidth) { for (Vertex aV : v) { aV.setPosition(); } } } } private class Vertex extends Circle { final Circle circle; final Line leg; final Text text; double centerAngle; Vertex(Circle circle, double centerAngle) { this.circle = circle; this.setAngle(centerAngle); this.leg = new Line(); this.text = new Text(); this.text.setFont(Font.font(20)); this.text.setStroke(Color.BLACK);
  • 8. this.text.setTextAlignment(TextAlignment.CENTER); this.text.xProperty().bind(this.centerXProperty().add(25)); this.text.yProperty().bind(this.centerYProperty().subtract(10)); } double getCenterAngle() {return this.centerAngle;} void setPosition() { this.setCenterX(circle.getCenterX() + circle.getRadius() * Math.cos(this.getCenterAngle())); this.setCenterY(circle.getCenterY() + circle.getRadius() * Math.sin(this.getCenterAngle())); } void setAngle(double centerAngle) { this.centerAngle = centerAngle; } void setAngle(double x, double y) { this.setAngle(Math.atan2(y - circle.getCenterY(), x - circle.getCenterX())); } void bindLeg(Vertex v1, Vertex v2) { leg.startXProperty().bind(v1.centerXProperty()); leg.startYProperty().bind(v1.centerYProperty()); leg.endXProperty().bind(v2.centerXProperty()); leg.endYProperty().bind(v2.centerYProperty()); } double getLegLength() { return Math.sqrt(Math.pow(leg.getStartX()-leg.getEndX(),2) + Math.pow(leg.getStartY()-leg.getEndY(),2)); } void setText(double angle) { this.text.setText(String.format("%.0fu00B0", angle)); } } }