Using more than 2 points of control in Interpolater.Spline

Hello

what I'm getting is a bouncing ball, I thought it could work controlling the interpolator to create a control of several points using the spline. (a feature of x ^ n ^, where n is the number of control points)
In a Groove I can use only two control points, is there a way to use more than that, or do I have to use another way.

Thanks for any help.

Edited by: A.m.z on 9 may 2013 01:49

Edited by: A.m.z on 9 may 2013 01:49

Well, I guess it was not so difficult - at least when there are libraries written by others to borrow to...

The interpolator requires the apache commons math 3.2 lib - you can download Commons-math3 - 3.2 - upload - the here:
http://Commons.Apache.org/proper/Commons-math/download_math.cgi
Remove Commons-math3 - 3.2.jar since the zip and put it on your class path.

The interpolator differs slightly from the interpolator of Interpolator.SPLINE that comes with JavaFX.
Instead of control points which bend the curve but do not lie on the curve, the interpolator takes a set of points and trace a straight regression line through the points.

import javafx.animation.Interpolator;
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator;
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction;

public class BestFitSplineInterpolator extends Interpolator {

  final PolynomialSplineFunction f;

  BestFitSplineInterpolator(double[] x, double[] y) {
    f = new SplineInterpolator().interpolate(x, y);
  }

  @Override protected double curve(double t) {
    return f.value(t);
  }
}

Here is a usage example:

import javafx.animation.*;
import javafx.application.Application;
import javafx.scene.* ;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.stage.Stage;
import javafx.util.Duration;

public class BestFitSplineDemo extends Application {

  private static final Duration CYCLE_TIME = Duration.seconds(7);

  private static final int PLOT_SIZE = 500;
  private static final int N_SEGS    = PLOT_SIZE / 10;

  public void start(Stage stage) {
    Path path = new Path();
    path.setStroke(Color.DARKGREEN);

    final Interpolator pathInterpolator = new BestFitSplineInterpolator(
      new double[] { 0.0, 0.25, 0.5, 0.75, 1.0 },
      new double[] { 0.0, 0.5,  0.3, 0.8,  0.0 }
    );

    // interpolated spline function plot.
    plotSpline(path, pathInterpolator, true);

    // animated dot moving along the plot according to a distance over time function.
    final Interpolator timeVsDistanceInterpolator = new BestFitSplineInterpolator(
        new double[] { 0.0, 0.25, 0.5, 0.75, 1.0 },
        new double[] { 0.0, 0.1,  0.4, 0.85, 1.0 }
    );

    Circle dot = new Circle(5, Color.GREENYELLOW);
    PathTransition transition = new PathTransition(CYCLE_TIME, path, dot);
    transition.setInterpolator(timeVsDistanceInterpolator);
    transition.setAutoReverse(true);
    transition.setCycleCount(PathTransition.INDEFINITE);
    transition.play();

    // show a light grey path representing the distance over time.
    Path timeVsDistancePath = new Path();
    timeVsDistancePath.setStroke(Color.DIMGRAY.darker());
    timeVsDistancePath.getStrokeDashArray().setAll(15d, 10d, 5d, 10d);
    plotSpline(timeVsDistancePath, timeVsDistanceInterpolator, true);

    stage.setScene(
      new Scene(
        new Group(
          timeVsDistancePath,
          path,
          dot
        ),
        Color.rgb(35,39,50)
      )
    );
    stage.show();
  }

  // plots an interpolated curve in segments along a path
  // if invert is true then y=0 will be in the bottom left, otherwise it is in the top right
  private void plotSpline(Path path, Interpolator pathInterpolator, boolean invert) {
    final double y0 = pathInterpolator.interpolate(0, PLOT_SIZE, 0);
    path.getElements().addAll(
      new MoveTo(0, invert ? PLOT_SIZE - y0 : y0)
    );

    for (int i = 0; i < N_SEGS; i++) {
      final double frac = (i + 1.0) / N_SEGS;
      final double x = frac * PLOT_SIZE;
      final double y = pathInterpolator.interpolate(0, PLOT_SIZE, frac);
      path.getElements().add(new LineTo(x, invert ? PLOT_SIZE - y : y));
    }
  }

  public static void main(String[] args) { launch(args); }
}

Published by: jsmith on 11 may 2013 05:58

Tags: Java

