Question

I Have Some problem.

Let's say I have Q Icons (simple icon let say android logo) and I want to place them in a star topology against the single star center (icons) and connecting them on android canvas.

enter image description here

How can I do it?

any exact Links?

any algorithm information?

Was it helpful?

Solution 2

public  void starTopology(Canvas mCanvas,int noOfFriends,float centerX,float centerY,int radious) {


        final double PI = 3.14;
        final double MARGIN = (2*PI)/noOfFriends;
        final double OFFSETX = centerX;
        final double OFFSETY = centerY;
        final int RADIUS = radious;

        float pointXCoord = 0;
        float pointYCoord = 0;
        double NextPositionOnCircumference = MARGIN;



        Paint myCustomizedBrush = new Paint();
        myCustomizedBrush.setAntiAlias(true);

        myCustomizedBrush.setColor(Color.WHITE);


        for(int i= 0; i < noOfFriends; i++){

            pointXCoord =  (float) (OFFSETX + RADIUS * Math.cos(NextPositionOnCircumference));
            pointYCoord  = (float) (OFFSETY + RADIUS * Math.sin(NextPositionOnCircumference));

            NextPositionOnCircumference += MARGIN;
            mCanvas.drawLine((float)OFFSETX, (float)OFFSETY, pointXCoord, pointYCoord, myCustomizedBrush);
            pointXCoord -= 10;
            pointYCoord -= 10;
            mCanvas.drawBitmap(Utility.FriendProfilePic.get(i), pointXCoord, pointYCoord, null);


        }
        mCanvas.drawCircle((float)OFFSETX, (float)OFFSETY, 5, myCustomizedBrush);

}

OTHER TIPS

Essentially what you will want to do is create points around a centre, give the points an icon and a line connecting them with the centre.
Creating 2d points on a circle can be done with cosine/sine:

double angle;
point.x = offsetX + radius*Math.cos(angle);
point.y = offsetY + radius*Math.sin(angle);

Increment the angle with a suitable value for each contact and store points like this in an array or a list.
When it comes to drawing, draw your icon centred at its point (yourCanvas.drawBitmap()), and draw a line to the centre point (yourCanvas.drawLine()).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top