-2

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?

gnat
  • 6,213
  • 108
  • 53
  • 73
Hikmat Khan
  • 6,434
  • 2
  • 25
  • 22

2 Answers2

1

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()).

Jave
  • 31,598
  • 14
  • 77
  • 90
  • for(int i= 0; i < 200; i++){ float x = (int) Math.cos(marginToNextAnglePtn); float y = (int) Math.sin(marginToNextAnglePtn); Log.e("Iteration Number X " + i +" = ",x+""); Log.e("Iteration Number Y" + i + " = ",y + ""); marginToNextAnglePtn += MARGIN; } Dude I try it But its Not Working. – Hikmat Khan Dec 20 '11 at 13:35
  • first of all, you should not cast your result to int (the '(int)'), or you will only get 1 or 0, use a float cast instead '(float)', second, the angle should be in radians, in case you are using degrees. – Jave Dec 20 '11 at 13:40
  • for(int i= 0; i < 200; i++){ double x = Math.cos(marginToNextAnglePtn); double y = Math.sin(marginToNextAnglePtn); Log.e("Iteration Number X " + i +" = ",x+""); Log.e("Iteration Number Y" + i + " = ",y + ""); marginToNextAnglePtn += MARGIN; } Now i have x and y Coordinates of a point on the circle. how can i get the center piont coordinate in order to draw line and draw both the icons. – Hikmat Khan Dec 20 '11 at 13:51
  • using this method, the center point will always be 0,0. I also modified the example with a radius parameter, or the circle will always have a 1 px radius. – Jave Dec 20 '11 at 13:53
  • http://docs.oracle.com/javase/tutorial/java/data/beyondmath.html This link contains information of how to convert a radient to degree. Now i have a Degree information but how can i get information of starting piont (center) and ending point laying on that degreee... Dude i want to draw bitmaps in circle around center. – Hikmat Khan Dec 20 '11 at 13:54
  • Ok i got You. but lets say center piont is (200,200) then how can we get pionts on it circle against it Center in order to make a star topology. – Hikmat Khan Dec 20 '11 at 13:58
  • There, I modified the example a little more. To get centre at 200,200 set offsetX to 200 and offsetY to 200. – Jave Dec 20 '11 at 13:59
  • 1
    The example code, together with your for loop should create all points as you need them, it's just the drawing left. – Jave Dec 20 '11 at 14:08
0
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);

}

Hikmat Khan
  • 6,434
  • 2
  • 25
  • 22