public void showTrajectoryAndSpline ( ) { if ( t . getDimension ( ) == 2 ) { double [ ] xData = new double [ rotatedTrajectory . size ( ) ] ; double [ ] yData = new double [ rotatedTrajectory . size ( ) ] ; for ( int i = 0 ; i < rotatedTrajectory . size ( ) ; i ++ ) { xData [ i ] = rotatedTrajectory . get ( i ) . x ; yData [ i ] = rotatedTrajectory . get ( i ) . y ; } // Create Chart Chart chart = QuickChart . getChart ( "Spline+Track" , "X" , "Y" , "y(x)" , xData , yData ) ; //Add spline support points double [ ] subxData = new double [ splineSupportPoints . size ( ) ] ; double [ ] subyData = new double [ splineSupportPoints . size ( ) ] ; for ( int i = 0 ; i < splineSupportPoints . size ( ) ; i ++ ) { subxData [ i ] = splineSupportPoints . get ( i ) . x ; subyData [ i ] = splineSupportPoints . get ( i ) . y ; } Series s = chart . addSeries ( "Spline Support Points" , subxData , subyData ) ; s . setLineStyle ( SeriesLineStyle . NONE ) ; s . setSeriesType ( SeriesType . Line ) ; //ADd spline points int numberInterpolatedPointsPerSegment = 20 ; int numberOfSplines = spline . getN ( ) ; double [ ] sxData = new double [ numberInterpolatedPointsPerSegment * numberOfSplines ] ; double [ ] syData = new double [ numberInterpolatedPointsPerSegment * numberOfSplines ] ; double [ ] knots = spline . getKnots ( ) ; for ( int i = 0 ; i < numberOfSplines ; i ++ ) { double x = knots [ i ] ; double stopx = knots [ i + 1 ] ; double dx = ( stopx - x ) / numberInterpolatedPointsPerSegment ; for ( int j = 0 ; j < numberInterpolatedPointsPerSegment ; j ++ ) { sxData [ i * numberInterpolatedPointsPerSegment + j ] = x ; syData [ i * numberInterpolatedPointsPerSegment + j ] = spline . value ( x ) ; x += dx ; } } s = chart . addSeries ( "Spline" , sxData , syData ) ; s . setLineStyle ( SeriesLineStyle . DASH_DASH ) ; s . setMarker ( SeriesMarker . NONE ) ; s . setSeriesType ( SeriesType . Line ) ; //Show it new SwingWrapper ( chart ) . displayChart ( ) ; } }
Plots the rotated trajectory spline and support points .