Mercurial > dive4elements > river
changeset 3765:d8f2ab5b61c3
Added JFreeUtil.randomizeLine() to generate randomized lines.
flys-artifacts/trunk@5467 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 14 Sep 2012 12:17:14 +0000 |
parents | a6f5bb10eff4 |
children | d29cebf371ba |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java |
diffstat | 2 files changed, 61 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Sep 14 08:01:02 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Sep 14 12:17:14 2012 +0000 @@ -1,3 +1,8 @@ +2012-09-14 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/jfree/JFreeUtil.java: Added function to + generate a randomized line. + 2012-09-14 Ingo Weinzierl <ingo@intevation.de> * doc/conf/themes.xml: Defined new mappings for the six bed quality
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java Fri Sep 14 08:01:02 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java Fri Sep 14 12:17:14 2012 +0000 @@ -1,19 +1,20 @@ package de.intevation.flys.jfree; +import java.awt.Shape; +import java.awt.geom.Rectangle2D; +import java.util.Iterator; +import java.util.Random; + +import org.apache.log4j.Logger; +import org.jfree.chart.entity.ChartEntity; +import org.jfree.chart.entity.EntityCollection; +import org.w3c.dom.Document; + import de.intevation.flys.artifacts.math.Function; -import java.awt.Shape; - -import java.awt.geom.Rectangle2D; - -import java.util.Iterator; - -import org.jfree.chart.entity.ChartEntity; -import org.jfree.chart.entity.EntityCollection; - -import org.w3c.dom.Document; - public class JFreeUtil { + + private static final Logger logger = Logger.getLogger(JFreeUtil.class); /** Do not instantiate. */ private JFreeUtil() { @@ -50,6 +51,50 @@ return false; } + + + /** + * This function samples a randomized line that contains of x and y values + * between <i>startX</i>, <i>endX</i>, <i>startY</i> and <i>endY</i>. The + * number of points in the line is specified by <i>num</i>. + * + * @param num The number of points in the line. + * @param startX The min value of the x values. + * @param endX The max value of the x values. + * @param startY The min value of the y values. + * @param endY The max value of the y values. + * @return an array with [allX-values, allY-values]. + * @throws IllegalArgumentException + */ + public static double[][] randomizeLine( + int num, + double startX, + double endX, + double startY, + double endY + ) throws IllegalArgumentException + { + if (num <= 0) { + throw new IllegalArgumentException("Parameter 'num' has to be > 0"); + } + + Random random = new Random(); + + double[] x = new double[num]; + double[] y = new double[num]; + + for (int i = 0; i < num; i++) { + double xFac = random.nextDouble(); + double yFac = random.nextDouble(); + + x[i] = startX + xFac * (endX - startX); + y[i] = startY + yFac * (endY - startY); + + logger.debug("Created new point: " + x[i] + "|" + y[i]); + } + + return new double[][] { x, y }; + } public static StyledXYSeries sampleFunction2D(