home *** CD-ROM | disk | FTP | other *** search
/ CICA 1994 September / CICA_Shareware_for_Windows_Walnut_Creek_September_1994.iso / win3 / excel / we0820.exe / CURVES.TXT < prev    next >
Text File  |  1993-08-19  |  13KB  |  307 lines

  1. ======================================================================
  2.   Microsoft(R) Product Support Services Application Note (Text File)
  3.               WE0820: GENERATING SMOOTH CURVES IN CHARTS
  4. ======================================================================
  5.                                                    Revision Date: 8/93
  6.                                                        1 Disk Included
  7.  
  8. The following information applies to Microsoft Excel for Windows(TM),
  9. version 4.0.
  10.  
  11. ----------------------------------------------------------------------
  12. | INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY     |
  13. | ACCOMPANY THIS DOCUMENT (collectively referred to as an Application |
  14. | Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER      |
  15. | EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED      |
  16. | WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR       |
  17. | PURPOSE. The user assumes the entire risk as to the accuracy and    |
  18. | the use of this Application Note. This Application Note may be      |
  19. | copied and distributed subject to the following conditions:  1) All |
  20. | text must be copied without modification and all pages must be      |
  21. | included;  2) If software is included, all files on the disk(s)     |
  22. | must be copied without modification (the MS-DOS(R)  utility         |
  23. | diskcopy is appropriate for this purpose);  3) All components of    |
  24. | this Application Note must be distributed together;  and  4) This   |
  25. | Application Note may not be distributed for profit.                 |
  26. |                                                                     |
  27. | Copyright (C) 1993 Microsoft Corporation.  All Rights Reserved.     |
  28. | Microsoft and MS-DOS are registered trademarks and Windows is a     |
  29. | trademark of Microsoft Corporation.                                 |
  30. | ------------------------------------------------------------------- |
  31.                                    
  32.  
  33. OVERVIEW
  34. ========
  35.  
  36. This Application Note includes two add-in macros that use the
  37. interpolation method to generate smooth curves in charts.
  38.                                    
  39.                                    
  40. INTRODUCTION
  41. ============
  42.  
  43. In Microsoft Excel 4.0, when you create an xy (scatter) chart, the
  44. series of xy data points generally do not form a smooth curve. Using a
  45. method called interpolation, you can generate a series of values based
  46. on a set of xy data points that, when plotted, appear as a smooth
  47. curve that connects your xy data points. Interpolation achieves this
  48. smooth-curve effect by joining together several smaller curves called
  49. splines.
  50.  
  51. The enclosed WE0820 disk includes two add-in macros, INTERPOL.XLA and
  52. BLEND.XLA, that work together to generate these interpolated values
  53. based on x and y data ranges that you specify. The INTERPOL.XLA macro
  54. uses a custom dialog box to prompt you for your input range
  55. information and allows you to specify how you want your data to be
  56. returned. Based on your specifications, BLEND.XLA calculates and
  57. returns the data points that will generate a smooth curve through the
  58. given arrays of x and y values. You also have the option to create a
  59. chart that displays the new values in a curve and the original values
  60. as data points.
  61.  
  62.   NOTE: When plotted, your x and y values can be in almost any form
  63.   (for example, your values can form one or more loops or rotate
  64.   through 90 degrees, and so on). In addition, if the original x and y
  65.   values change, the data returned by BLEND.XLA will automatically be
  66.   updated.
  67.   
  68. The following information explains how to install and use these add-in
  69. macros and then discusses their theoretical basis.
  70.                                    
  71.                                    
  72. INSTALLING AND USING THE MACROS
  73. ===============================
  74.  
  75. To install the add-in macro files
  76. ---------------------------------
  77.  
  78. 1. In File Manager, copy the BLEND.XLA and INTERPOL.XLA files from the
  79.    enclosed WE0820 disk to the LIBRARY subdirectory on your hard disk
  80.    (this subdirectory is located in the directory where you installed
  81.    Microsoft Excel).
  82.  
  83. 2. In Microsoft Excel, choose Open from the File menu. Select the
  84.    INTERPOL.XLA file and choose the OK button.
  85.  
  86. When you open the INTERPOL.XLA file, the BLEND.XLA file is
  87. automatically loaded and the Interpolate command is added to the Data
  88. menu.
  89.  
  90. To specify options in the Data Interpolate dialog box
  91. -----------------------------------------------------
  92.  
  93. When you choose Interpolate from the Data menu, the Data Interpolate
  94. box appears, prompting you for certain information. In this dialog
  95. box, you are requested to enter information about your existing data,
  96. and you are given options for how you want to present the data that
  97. the macro generates. Once you have entered the appropriate information
  98. in the dialog box, the macro will return a two-column vertical array
  99. of x and y values. These values are the additional data points you'll
  100. need to make a smooth curve.
  101.  
  102. The following tables explain what you should enter in each box and
  103. discuss the specific options you can select to control how the new
  104. data is displayed.
  105.  
  106.    In this box          Enter the range of
  107.    ---------------------------------------
  108.  
  109.    Known X Values       Your known x values
  110.    Known Y Values       Your known y values
  111.  
  112.     NOTE: Your data must consist of at least four x values and four y
  113.     values; these values can be in rows or columns.
  114.  
  115.    In this box          Enter the following
  116.    ----------------------------------------
  117.  
  118.    Output Reference     Specify the first cell in
  119.                         which the interpolated data
  120.                         will be pasted
  121.  
  122.     NOTE: If you select a cell that contains data or is located above
  123.     data that will be overwritten, you will receive an alert message.
  124.     When you choose OK in this alert dialog box, you will be returned
  125.     to the Data Interpolate dialog box to make another cell selection.
  126.  
  127. In the Number Of Intermediate Data Points box, you can specify the
  128. number of intermediate points you think you will need to generate a
  129. smooth curve--the initial value displayed for the number of
  130. intermediate points is calculated based on several factors, including
  131. screen resolution, printer resolution, and "smoothness" of the
  132. original data. In most cases, ten intermediate data points should be
  133. enough to generate a smooth curve.
  134.  
  135.    In this box         Enter the following
  136.    ---------------------------------------
  137.  
  138.    Number Of           The number of additional
  139.    Intermediate        data points between your
  140.    Data Points         original data points that
  141.                        you will need to generate
  142.                        a smooth curve
  143.  
  144. To control how your data will be displayed, use the options in the
  145. Options section of the dialog box.
  146.  
  147.    Select this option   To do this
  148.    -------------------------------
  149.  
  150.    Include Original     Include the xy values on
  151.    Points               which your interpolated
  152.                         data is based
  153.  
  154.    Create Chart         Create a chart with a
  155.                         smooth curve
  156.  
  157. When you select both of these options, the add-in macros work together
  158. to create a chart with two data series: one for the smooth curve that
  159. has a line style but no data point markers and one for the original
  160. data that has data point markers but no line style.
  161.  
  162.     NOTE: You can use the BLEND.XLA macro independent of INTERPOL.XLA
  163.     to return data points along your smooth curve. You can use the
  164.     Paste Function command on the Formula menu to paste this data to
  165.     your sheet. The function takes three arguments: the range
  166.     containing your x values, the range containing your y values, and
  167.     the number of intermediate points you want. To enter the formula,
  168.     you must have at least two cells selected (either columns or rows)
  169.     and you must enter it as an array formula by pressing
  170.     CTRL+SHIFT+ENTER.
  171.  
  172.  
  173.  
  174. USING THE INTERPOL.XLA AND BLEND.XLA MACROS WITH SAMPLE DATA
  175. ============================================================
  176.  
  177. The following sample data
  178.  
  179.    |   A   |  B
  180. -----------------
  181. 1  |   1      4
  182. 2  |   2      2
  183. 3  |   3      2
  184. 4  |   4      4
  185. 5  |   5      3
  186.  
  187. Figure 1-Sample Data
  188.  
  189. when plotted in a chart will resemble the following:
  190.  
  191. <chart deleted>
  192. Figure 2-Sample Data Plotted in a Chart
  193.  
  194. To generate a new xy (scatter) chart with a smooth curve that is based
  195. on the data in cells A1:B5, do the following:
  196.  
  197. 1. From the Data menu, choose Interpolate. In the startup message box,
  198.    choose OK.
  199.  
  200. 2. In the dialog box that is displayed, do the following:
  201.  
  202.    a. In the Known X Values box, type "$A$1:$A$5" (without the quotation
  203.       marks).
  204.  
  205.    b. In the Known Y Values box, type "$B$1:$B$5" (without the quotation
  206.       marks).
  207.  
  208.    c. In the Output Range box, type "$C$1" (without the quotation marks).
  209.  
  210.    d. In the Number Of Intermediate Points box, leave the value set to
  211.       10.
  212.  
  213.    e. Under Options, verify that Include Original Points and Create
  214.       Chart are both selected.
  215.  
  216. 3. Choose OK.
  217.  
  218. The following table shows the first 15 of 45 rows of the resulting
  219. data (the total number of rows will vary with the number of x and y
  220. values and the number of intermediate points that you specify).
  221.  
  222.        |     C     |    D     |    E
  223.     -----------------------------------
  224.     1  |         1          4      4
  225.     2  |  1.090909   3.735537      
  226.     3  |  1.181818   3.487603      
  227.     4  |  1.272727   3.256198      
  228.     5  |  1.363636   3.041322      
  229.     6  |  1.454545   2.842975      
  230.     7  |  1.545455   2.661157      
  231.     8  |  1.636364   2.495868      
  232.     9  |  1.727273   2.347107      
  233.    10  |  1.818182   2.214876      
  234.    11  |  1.909091   2.099174      
  235.    12  |         2          2      2
  236.    13  |  2.090909   1.917355      
  237.    14  |  2.181818    1.85124      
  238.    15  |  2.272727   1.801653      
  239.  
  240. Figure 3-Table of Intermediate Data Point Values
  241.  
  242. Based on these values, INTERPOL.XLA automatically creates the
  243. following chart:
  244.  
  245. <chart deleted>
  246. Figure 4-Interpolated Curve
  247.  
  248. In Figure 4, the line shows the interpolated curve, and the data point
  249. markers show the original xy values.
  250.                                    
  251.                                    
  252. THEORETICAL BASIS FOR THIS METHOD OF CREATING SMOOTH CURVES
  253. ===========================================================
  254.  
  255. This particular implementation of curve smoothing is defined as the
  256. construction of a smooth curve by the piecewise addition of linearly
  257. blended second order polynomials (Burger and Gilles 1992).
  258.  
  259. An explanation of this method is as follows: given any three non-
  260. singular points, it is possible to define a unique parabola that will
  261. pass through all three of them (Burger and Gilles 1992). (See Figure
  262. 5.)
  263.  
  264. <chart deleted>
  265. Figure 5-A Unique Parabola that Passes Through Three Given Points
  266.  
  267. To generate a curve through several points, parabolas are calculated
  268. for each set of three points (see Figure 6).
  269.  
  270. <chart deleted>
  271. Figure 6-The Unique Parabolas that Pass Through Each Set of Three
  272. Points
  273.  
  274. If the interpolated point we want to find lies to the left of <b>, or
  275. to the right of <e>, then the parabolic equation that passes through
  276. these points is used (See Figure 7).
  277.  
  278. <chart deleted>
  279. Figure 7-The End Conditions
  280.  
  281. For each intermediate section of the curve, the two parabolas that
  282. pass through each point are added together in proportion to how close
  283. they are to the original points (see Figure 8).
  284.  
  285. <chart deleted>
  286. Figure 8-Blending Curves 1 and 2
  287.  
  288. For instance, if the desired point lies between <b> and <c>, then the
  289. closer the point is to <b>, the more of curve 1 is used; and
  290. conversely, the closer the point is to <c>, the more of curve 2 is
  291. used. At point <b>, only curve 1 is used; at point <c>, only curve 2
  292. is used; and halfway between <b> and <c>, the interpolated point is
  293. the average of curves 1 and 2.
  294.  
  295. Continuing in this way, you can construct a smooth curve (see Figure
  296. 9).
  297.  
  298. <chart deleted>
  299. Figure 9-The Resulting Smooth Curve
  300.                                    
  301.                                    
  302. REFERENCES
  303. ==========
  304.  
  305. Burger, P., and Gilles, D. "Interactive Computer Graphics, Functional,
  306. Procedural and Device Level Methods," 276-277. Palo Alto: Addison
  307. Wesley, 1992.