Similar Questions

  • Adding more than 1 point margin to #content everything makes you invisible.

    Hello

    Just changed all my divs fixed PA, such as recommended by someone within a week or 2 ago. I want to add a margin between #content and #sidebar, however, when I add more than 1 point to the left margin of #content. Everything vanished. Whats up with that? Same thing when I add extra divs inside of my #content, floating the divs will make everything disappear.

    www.nitroset.com

    Problem #2: on this page: http://nitroset.com/clips.html I want the border at the bottom of each table to disappear, the area where it says 'space '. Any ideas?

    An AP div would be supported in this situation?

    Oh, good grief No.   You don't need to complicate your code with additional divisions to control tables.

    Table, tr, th, td... can all be style with CSS.  Use the .class and IDs for special styles.

    Examples of CSS style tables

    http://ALT-Web.com/demos/CSS-3-color-table.shtml

    http://ALT-Web.com/demos/CSS-Zebra-table.shtml

    Nancy O.
    ALT-Web Design & Publishing
    Web | Graphics | Print | Media specialists
    http://ALT-Web.com/
    http://Twitter.com/ALTWEB

  • Slow Server 2008 performance when you use more than 1 CPU - bug?

    Hello

    It seems that when I run Server 2008 on one of my boxes 3 10.5.7 if I use more than 1 CPU in the settings, the ankles of machine the CPU while booting and then during the use of the operating system.  Normally, I have to run all 3 of them at the same time... and if I get all 3 virtual machines running, the CPU remains just pegged and slows down the machine.

    Then, if I close everything and change the settings to 1 CPU, virtual machines work fine, the CPU barely sees any activity and 75% of the 8 GB is used and it can run for weeks at a time without any problem.

    My 3 VMs

    1 Server 2008 x 64 w/Exchange 2007 2 GB, 1CPU

    2 Server 2008 x 86 File Server/Anti-anti-virus/utilities/Quickbooks, etc. 1 GB, 1CPU

    3 Server 2008 x 86 Active 1 GB, 1CPU Directory

    My Mac run all 10.5.7

    1 Macbook Pro 2007 2.33 Core 2 Duo

    1 mac Pro desktop 2008

    Rig EFIX running 10.5.7

    1 EFIX EP45-DS3R Q9550

    all the boxes are running 10.5.7 with the EFIX running 10.5.7 platform server and I can recreate in one of the 3 machines, 10.5 server or workstation, etc.

    Yes, I have the tools are installed and uses the latest patches, software, etc.

    Thanks for any help...

    VCPU more inside a virtual machine using could be a big problem, if you don't have much physical basis.

    If you set vCPU # = # pCore, then you will have several performance issue, cause you VM hangs (during its run) ALL of your hearts.

    André

    * If you found this device or any other answer useful please consider awarding points for correct or helpful answers

  • Satellite Pro L40 PLS4BE: Can I use more than 2 GB of memory

    Is it possible add more than 2 GB of memory?

    What happens if I add e.g. 2 x 2 GB?

    Intel says GM965 supports 4 GB max memory...

    BR,

    Mikko

    Hello

    No you can not use more than 2 GB of RAM. You can upgrade the laptop up to 2GB (2 x 1 GB).

    > What happens if I add e.g. 2 x 2 GB?
    I think that nothing will happen ;)
    Either your laptop will not start or will start the laptop but the full RAM will not be recognized

  • Can I use more than one flash drive to ready boost on Satellite L650/0ed

    Hello

    I have a toshiba Satellite L650/0ed, it's good if I use more than one drive 8 GB flash for "ready boost" - what is the maximum number of using flash-drives can devote to the "ready-boost.

    In addition, if I use a 16 gb flash drive, will this affect more memory "ready boost".

    Why the 3.5 drive seagate expansion 1 TB is not compatible for ready-boost.

    Thank you
    -Brent907

    Hi mate

    Please check this Microsoft page that describes the ReadyBosst
    http://Windows.Microsoft.com/en-us/Windows7/products/features/ReadyBoost

    There, you can find this statement:
    + ReadyBoost works with storage devices more flash. In Windows 7, it can handle more memory and even multiple devices * eight *, for a maximum of 256 GB of additional memory. +

    I hope this can be useful!

  • How is it you can't use more than 126 GB of a 1.5 TB with LabVIEW Real-time hard drive?

    How is it you can't use more than 126 GB of a 1.5 TB with LabVIEW Real-time hard drive?
     
    It's only 8.3% of disk space!

    http://digital.NI.com/public.nsf/allkb/E7E2F5657B6026358625750B007201A6?OpenDocument

    The national Instrument is reformat that you drive less than 126 GB or replace the drive with a less than this size.

    Please OR tell me you go fix your LabVIEW Real Time soon, and that we will not have to wait for LabVIEW RT 9.2.1 in 2011 for this one to fix.

    http://upload.wikimedia.org/Wikipedia/Commons/9/90/Hard_drive_capacity_over_time.svg

    Readers as high as 126 GB or more have been around since mid-2002.  It's about 7 years now and LabVIEW Real-time STILL cannot use greater than 126 GB drives!  Please OR.  Do something.

    We deserve the patches for older versions of LabVIEW RT.  What about updates to LabVIEW RT.  As 7.0.2 7.1.2 7.6.2, 8.0.2, 8.2.2, 8.6.2.

    We don't need new features or versions of LabVIEW RT as 9.0 until we have some of the bugs fixed in existing versions.

    Kevin.


  • How to activate my MSF program for I could use more than 30 minutes at a time

    I had to uninstall my Microsoft Flight Simulator X and MSF - program of acceleration of my PC and reinstall them.  I did it.  When I installed FSX-Deluxe edition, the program asked me the activation number, I gave and then reinstalled the acceleration program. He asked for all the numbers, but now when I run the program, it suits me after 30 minutes then and asks for the active program.  I tried to use the Enternet and everything, but I can't well any place where I can activate this program.  I even call your hotline, they were of no help at all.  First I did not understand that you are Tech. He talked so fast and has no sense at all.  My question is: How can I activate the program? without going to halfway around the world to do. I never had this problem in the past, why now?

    Chuck Baumgartner

    Hello

    I suggest you to follow the steps mentioned in the article below and let us know if the problem is solved or not.

    How to activate my MSF program for I could use more than 30 minutes at a time

    http://support.Microsoft.com/kb/925723

    Also check the links below.

    Frequently asked questions on how to enable Microsoft Games for Windows, streets and trips and Mappoint

    http://support.Microsoft.com/kb/927007

    Microsoft Flight Simulator X Service Pack 2 Readme

    http://www.Microsoft.com/products/games/FSInsider/downloads/pages/SP2-en-Readme.aspx

  • How to use more than 5 esxi hosts?

    If I try to use more than 5 guests esxi, that io parser gives a hint to use an other Analyzer io controller VM.

    So does that mean I have to use two io parser controller vms, i.e. to two Web sites that are not in sync?

    Page 6 of the IO parser guide:

    Maximum Configuration Analyzer of e/s

    Analyzer IO 1.5.1 has been tested up to the following configurations:

    With up to 128 worker virtual machines per ESX/ESXi host.

    With up to five ESX/ESXi hosts by controller i/o parser VM.

    To run the Analyzer of i/o tests with more than five ESX/ESXi hosts, we recommend using several VMs controller.

    Yes, you can use several controller - VMs

  • can I use more than 2 devices for 1 account of creative cloud?

    Hello.

    can I use more than 2 devices for 1 account creative cloud?

    I know that it is limited to 2 devices for activation / account.

    Thank you

    You can, but you must disconnect from Adobe Creative Cloud app of any one of the 2 previous computers, so that you can activate on other computers.

    Connect and disconnect activate Cloud Creative applications

  • How do I avoid the accumulation of color / opacity where two brush strokes overlap?  In other words, I want to use more than one path with the Paintbrush tool, but see no additive effect where strokes overlap.  What Miss me?

    How do I avoid the accumulation of color / opacity where two brush strokes overlap?  In other words, I want to use more than one path with the Paintbrush tool, but see no additive effect where strokes overlap. 5 Lightroom

    I use it all the time. Turn your opacity, density and traffic all 100%.

    Benjamin

  • Codes of the lesson can be used more than once?

    My students purchase the book for class and use the codes of the lesson in the back of the book. These codes may be used more than once? Sometimes my students buy used texts. Thank you!

    Yes, I use classroom in a book for Photoshop and InDesign. Thank you!

  • How to use more than one address at the same time?

    The Adobe server page that allows entry of a recipients address should not inform users how to add another address?  We separate them by semicolons? Commas?  Or is it still possible to use more than one address?

    Hi orison123,

    You talk about Adobe send? If Yes, you are absolutely right. Who should be written somewhere I had to double check and was able to send to multiple email addresses separated by commas or semicolons.

    Best,

    Sara

  • Configuration of 10g to use more than 1 CPU

    Hello experts,

    I have server Oracle 10.2.0.4 Enterprise Edition running on a Windows Server 2003 - Enterprise 64-bit.

    * The server has 4 Xeon processors *.

    We have a performance tool that we alert to an enrichment of the CPU.

    It seems that Oracle uses only a SINGLE processor.

    Is this normal in a 4-processor server?

    Can I make a configuration change to allow Oracle to use more than 1 CPU a CPU?

    Thank you very much. John

    You have several active sessions simultaneously (i.e. normal operation OLTP) relatively fast SQL statements running? Or if you use with a handful of active sessions that each runs relatively long SQL statements (i.e. normal DSS / operations data warehouse)?

    Unless you explicitly prevented Oracle to use several processors, it will use Fortunately each processor on the server. But if you have only one session active at a time and that the session is not running of the parallel operations, you would only end up using one of the available processors.

    Justin

  • How to export more than 100 points of waveform to Excel

    Hello world. Novice here.

    I am sure other people have my problem, but I don't know how the word it... and impossible to find a solution for it. Maybe I don't understand Labview enough to know what is happening.

    Here's what I do: I have a waveform, and I try to save the data in the worksheet.

    Problem: the CAP is on plots of 100 data (only what is shown on the chart). In other words, I get only the data for the chart hold right now.

    Here: I want more than that - EVERYTHING. If it starts from 0 to 50 years old, I want that all the points (increments of 10 ms, which is already done) on the excel file.

    Can you guys help me? How suck this story on the graph?

    I've attached my labview (a really simple) file, so you guys know where I am.

    Thank you guys!

    I probably go this route and use import TDMS Excel add-on

  • PlotYAppend to draw more than 1000 points

    Dear all

    When I tried to add more than 1,000 points for a WaveformPlot on a WaveformGraph, only the last 1000 points were plotted on the graph.

    Take into account that I use the method "PlotYAppend" to add points to the plot.

    Please advice because we want to increase the number of points to exceed 1000 points

    Best regards

    Mohammed,

    One of the properties of the wave shape curve is the ability of the story. The default value is 1000, you resize it to a higher value?

Maybe you are looking for