Java Array Scale scalePoints(double[] points, int height)

Here you can find the source of scalePoints(double[] points, int height)

Description

scale Points

License

Open Source License

Declaration

public static int[] scalePoints(double[] points, int height) 

Method Source Code


//package com.java2s;
/*//w ww . j a  v  a2 s  .  c o m
 * Boltzmann 3D, a kinetic theory demonstrator
 * Copyright (C) 2013 Dr. Randall B. Shirts
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Arrays;

public class Main {
    public static int[] scalePoints(double[] points, int height) {
        double maxValue = -1.0;

        for (int i = 0; i < points.length; i++) {
            if (points[i] > maxValue && points[i] != Double.POSITIVE_INFINITY) {
                maxValue = points[i];
            }
        }

        return scalePoints(points, height, maxValue);
    }

    public static int[] scalePoints(double[] points, int height, double maxValue) {
        int[] scaledPoints = new int[points.length];

        if (maxValue <= 0) {
            Arrays.fill(scaledPoints, height - 1);
        } else {
            for (int i = 0; i < points.length; i++) {
                scaledPoints[i] = (int) (((points[i] / maxValue)) * height);
            }
        }

        return scaledPoints;
    }
}

Related

  1. expandToLength16(byte scaledValue[], final boolean isNegative)
  2. minMaxScale(final double[] x)
  3. scale(double[][] as)
  4. scale(final double[] a, double scale)
  5. scaleMAD(double[] data)