Mapping float numbers on an arc

Hello,

I have a list of float numbers ranging from -1 to 1, and I want to map them on an arc and then connect them to the arc centre, as shown in the image below. The line of code for creating the arc is this one:

arc(width/2, weight/2, width-10, weight-10, PI-QUARTER_PI, TWO_PI + QUARTER_PI);

From what I've read, I should get the coordinates on the arc in this way: (x,y) = (rcosθ, rsinθ), but it doesn't seem to work correctly. I know that it's more of a maths question, but if someone could help me, it would be much appreciated!

image000166

Tagged:

Answers

  • Answer ✓

    I assume that -1 corresponds to the left end of the arc and +1 the right end of the arc if that is true then you can

    float fn = 0.234; // a number to be mapped
    float angle = map(fn, -1, 1, PI - QUARTER_PI, TWO_PI + QUARTER_PI);
    
    // so we can get the point on the arc with
    
    float x = radius * cos(angle) + cx;
    float y = radius * sin(angle) + cy;
    

    where radius is the radius of the arc and cx, cy define the centre of the arc.

  • edited March 2016

    You basically want to map a range of values to the arc's circumference. That is simply done as follows:

    theta = map(value, -1, 1, PI-QUARTER_PI, TWO_PI + QUARTER_PI);

    (x,y) = (arc_x + rcos(theta), arc_y + rsin(theta))

    And it works fine!

    float value = -1;
    float theta;
    
    void setup(){
      size(600, 600);
    }
    
    void draw(){
      background(255);
      noFill();
      arc(width/2, height/2, width-10, height-10, PI-QUARTER_PI, TWO_PI + QUARTER_PI);
      theta = map(value, -1, 1, PI-QUARTER_PI, TWO_PI + QUARTER_PI);
    
      fill(255,0,0);
      ellipse(width/2 + cos(theta)*width/2, height/2 + sin(theta)*height/2, 5,5);
    }
    
  • Thank you both for the fast reply. The answer from quark worked for me! :)

  • The answer from Alex_Pr was the same as mine except he hard coded the numbers for radius, cx and cy.

Sign In or Register to comment.