Using more than 2 control points in Interpolater.Spline

Hello,
what I'm working on is a bouncing ball, I figured it might work controlling the interpolator to create a multiple control points using the spline. ( a function with x ^n^ , where n is the number of control points)
In a spline I can use only two control points, is there a way to make it use more than that, or do i have to use another way.
Thanks for all help.
Edited by: A.m.z on May 9, 2013 1:49 AM
Edited by: A.m.z on May 9, 2013 1:49 AM

Well, I guess it wasn't so hard - at least when there are libraries written by others to borrow from . . .
This interpolator requires the apache commons math 3.2 lib - you can download commons-math3-3.2-bin.zip from here:
http://commons.apache.org/proper/commons-math/download_math.cgi
Extract commons-math3-3.2.jar from the zip and put it on your class path.
This interpolator differs a little from the Interpolator.SPLINE interpolator 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 plots a curve of best fit directly 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 an example usage:
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); }
}Edited by: jsmith on May 11, 2013 5:58 AM

Similar Messages

  • Can I use more than one Apple ID on one device

    I have seen some answers to this type of question before but not that since the ios 6 so will ask again. My household shares an Apple ID and it has worked great as we have added devices and purchased apps.  My problem now is this, we have hit a point where I have work things on my iPad and iPhone that I really don't need to be shared with the whole family but it isn't a major deal or security risk. I don't want to give up the advantages of having the household ID.  Is there an easy way to have another ID on my iPad and switch between them without having major complications?  I am for the most part a techie so not afraid of these kind of things but I can't afford to lose everything right now and take the time to set it all back up so getting advice here.  Thanks in advance for any help you can give.

    You can use more than one apple id, but keep in mind that when apps need updating that you'll will need to sign in with correct credentials to update them.
    Share an apple id for the itunes and app stores, but keep your own for icloud, facetime and messages.
    Managing and Sharing multiple id's with your family
    http://www.macstories.net/stories/ios-5-icloud-tips-sharing-an-apple-id-with-you r-family/

  • Using more than one PU and PC for the same database

    I have a scenario described here: [http://www.seamframework.org/Community/UsingTwoParallelNestedConversationsWithParentAtomicConversation|http://www.seamframework.org/Community/UsingTwoParallelNestedConversationsWithParentAtomicConversation]
    which uses Seam, EJB3, JPA, Hibernate, Richfaces (modalPanel) and JSF.
    The question I have is the following:
    is there any negative consequence (memory consumption, performance hit, etc.) of using more than one persistence unit in the persistence.xml that points to the same EntityManagerFactory? I was thinking of having one PersistenceContext (Seam-managed PC - an extended PC which is conversation-scoped) which uses one PU and reserving the other PC for the modalPanel forms and backing beans (SFSBs).
    The reason I needed to use this solution/approach is so that when using Hibernate MANUAL flush with SMPC, I can achieve isolated synchronization of the PersistenceContext without updating values in the modalPanel forms and vice versa.
    Any tips on best practices or alternative solutions? thx.
    persistence.xml snippet:
       <persistence-unit name="boBETS">
          <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <jta-data-source>java:/boBETSDatasource</jta-data-source>
          <properties>
             <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
             <!-- <property name="hibernate.hbm2ddl.auto" value="validate"/>   -->
             <property name="hibernate.show_sql" value="true"/>
             <property name="hibernate.format_sql" value="true"/>
             <property name="hibernate.generate_statistics" value="true"/>
             <property name="jboss.entity.manager.factory.jndi.name" value="java:/boBETSEntityManagerFactory"/>
             <property name="hibernate.default_catalog" value="boBETS"/>
             <property name="hibernate.default_schema" value="dbo"/>
          </properties>
       </persistence-unit>
       <!-- using boBETS2 for ListValueParamAction for now! trying to isolate the em.flush() such that we can achieve atomic conversations for the
       base form as well as the popup form! -->   
       <persistence-unit name="boBETS2">
          <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <jta-data-source>java:/boBETSDatasource</jta-data-source>
          <properties>
             <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
             <!-- <property name="hibernate.hbm2ddl.auto" value="validate"/>   -->
             <property name="hibernate.show_sql" value="true"/>
             <property name="hibernate.format_sql" value="true"/>
             <property name="hibernate.generate_statistics" value="true"/>
             <property name="jboss.entity.manager.factory.jndi.name" value="java:/boBETS2EntityManagerFactory"/>
             <property name="hibernate.default_catalog" value="boBETS"/>
             <property name="hibernate.default_schema" value="dbo"/>
          </properties>
       </persistence-unit>What happens if I were to have 10 PUs and 10 PCs in the same app? Whether they're all pointing to same DB or not. What's the consequence of using "too many"?

    Yes, you can use multiple iCloud accounts in multiple User Accounts on one computer, but, as you know not multiple iTunes Match accounts. Keep in mind that the two services are not the same.
    Since you've posted your question to the iTunes Match forum, which it really doesn't pertain to, you might want to also post it to the iCloud on my Mac forum.

  • Use more than one Catalog from ECC 6

    At the configuration point in ECC 6 Materials Management ... Web Services: ID and Description I can describe more than one catalog URL address , but the user see in transaction ME21N or ME51N only that catalog with the default flag.
    Is it possible to use more than one catalog by these SAP standard functionality?

    Hi Markus,
    no!
    Unfortunatly, it is just posible to use ONE catalogue. At the beginning of development there was kept open the posibilitiy to make posible the use several catalogues in a later state.  That`s mainly the reason why more than one can be entered in customizing. But the functionality of using more than one was never developed later on.
    best regards,
    Angela

  • Use more than one DB in InfiniteInsight

    Hi,
    I want to know if is it possible to use more than one Data Base for create a Data Source in InfiniteInsgiht and how.
    Thank you very much.

    Hi Daniel and Edouard,
    I would first like to clarify one point: SAP InfiniteInsight can read data from the database directly.
    If your data are in a table or view, you can select the option "Use a File or a Database Table".
    With this same option, you can also enter a SQL query in "Data Set" :
    Now, as Edouard mentioned, you can also use Explorer to create a more complex dataset for your analysis.
    Technically, you will need to enter either one database connection or file as input for your different analyses. That being said, if you need to access 2 databases, (let's call them A and B) there is a way.
    It's called heterogeneous database system. You have to configure your database A to enable an access to database B.
    SAP InfiniteInsight will be connected to A which has access to B. Thus, you will be able to use data from 2 different databases. 
    I am unfortunately no a database specialist, I am not sure all DB enable this and the procedures might be complex.
    Hope this helps,
    Armelle

  • How can I use more than one Data Provider in my web Apps

    I am trying to use two different data provider in my web apps to run two different queries from the same table ,the data provider A is working correctly but when I attempt to run data provider B ,It display an error page ,here is the error message : Exception Details :javax.servlet.ServletEx ception
    java.lang.RuntimeException: java.sql.SQLException : Cannot connect .Both dataSourceName and url properties are null.

    Hi,
    You can use more than one data provider in your application. However if you have defined a dataprovider for a particular table already, and wish to bind a component, select the component and use its context menu to Bind to Data...

  • Can we use more than one Help Provider class in a same project in ADF11g

    Hi All,
    There are two help providers i want to use .They are "ResourceBundleHelpProvider","OHW Help Provider"
    In adf-settings.xml file
    <help-provider>
    <help-provider-class>oracle.adf.view.rich.help.ResourceBundleHelpProvider</help-provider-class>
    <property>
    <property-name>baseName</property-name>
    <value>com.symmetry.dashboard.panels.Help</value>
    </property>
    </help-provider>
    if try to register both help providers confliction occurs. Is it possible to register and use more than one help provider.?
    Thanks in advance.:)

    Thanks Frank,
    In adf-settings.xml file
    <help-provider>
    <help-provider-class>oracle.adf.view.rich.help.ResourceBundleHelpProvider</help-provider-class>
    <property>
    <property-name>baseName</property-name>
    <value>com.symmetry.dashboard.panels.Help</value>
    </property>
    </help-provider>
    <help-provider prefix="RB_">
    <help-provider-class>oracle.help.web.rich.helpProvider.OHWHelpProvider</help-provider-class>
    <property>
    <property-name>ohwConfigFileURL</property-name>
    <value>/myHelpset/config.xml</value>
    </property>
    <property>
    <property-name>baseURI</property-name>
    <value>http://127.0.0.1:7101/Dashboard_workflow/myHelpset/%3c/value>
    </property>
    </help-provider>
    I differentiated the help providers with the "prefix" attribute in the <help-provider> tag. So now confliction is not occuring between those.
    I used this prefix in the "helpTopicId" property of the adf components like "input text box" . I got the result. :)

  • Can I use more than one song in a slideshow?

    Can I use more than one song in a slideshow?  If so, how?  Thank you

    Dear Barbara B. 
    Thank you for your response.  Good idea about combining the songs in another program first.
    Thank you for your time and thoughts.

  • Can I use more than one SIM card in my iPhone if I buy it SIM free?

    Can I use more than one SIM card in my iPhone if I buy it SIM free?

    Sim free is not enough, you can use different sim if it's unlock.

  • Can I use more than one Apple ID for an Apple TV?

    I wanted to use more than one Apple ID account on my Apple TV, is that possible?

    Welcome to the Apple Community.
    You can only use one ID for purchasing from the Apple TV, but you can stream content from multiple libraries even though they have different ID's

  • Can u use more than one apple account on your device and itunes

    Can u use more than one apple account on your device and itunes

    Yes, but you have to logout of one, and login to the other.
    If it is an iPhone/iPad/iPod Touch and you buy apps on different accounts, when it comes time to update an app, you have to specify the password for the account used to acquirer the app. You change an iOS account via Settings -> Store -> Apple ID (tap on it), and start by logging out and then you can enter the other Id
    So it is possible, but it can also be a pain.

  • Can I use more than one iTunes account with my apple TV?

    Can I use more than one iTunes account with my apple TV?

    That depends what you mean. If you mean can you purchase from more than one iTunes account on the Apple TV, then the answer is no. If you mean can you stream from more than one iTunes library, which use different accounts, then the answer is yes, so long as they both use the same ID and password for homesharing.

  • HT1589 Can I use more than 1 device ie iPod and iPhone on the same iTunes account and have different music on them

    Can I use more than 1 device ie iPod and iPhone on the same iTunes account and have different music on them

    Yes. Use the option to sync with selected playlists on the music tab when your devices are connected.
    tt2

  • HT1206 how could I use more than 5 devices on the same apple ID

    Hi,
    I am trying to use more than 5 different devices (i-Phone's, MacBook Air, iMac, PC etc...) on the same Apple ID.
    The Apple ID is not allowing me to add more than 5.
    Do you have an idea what could I do?
    I would like to share all the devices in my Home network thru i-Tunes.
    Thnx

    You can only associate a maximum of 5 devices. There is no workaround for this.

  • I keep my library on an external hard drive 4TB.  It's full.  Can I use more than one hard drive to keep my library on?

    I keep my iTunes library on an external hard drive 4TB.  It's full.  Can I use more than one hard drive to keep my library on? Like two 4TB next to each other.

    Create a concatenated disk set
    Increase storage space with a concatenated RAID set (also called “Just a Bunch of Disks” or JBOD). If you need one large disk, but you have only several smaller disks, you can create a concatenated disk set to use several small disks as one large disk.
    Open Disk Utility, in the Utilities folder in Launchpad.
    Select one of the disks that you want in the set, and then click RAID.
    Click Add (+), and type a name for the RAID set.
    Choose a format from the Format pop-up menu. Usually you’ll choose the Mac OS Extended (Journaled) format.
    Choose Concatenated Disk Set from the RAID Type pop-up menu.
    Drag the disks you want to add to the set to the list on the right.
    Click Create.
    Exerpt from:
    Disk Utility 12.x: Create a RAID set - Apple - Support
    Note that the biggest CON to concatenated RAID configurations is vulnerability to volume failure. If either disk fails, the whole volume fails. If you choose this option, I would highly recommend backing up your music to a cloud service. There are very cheap per GB/storage, and some of the most reputable actually offer unlimited storage:
    Five Best Cloud Storage Providers - Lifehacker

Maybe you are looking for

  • Time Capsule set up Question(s)

    I am finally setting up my time capsule and I want to run a back up off of my Mac Book Pro. I have a wireless network already set thru the airport express. My time capsule is 802.aan Wi Fi Hard drive, the flat hard drive model (not the latest current

  • [Rookie] Some clarification on Dimension Table

    Hi! I am preparing for BW certification, and sorry to post this very basic query. On certification notes, I came accross a statement that says - "Dimension table contains link to fact table and SID table". I think this statement is wrong. Dimension t

  • Outlook 2013 send & receive is very slow or freezes

    Hello. I recently purchased Office 2013 to install on my new laptop at the beginning of February. Everything was working fine up until a couple weeks ago. I am having issues in Outlook 2013, specifically I am not getting emails or when I send emails

  • Creating login screens in java

    hello. this is james mcfadden. i am trying to create a login screen in java. the problem i have is this: i am completely new to GUI programming. i know that i have to use strings. the code shown below is incomplete and when i try to compile it i get

  • IDOC Serialization issue.

    Hi, I tried to do IDOC serialization using this blog /people/community.user/blog/2006/11/04/how-to-serialize-idoc-xml-messages-fed-into-xi But in this blog its says to create a queue processing rule using WE85 transaction. My system is not as WAS 6.4