OangUtanKlaus
OangUtanKlaus

Reputation: 53

setPixel; Pixelkoordinates with Datatype 'long'

I am trying to plot a Siemens Star into an empty Bitmap. When I am witing down the formula for the coordinates of the circle pixels, the pogramm tells me, that it results in a Long-number instead of an Integer.

    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

I have tried this algoithm in Matlab and it works fine. Can anyone tell me my mistake?

Upvotes: 1

Views: 46

Answers (1)

aldarel
aldarel

Reputation: 456

You need to cast Math.round result to integer with following code:

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

Upvotes: 2

Related Questions