|
» codelab : http://codelab.fr/accueil » Forum : discussions Code : http://codelab.fr/code » ArrayList en Java : http://codelab.fr/827 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : ArrayList en Java |
| oyster_twiter — 2008-10-28 17:20:16 |
salut, |
| 22_80 — 2008-10-28 19:18:37 |
Yop, class Element implements Comparable {
int x;
int y;
...
int compareTo(Object o){
Element elt = (Element) o;
if(this.x < elt.x) return -1;
if(this.x > elt.x) return 1;
return 0;
}
...
}Crois-moi, ce tri est très rapide, tu n'arriveras pas à de telles performances en faisant un algo à la main. |
| oyster_twiter — 2008-10-29 09:21:23 |
salut! |
| 22_80 — 2008-10-29 10:10:40 |
...:lol: ... ben ... j'avoue que non ... |
| 22_80 — 2008-10-29 11:11:24 |
Yep, journée pépère au taf ... j'essaye de comprendre ... c'est pas vraiment un pb de tri en fait ? |
| oyster_twiter — 2008-10-29 12:42:23 |
ahah //-------------------------------- springs ---------------------
// CALC BOUNCE FORCES
vec2d v = new vec2d(0,0);
vec2d diff = new vec2d(0,0);
// CALC BOUNCE FORCES
for (int i=0; i < P_temp_A.size();i++) {
for (int j=0; j<i; j++) {
//DERIVS = (derivative)D_A.get(i) ;
PRTS_temp = (particle)P_temp_A.get(i) ;
particle PRTS_temp2 = (particle)P_temp_A.get(j) ;
// calc the vector which represents distance
diff.set(PRTS_temp.pos);
diff.sub(PRTS_temp2.pos);
float distance = diff.length();
// collision check!
if (distance < (PRTS_temp.radius + PRTS_temp2.radius)){
// 1 to 0 based on closeness
float strength = (distance / (PRTS_temp.radius + PRTS_temp2.radius));
// angle of collision
float dir = (float)Math.atan2(-diff.y, diff.x);
if (PRTS_temp2.bFixed != true){
// dampen on collision
v.set(PRTS_temp2.vel);
v.mult(0.03f );
PRTS_temp2.frc.sub(v);
PRTS_temp2.frc.x -= 10*(1-strength)*Math.cos(dir);
PRTS_temp2.frc.y += 10*(1-strength)*Math.sin(dir);
}
if (PRTS_temp.bFixed != true){
v.set(PRTS_temp.vel);
v.mult(0.03f );
PRTS_temp.frc.sub(v);
PRTS_temp.frc.x -= -10*(1-strength)*Math.cos(dir);
PRTS_temp.frc.y += -10*(1-strength)*Math.sin(dir);
}
}
}
}j'espere ça t'aidera à y voir plus clair... |
| 22_80 — 2008-10-29 13:07:12 |
okkkk ... ayé, j'y suis ...
Qu'est-ce qui te dérange dans cette opération ? ça m'a l'air très correct ... |
| 22_80 — 2008-10-29 13:21:24 |
Ah ... attends ... je crois comprendre ... Particule obj2 = (Particule) MyArrayList.get(j); ... tu précises le type de ton objet. List<Particule> maListe = new ArrayList<Particule>(); Et ainsi éviter l'opération de caste, ainsi dans ta boucle, tu peux accéder directement à tes attributs : maListe.get(i).x |
| oyster_twiter — 2008-10-29 13:43:19 |
En effet j'ai pu voir les possibilité de java >=5 mais je n'y suis pas pour plus longtemps d'ailleurs. // CALC BOUNCE FORCES
vec2d v = new vec2d(0,0);
vec2d diff = new vec2d(0,0);
// CALC BOUNCE FORCES
for (int i=0; i < numParticles;i++) {
for (int j=0; j<i; j++) {
// calc the vector which represents distance
diff.set(PRTS_temp[i].pos);
diff.sub(PRTS_temp[j].pos);
float distance = diff.length();
// collision check!
if (distance < (PRTS_temp[i].radius + PRTS_temp[j].radius)){
// 1 to 0 based on closeness
float strength = (distance / (PRTS_temp[i].radius + PRTS_temp[j].radius));
// angle of collision
float dir = (float)Math.atan2(-diff.y, diff.x);
if (PRTS_temp[j].bFixed != true){
// dampen on collision
v.set(PRTS_temp[j].vel);
v.mult(0.03f );
PRTS_temp[j].frc.sub(v);
PRTS_temp[j].frc.x -= 10*(1-strength)*Math.cos(dir);
PRTS_temp[j].frc.y += 10*(1-strength)*Math.sin(dir);
}
if (PRTS_temp[i].bFixed != true){
v.set(PRTS_temp[i].vel);
v.mult(0.03f );
PRTS_temp[i].frc.sub(v);
PRTS_temp[i].frc.x -= -10*(1-strength)*Math.cos(dir);
PRTS_temp[i].frc.y += -10*(1-strength)*Math.sin(dir);
}
}
}
}les comportements de spring diffèrents lorsque je passe à l'ArrayList, ce qui me mettait un doute sur la bonne syntaxe de mon code. |
| 22_80 — 2008-10-29 14:17:45 |
Les ArrayList et les tableaux ont le même comportement, je ne pense pas qu'il y ait de pbs à ce niveau-là. |
| oyster_twiter — 2008-10-29 15:21:21 |
merci pour tes eclaircies... |
| 22_80 — 2008-10-29 16:01:53 |
De rien, oui ... envoie, je regarde ça. |
| oyster_twiter — 2008-10-29 22:04:04 |
... |