LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default Function for smooth curve on a chart

Knowing how the "smoothed line" charting option is created is useful for a
variety of estimation and presentation purposes. Brian Murphy has previously
identified a curve that matched but the code was given in Bezier coordinates
and not particularly transparent. It's actually fairly straightforward to set
up a spreadsheet to do this as described below, but it would be great to have
a simple VBA function if anyone has some spare time to write some easier code
for this?

In fact the curve matches a Catmull Rom spline, these are frequently used in
computer graphics and there are many references online. Given four points
A,B,C and D, the tangent vectors within the interval BC are set to half of AC
or BD with a limit on the lengths equal to 1.5 times the interval BC.
Repeating this procedure for each consecutive set of data points determines
all the points along the curve. At the endpoints the tangents just point
along the interval and can be set by using an extra point one interval length
away.

eg Consider this set of points:

x y
1 5
3 9
4 9
9 1
12 6

First add the extra points (-1,1) and (15,11) so that the same method can be
used to find all intervals. Taking the interval between (4,9) and (9,1) as an
example, the curve is given by

x(t): =SUM(t^{3,2,1,0}*M*{3;4;9;12})
y(t): =SUM(t^{3,2,1,0}*M*{9;9;1;6})

where t ranges between 0 and 1 and M is the matrix:

M = {-1,2,-1,0;3,-5,0,2;-3,4,1,0;1,-1,0,0}/2

The tangents are (3,4)/2 and (6,8)/2 which are both less than 1.5 times the
interval length: 1.5|(5,8)|.

This tangent condition holds everywhere except between (3,9) and (4,9) where
the longer tangent is L=5 times the interval length. An adjusted (cardinal)
matrix M' is used here instead:

M' = M - r{-1,2,-1,0;-1,1,0,0;1,-2,1,0;1,-1,0,0}

where r=0.5-0.75/L=0.35 in this case. In extreme cases there may be an
additional tweak that is used internally but by setting this r value
appropriately every test scenario could be matched to within the nearest
pixel even at maximum zoom.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create data for a smooth curve Snarf Charts and Charting in Excel 1 October 6th 08 02:24 PM
To have smooth curve using time scale catergory Sun Charts and Charting in Excel 7 August 9th 07 06:56 PM
How does Excel smooth chart data when smooth option is selected? Larry Charts and Charting in Excel 1 April 19th 07 05:40 AM
Fill in the blanks to smooth my projection curve Statistically Challenged Excel Discussion (Misc queries) 0 November 18th 06 03:40 PM
Generate a smooth curve from uneven data points in a "stepped" co. [email protected] Excel Worksheet Functions 1 December 29th 04 02:07 AM


All times are GMT +1. The time now is 09:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"