• How to Scale any two given points into [0,1]

    CatheriBurbank Member

    Doing a project I got stuck with this. I have to implement a method that gets any two given points ( x, y) and scales them between [0,1]

    I been trying to many different ways, I even browsed other site but I still don’t understand. This is the formula other sites used to scale it down, but I doesn’t seem to work

    Code: Select all

    (x-min)/(max - min)

    This is my Example

     double max = 1;
           double low = 0;
          
           double x = 50;
           double y = 100;
          
           double newPointX = (x-low)/(max-low);
           double newPointY = (y-low)/(max-low);
          
           System.out.println(newPointX);
           System.out.println(newPointY);
          
    

    I tried do my own example where my Point is (50,100), so generally this should be scaled down to “[0,1]” but it doesn’t work. Can any one help with this small algorithm.

  • ShikhaTan Member
    x-low: 50 - 0 = 50
    max-low: 1-0 = 1
    newpointx = 50/1 = 50
    

    I guess it doesn’t work! I believe the max/min that the original formula refers to is the min / max of the original points 50/100. With that hint you should be able to complete the assignment

  • BuckRenard Member

    The scaling formula (from your original post) *does* work.

    But it will work for the two individual axes – “X” (horizontal) and “Y” (vertical) – individually.

    As in, your original point [50,100] really represents an X-value of 50 and an Y-value of 100. To apply the formula, you will have to indicate if these axis share a common scale – in which case, the max value is 100 and min is 50 (or zero) – or if they are separate scales – in which case, for X-axis the max may be 50, whilst for Y-axis may be 100.

    Supposing they share a common scale (min=0, max=100): to normalize the X value, apply the formula: (50 – 0) / (100 – 0) » 0.5
    Normalizing the Y value, you get 1.0, therefore the point really is [0.5, 1.0]

    If you need it to be something else, you will have to muck around with the range values (max and min).

  • Abhey Member

    I had to create method that obtained the [Max, Min] Points. I feel that the logic to my problem IS my problem. hope that makes sense. Ha

    Well, I had several methods that obtain the [Max, Min] of both [X,Y]

    public double getMax(BunchOfObjects points){
          double maxX = points.getAll().get(0).getX();
          for( Point p : points.getAll()){
             if(p.getX() > maxX){
                maxX = p.getX();
             }
          }
    
          return maxX;
    
       }
    

    Now, I need a Scale method that is going to work around these points
    Can any help me with this method?

    public double  scale(BunchOfObjects points , double x, double y){
    
       double maxX = getMax(points);
       double maxY = getMaxY(points);
       double minX = getMinX(points);
       double minY = getMinY(points);
       double dx = maxX - minX;
       double dy = maxY -minY;
       double scaledx = (x-minX)/dx;
       double scaledy = (y-minY)/dy;
    

    Now, my question is…What do I return? Sorry, this problem is giving me headaches. and I can’t figure out exactly.

  • ShikhaTan Member

    Create two different method to ScaleX and ScaleY then set those points in before you actually drew them.

Viewing 4 reply threads
  • You must be logged in to reply to this topic.
en_USEnglish