We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Index › Rectangular selection of curves using mouse
 Pages: 1
 Rectangular selection of curves using mouse (Read 2882 times)
 syntor2001 Rectangular selection of curves using mouse Jun 14th, 2010, 2:51pm   Hello everybody, I am a newbie of processing. I am supposed draw curves (or connected points) from a file and select rectangular area on the screen and identify the curves partially fall within the rectangle.is it possible?thank you very much in advance.
 syntor2001 Re: Rectangular selection of curves using mouse Reply #1 - Jun 15th, 2010, 12:25am   this is what I mean exactlyhttp://www.stat.sc.edu/~west/bradley/PCPiris.html
 PhiLho Re: Rectangular selection of curves using mouse Reply #2 - Jun 15th, 2010, 7:59am   It is quite simple with lines as shown. It should be quite harder with curves... It depends on the kind of curves, too.
 guss Re: Rectangular selection of curves using mouse Reply #3 - Jun 15th, 2010, 9:05am   I was going to just write you a small example program but thing kinda got out of hand... good exercise though!Anyways here's one way you can do it: Code:```class Point{  public float x;  public float y;  public Point(float nx,float ny){    x = nx;    y = ny;  } }class Line{  //every line is a list of connected points  public ArrayList listOfPoints;  public color c;  public boolean selected;  public Line(){    listOfPoints = new ArrayList();    selected = false;    //Every line is given a random color with low alpha so that    //1) you can tell them apart and 2) the selected onces will be more visible when selected    c = color(random(255),random(255),random(255),100);  }  public void drawLine(){    // A line needs two points to be a line....    if(listOfPoints.size() >=2){      if(selected){        stroke(255,0,0,255);//full red      }      else{        stroke(c);      }        beginShape();      for(int i = 0; i 0) {    topIntersection = (m*rx1  + c);    bottomIntersection = (m*(rx2)  + c);  }  // Otherwise it's on the right  else {    topIntersection = (m*(rx2)  + c);    bottomIntersection = (m*rx1  + c);  }  // Work out the top and bottom extents for the triangle  if(y1 < y2) {    topPoint = y1;    bottomPoint = y2;  }  else {    topPoint = y2;    bottomPoint = y1;  }  float topOverlap;  float botOverlap;  // Calculate the overlap between those two bounds  topOverlap = topIntersection > topPoint ? topIntersection : topPoint;  botOverlap = bottomIntersection < bottomPoint ? bottomIntersection : bottomPoint;  return (topOverlapry2)));} ```
 syntor2001 Re: Rectangular selection of curves using mouse Reply #4 - Jun 16th, 2010, 12:31pm   guss, you are wonderful !!thank you very much, now I should modify your code, in order to get data from text file.any idea of reading from external text file?
 guss Re: Rectangular selection of curves using mouse Reply #5 - Jun 16th, 2010, 2:39pm   syntor2001 wrote on Jun 16th, 2010, 12:31pm:guss, you are wonderful !!thank you very much, now I should modify your code, in order to get data from text file.any idea of reading from external text file np, as what goes for reading from an external file:http://processing.org/reference/BufferedReader.html
 PhiLho Re: Rectangular selection of curves using mouse Reply #6 - Jun 17th, 2010, 4:48am   For small amount of text, loadStrings() does the job nicely. (BufferedReader is harder to use but perfect for large data files.)
 Pages: 1