reconnaissance de forme

This commit is contained in:
DonRenando 2017-01-18 14:10:17 +01:00
parent 6138e26c0c
commit 7f1098c41b
3 changed files with 77 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import fr.dgac.ivy.IvyException;
import model.Forme;
import javax.swing.*;
import java.awt.event.MouseEvent;
@ -34,12 +35,22 @@ class Fenetre extends JFrame {
public void mousePressed(MouseEvent mouseEvent) {
if (SwingUtilities.isLeftMouseButton(mouseEvent))
panel.getStroke().addPoint(mouseEvent.getX(), mouseEvent.getY());
panel.stroke = new Stroke();
}
@Override
public void mouseReleased(MouseEvent mouseEvent) {
monIvy.sendMsg("coord=" + panel.getStroke().toString());
if (!panel.getStroke().isEmpty())
monIvy.sendMsg("coord=" + panel.getStroke().toString());
panel.getStroke().normalize();
System.out.println(panel.getStroke());
Reconnaissance.comparaison(Reconnaissance.reconnaissance(panel.getStroke(), Forme.ROND.split(";")),
Reconnaissance.reconnaissance(panel.getStroke(), Forme.CARRE.split(";")),
Reconnaissance.reconnaissance(panel.getStroke(), Forme.TRAIT.split(";")),
Reconnaissance.reconnaissance(panel.getStroke(), Forme.Z.split(";")));
}

50
src/Reconnaissance.java Normal file
View File

@ -0,0 +1,50 @@
import java.awt.geom.Point2D;
/**
* Created by renando on 18/01/17.
*/
public class Reconnaissance {
public static int reconnaissance(Stroke listePoint, String[] listeCoor) {
listePoint.normalize();
int result = 0;
int cpt = 0;
for (Point2D.Double point : listePoint.getPoints()) {
String x;
String y;
x = listeCoor[cpt].split(",")[0];
y = listeCoor[cpt].split(",")[1];
Double x1 = Double.parseDouble(x);
Double y1 = Double.parseDouble(y);
String x2 = String.valueOf(point.getX());
String y2 = String.valueOf(point.getY());
Double x3 = Double.parseDouble(x2);
Double y3 = Double.parseDouble(y2);
result += (int) Math.sqrt((Math.pow(x1 - x3, 2) + Math.pow(y1 - y3, 2)));
cpt++;
}
return result;
}
public static void comparaison(int rond, int carre, int trait, int z) {
if ((carre < rond) && (carre < trait) && (carre < z)) {
System.out.println("C'est un carre");
} else if ((rond < carre) && (rond < trait) && (rond < z)) {
System.out.println("c'est un rond");
} else if ((trait < carre) && (trait < rond) && (trait < z)) {
System.out.println("c'est un trait");
} else if ((z < carre) && (z < rond) && (z < trait)) {
System.out.println("c'est un z");
}
}
}

15
src/model/Forme.java Normal file
View File

@ -0,0 +1,15 @@
package model;
/**
* Created by renando on 18/01/17.
*/
public class Forme {
public static String ROND = "49.36874425801907,99.99999999999997;52.137871590575564,109.91625276383108;56.071737363139725,119.43046540184451;61.80214324175517,127.98253939153958;68.89471962788437,135.44422256956452;76.68186247740189,142.17925022153233;85.87198322006986,146.8126274043917;96.00996880953375,148.58178953920262;106.30348216548668,148.74827722994524;116.3519797100073,146.52677692490897;126.14370717100178,143.3448747517063;135.92126553439746,140.11654316149;144.41428197808477,134.3171447844094;148.24516566682732,124.8014058846849;149.03560351590554,114.53640681797566;149.36874425801906,104.24975635462238;147.39562610365587,94.14501723046394;145.28117280397439,84.06889275065305;143.01783890049052,74.02734945701613;137.48652127661168,65.34342362618126;131.02102931463523,57.33057752027884;123.12244448897232,50.739695681273176;113.02399684625674,48.74827722994524;102.8427552516016,50.28684381904298;92.66151365694648,51.82541040814067;82.61053834560903,54.06179127227966;73.78333719845705,59.35301223779952;66.27977144115522,66.40040197451862;60.51849518502251,74.9322627147603;55.9393686686839,84.15335696130637;52.217424180785834,93.75219995571582;50.17490574903211,103.84315395897521";
public static String CARRE = "52.69884296685535,100.00000000000001;57.4263570169215,108.7627130884843;62.15387106698762,117.52542617696861;66.88138511705375,126.28813926545291;71.6088991671199,135.0508523539372;76.33641321718605,143.81356544242152;81.9393150231771,150.7243427755041;88.75367246214458,144.65272855936794;95.6682031135426,138.38728807664415;102.19946012447102,131.80623532807886;110.1454607888168,126.59281401181991;118.0914614531626,121.379392695561;126.45232993472823,118.18962767471157;135.0768084537892,115.8731941928786;143.03511235346264,110.75333974112675;149.62363392311394,104.21944232813007;148.79990706473362,94.83247229883482;144.94917344547378,85.76548679090541;140.22165939540764,77.00277370242112;135.49414534534148,68.2400606139368;130.76663129527535,59.47734752545251;126.03254354577487,50.724342775504105;117.67125594886619,52.77948132175305;109.5863007401236,56.93614474612603;101.64030007577782,62.14956606238497;94.33319187392759,68.09173283897825;87.93889359142544,74.5829260991812;80.63178538957524,80.5250928757745;72.68578472522942,85.73851419203345;64.73978406088362,90.95193550829234;56.79378339653783,96.16535682455128;49.62363392311395,102.01766411278217";
public static String TRAIT = "50.160415354784085,100.00000000000003;53.17326353894357,100.00000000000003;56.35600623453709,100.00000000000003;59.51615808464585,100.00000000000003;62.75345298715079,100.00000000000003;65.99074788965572,100.00000000000003;69.22804279216066,100.00000000000003;72.46533769466562,100.00000000000003;75.70263259717055,100.00000000000003;78.9399274996755,100.00000000000003;82.17722240218043,100.00000000000003;85.41451730468539,100.00000000000003;88.65181220719032,100.00000000000003;91.88910710969526,100.00000000000003;95.1264020122002,100.00000000000003;98.36369691470514,100.00000000000003;101.60099181721009,100.00000000000003;104.83828671971503,100.00000000000003;108.07558162221997,100.00000000000003;111.31287652472491,100.00000000000003;114.55017142722986,100.00000000000003;117.78746632973477,100.00000000000003;121.02476123223974,100.00000000000003;124.26205613474465,100.00000000000003;127.4993510372496,100.00000000000003;130.73664593975454,100.00000000000003;133.97394084225948,100.00000000000003;137.21123574476442,100.00000000000003;140.44853064726934,100.00000000000003;143.68582554977428,100.00000000000003;146.92312045227925,100.00000000000003;150.16041535478408,100.00000000000003\n";
public static String Z = "48.667281781568214,100.0;56.13077547156965,94.72412814215066;63.77348169611861,89.9756698954599;71.23697538612005,84.69979803761056;78.7004690761215,79.42392617976122;86.16396276612292,74.14805432191187;93.62745645612435,68.87218246406253;101.0909501461258,63.59631060621317;108.55444383612726,58.32043874836383;116.01793752612869,53.04456689051448;123.48143121613015,47.76869503266513;121.4608044018126,56.99298506179767;118.64458463730392,66.72237206952269;114.53741951567872,75.67633931460418;110.27274746607802,84.73859669014485;105.67084324582817,93.65742190626618;100.06305716815451,101.7033649232467;94.50357355821771,109.79544189231966;89.95456462449619,118.693792519923;85.98014937284123,127.86913720577274;81.88749642931137,136.86849264487194;78.53452483983213,146.29670266389215;81.02563079106577,147.76869503266514;88.8369779585736,143.87322297174438;96.71588431898968,140.60198918508388;104.17937800899111,135.32611732723453;111.58572629674038,129.96309423096258;118.81330702156262,124.32743652394561;126.27680071156405,119.05156466609625;133.74029440156548,113.7756928082469;141.20378809156693,108.49982095039755;148.66728178156822,103.22394909254834";
}