Skip to content

Commit db18906

Browse files
committed
Added drawing arc error
1 parent 2f732ac commit db18906

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

resources/input4G02.file

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ G00 X0 Y50
44
G01 X0 Y200
55
G02 X50 Y250 I50 J200
66
G01 X200 Y250
7-
G02 X250 Y200 I200 J200
7+
G02 X250 Y200 I150 J250
88
G01 X250 Y50
99
G02 X200 Y0 I200 J50
1010
G01 X50 Y0

src/GCODECompiler/GCODEHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void printCommand(List<String> listcom) {
162162
data = "";
163163
System.out.print("Movimento-> "+com+" ");
164164
System.out.println(recognizeComm(com));
165-
Graphic.Graphic(listcom);
165+
Graphic.setArray(listcom);
166166
data = "Movimento-> "+com+" " + recognizeComm(com) + "\n";
167167
Interfaccia.setData(data);
168168
}

src/myPackage/Graphic.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package myPackage;
22

3-
import java.awt.BasicStroke;
43
import java.awt.Dimension;
54
import java.awt.Graphics;
6-
import java.awt.Graphics2D;
75
import java.util.ArrayList;
86
import java.util.List;
97

@@ -20,7 +18,7 @@ public Graphic() {
2018
@Override
2119
public void paintComponent(Graphics g) {
2220
// Paint its background
23-
super.paintComponent(g);
21+
//super.paintComponent(g);
2422

2523
int xorigin = 500, yorigin = 500;
2624
int firstx = 0, firsty = 0;
@@ -58,6 +56,13 @@ public void paintComponent(Graphics g) {
5856
float startAngle = (float) (180/Math.PI*Math.atan2(y1-y0, x1-x0));
5957
float endAngle = (float) (180/Math.PI*Math.atan2(y2-y0, x2-x0));
6058

59+
float endDist = (float)Math.sqrt((x2-x0)*(x2-x0) + (y2-y0)*(y2-y0));
60+
float startDist = (float)Math.sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
61+
62+
if(endDist != startDist) {
63+
System.out.println("Il comando -> " + com + " non può collegare il punto: " + x1 + ";" + (500 - y1) + " con il punto " + x2 + ";" + (500 - y2) +".");
64+
}
65+
6166
//System.out.println(x0 + " " + y0 + " " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + r + " " + x + " " + y + " " + width + " " + height + " " + startAngle + " " + endAngle);
6267
if(startAngle - endAngle < 0)
6368
g.drawArc((int)x, (int)y, (int)width, (int)height, (int)(360.0 - startAngle), (int)(startAngle - endAngle));
@@ -98,14 +103,7 @@ public void paintComponent(Graphics g) {
98103
}
99104
}
100105

101-
public static void main(String[] args) {
102-
JFrame frame = new JFrame("Sample Drawings Using a Graphics Object");
103-
//frame.getContentPane().add(new Graphic());
104-
frame.pack();
105-
frame.setVisible(true);
106-
}
107-
108-
public static void Graphic(List<String> listcom) {
106+
public static void setArray(List<String> listcom) {
109107
l = listcom;
110108

111109
}

0 commit comments

Comments
 (0)