How to cover scattered point???

kirkir
edited October 2015 in Questions about Code

Hi, I have few set of point in the form (x,y coordinate),I would wish to draw a ellipse (i.e.circle) such that it all points fall within the circle.Would really appreciate if some one can help me .

Thanks in advance !!!!

Tagged:

Answers

  • a nice task!

    I appreciate the beauty of the problem.

  • break it down into smaller steps.

    what do you need for a circle?

    make a list.

    imagine you'd have only 2 points.

    Where would you start?

  • Hi Chrisir thanks for that post !!!

    But sorry I didn't get what you said.

    Let me explain you where I am exactly struggling .

    I am able to draw right angled triangle. Am generating few set of dynamic point (i.e x,y coordinates) these points are scattered all around the region, what I am looking for is that I wish to draw a ellipse or circle in such a way that all points fall with in the region (circle) .

    IF you guide me I can send the snapshot of it .

    Really looking forward for your reply. Thanks !!!

  • understood

    you need to draw a circle.

    what do you need to draw a circle?

  • hi,

    reference point and the radius.

  • edited October 2015

    ok, let's say you have only two points

    where would the reference point for the circle be?

  • No no

    I lead you through

    again

    let's say you have only 2 points P1 and P2

    where is the center of the circle then?

    HOW can you calulate it?

  • edited October 2015

    It's a thought experiment: if you had only 2 points

  • No I have set of finite points (x,y coordinates) grey circle is one am able to do but it covers extra area but I only need to cover those dense area i.e the pink circle .

  • Kir, Chrisir is breaking down the problem for you so it's easier to work you towards a solution. Say you only needed to find the circle around two points. Then how would you draw it? Hint,

    it can be any one among them

    is wrong.

  • also post your entire code please

  • U find the above url for the snapshot for which i am trying to find the answer.

  • "The requested URL /oie_upload/images/89214EI12nHArwj/mVivvO6E2bzF.png was not found on this server."

  • (you can upload an image to this forum using the button above the text box, the one on the left that looks like a picture)

  • I found the grey circle by averaging the set of points (x,y). I took the avg(x,y) as the reference point . I found the distance from this point i.e avg (x,y) to all other points . Among them I took the largest distance as radius and drew a circle from avg (x,y) !!!!!

    I want to get only the pink circle as result....

  • what grey circle. we cannot see a grey circle because the urls you posted are broken.

  • @ koogs

    I have the image on my desktop !!!!

  • i can't see your desktop

  • yeah i hope u got my snap shot ???

  • were you given an algorithm or do you have to work it out yourself (which is hard)?

    luckily someone already has: http://www.personal.kent.edu/~rmuhamma/Compgeometry/MyCG/CG-Applets/Center/centercli.htm

  • hi Koogs,

    I really appreciate ur help.THANKS A TON!!! I am suppose to implement this in processing !!!

  • I wanted to lead you to understand that you have to take the average of all points positions

    Now you write you have that... Why didn't you write that.... also the distance is the right approach

    Now it doesn't work... why didn't you say so?

    Post your code so we can have a look....

  • kirkir
    edited October 2015

    [unformated code deleted, see below]

  • @ CHRISIR

    SORRY !!! Am completely new to this. Sorry do find the above code let me know !!!

  • thank u GoToLoop for that post !!!!!!!!!!!!!!!!!!

  • kirkir
    edited October 2015
    void draw()
    { 
      d1 = dist1[i];
      d2 = dist2[i];
      d3 = dist3[i];
    
      i++;
      /////////// x and y are calculated based on some condition
    
      arrx[j] = x;
      arry[j] = y;
    
      println(arrx[j], arry[j]);
    
      j++;
    
      if(j==dist1.length)
      {
        for(int k=j-1; k>1; k--)
        {
          avgx = avgx + arrx[k];
          avgy = avgy + arry[k];
        }
       nx=(avgx/j);
       ny=(avgy/j);
    
       distx[0] = sqrt(((nx - arrx[1])*(nx - arrx[1])) + ((ny - arry[1])*(ny - arry[1])));
       println(distx[0]);
       for(int k = 1;k<j;k++)
        { 
          distx[k] = sqrt(((nx - arrx[k])*(nx - arrx[k])) + ((ny - arry[k])*(nx - arrx[k])));
            if(distx[k]>=distx[0])
              { 
                distx[0]=distx[k];
                }
        }
        println(distx[0]);
    
       stroke(0);
       fill(155);
       ellipse(scaleAxis(nx),scaleAxis(ny),scaleAxis(distx[0]),scaleAxis(distx[0]));
    
       for(int k= 1; k<=j-1;k++)
       {
        ellipse(scaleAxis(arrx[k]),scaleAxis(arry[k]),5,5);
         }
    
      }
    
      delay(300);
    }
    
    void delay(int wait)
    {
      int time = millis();
      while(wait >= (millis() - time));
    }
    
    float scaleAxis(float var)
    {
      return (150 * var);
    }
    
  • That code does not look very complete.

  • paste code. highlight code. hit ctrl-o.

  • kirkir
    edited October 2015
    float X1, Y1, X2, Y2, X3, Y3;
    float AB, BC, AC;
    float[] dist1, dist2, dist3;
    float x, y, prev_x, prev_y;
    float d1, d2, d3;
    float avgx=0,avgy=0,nx=0,ny=0;
    float[] arrx = new float[51];
    float[] arry = new float[51];
    float[] distx = new float[51];
    int i = 0,j = 1;
    
    void setup()
    {
      AB = 2;
      BC = 2;
      AC = 2;
    
      X1 = 0; 
      Y1 = 0;
      X2 = 0;
      Y2 = AB;
      X3 = AC;
      Y3 = 0;
      size(640,560);
      fill(0, 0, 0);
      text("A", scaleAxis(X1), scaleAxis(Y1));
      text("B", scaleAxis(X2), scaleAxis(Y2));
      text("C", scaleAxis(X3), scaleAxis(Y3));
    
      stroke(0);
      fill(255);
    
      String[] dist1_str = loadStrings("output_r1.txt");
      String[] dist2_str = loadStrings("output_r2.txt");
      String[] dist3_str = loadStrings("output_r3.txt");
    
      dist1 = float(dist1_str);
     dist2 = float(dist2_str);
     dist3 = float(dist3_str);
    
     triangle(scaleAxis(X1), scaleAxis(Y1), scaleAxis(X2), scaleAxis(Y2), scaleAxis(X3), scaleAxis(Y3));
     fill(0);
    }
    
    void draw()
    {
      d1 = dist1[i];
      d2 = dist2[i];
      d3 = dist3[i];
    
      i++;
    
       y = (((d1 *d1) - (d2* d2) + (Y2*Y2) )/ (2*Y2));
       x = (((d1*d1)-(d3*d3)+(X3*X3))/(2*X3)); 
      arrx[j] = x;
      arry[j] = y;
    
      println(arrx[j], arry[j]);
    
      j++;
    
      if(j==dist1.length)
      { 
        for(int k=j-1; k>1; k--)
        {
          avgx = avgx + arrx[k];
          avgy = avgy + arry[k];
        }
       nx=(avgx/j);
       ny=(avgy/j);
        println("averge of x ,y",nx,ny);
       distx[0] = sqrt(((nx - arrx[1])*(nx - arrx[1])) + ((ny - arry[1])*(ny - arry[1])));
       println(distx[0]);
       for(int k = 1;k<j;k++)
        { 
          distx[k] = sqrt(((nx - arrx[k])*(nx - arrx[k])) + ((ny - arry[k])*(nx - arrx[k])));
            if(distx[k]>=distx[0])
              { 
                distx[0]=distx[k];
                }
        }
        println(distx[0]);
    
       stroke(0);
       fill(155);
       ellipse(scaleAxis(nx),scaleAxis(ny),scaleAxis(distx[0]),scaleAxis(distx[0]));
    
       for(int k= 1; k<=j-1;k++)
       {
        ellipse(scaleAxis(arrx[k]),scaleAxis(arry[k]),5,5);
         }
    
      }
    delay(300);
    }
    
    void delay(int wait)
    {
      int time = millis();
      while(wait >= (millis() - time));
    }
    
    float scaleAxis(float var)
    {
      return (150 * var);
    }
    
Sign In or Register to comment.