2017-02-02 3 views
1

J'essaye de tracer un Siemens Star dans un Bitmap vide. Quand je parle de la formule pour les coordonnées des pixels du cercle, le pogramm me dit qu'il en résulte un nombre long au lieu d'un nombre entier.setPixel; Pixelkoordinates avec Datatype 'long'

double d = 0.001; 
    Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); 

    for(int r = Rin; r < Rout; r++){ 
     double phi = 0; 
     while(phi < 2* Math.PI){ 
      for(int i = 0; i<Math.PI/nPeriods*1/d; i++){ 
       int x = Math.round(X_Center + Math.cos(phi)*r); 
       int y = Math.round(Y_Center + Math.sin(phi)*r); 
       bmp.setPixel(x,y,Color.BLACK); 
       phi = phi+d; 
      } 

      for(int i = 0; i<Math.PI/nPeriods*1/d; i++){ 
       phi = phi+d; 
      } 
     } 
    } 

enter image description here

J'ai essayé algoithm dans Matlab et il fonctionne très bien. Quelqu'un peut-il me dire mon erreur?

Répondre

2

Vous devez jeter résultat Math.round en entier avec le code suivant:

int x = (int) Math.round(X_Center + Math.cos(phi)*r); 
+0

si simple ... Merci! – OangUtanKlaus