How to get the point of intersection from curve.

edited August 2016 in Library Questions

名称未設定

Hello.I'd like to make a some kind of controller like attached file. the curve(white bold line) can be controlled by green button and numbers can map from x coordinate from y coordinate.

I could make curve and button controll. I have been stuck while getting the point of intersection. (added red point by photoshop) I researched and found geomerative library provides intersection method. but i couldn't find how to read bezier curve Rpath object.

Could anyone can tell me how to read bezier curve to geomerative, or any other idea to getting intersection with bezier and lines?

Tagged:

Answers

  • How do you generate your white line? Is it a function?

    Kf

  • edited August 2016

    I generate white bold line by processing function put in draw() loop,

    beginShape();
    strokeWeight(5);
    vertex(12, 468);
    bezierVertex(icon1.x, icon1.y,icon2.x, icon2.y,468,12);
    endShape();

    and value of icon1.x, icon1.y,icon2.x, icon2.y is provided dynamically by other class

  • The benzierCurve has to generate the curve based on a function. I would suggest you look it up. If you know the function, then you can get the interceptions using this function. Maybe somebody in the forum has done this before. Here I have an idea of doing it with a function I defined explicitly. This is not what you ask but it it is more a proof of concept.

    Kf

    int xLine=0;
    float k=60;
    
    void setup() {
      size(600, 600);
      textAlign(LEFT,TOP);
    }
    
    void draw() {  
      background(0);
      stroke(220);
    
      for(int x=0;x<width;x++){   
         point(x,f(x));
      }
    
      stroke(155,10,10);
      line(xLine,0,xLine,height);
    
      int y=int(f(xLine));
      fill(10,155,10);
      text(xLine+"@"+y,xLine,y);
    
    }
    
    float f(int x){
      return int(height*(1-x/(k+x)));
    }
    
    void mouseReleased(){
      xLine=mouseX;  
      k=map(xLine,0,width,height/100.0,height/5.0);
    
    
    }
    
Sign In or Register to comment.