Search code examples
c++formulacurve

invert a curve by his x axis


What would be the formula to rotate a curve by the x axis in java?


Solution

  • Assuming you have the curve as an array of Points here is something like a pseudocode:

    Point[] curve;
    
    double x_max = curve[0].x, x_min = curve[0].x;
    for( point : curve) {
      x_max = max(x_max, point.x);
      x_min = max(x_min, point.x);
    }
    
    for (point : curve) {
      point.x = x_max - point.x + x_min;
    }
    

    How does it work? In fact I try to mirror the curve's normalized coordinates - that is the coordinates that the points would have if they started from x = 0 (the formula for that is point.x - x_min) and then you subtract the result from x_max so that the curve now is defined right to left instead of left to right.