00001
00002 /*---------------------------------------------------------------------------
00003 E.S.O.
00004 ----------------------------------------------------------------------------
00005 File name : poly2d.h
00006 Author : N. Devillard
00007 Created on : 22 Jun 1999
00008 Language : ANSI C
00009 Part of ECLIPSE library
00010 Description : 2D polynomial handling
00011 *--------------------------------------------------------------------------*/
00012
00013 /*
00014
00015 $Id: poly2d.h,v 1.3 2005/04/19 09:15:42 amodigli Exp $
00016 $Author: amodigli $
00017 $Date: 2005/04/19 09:15:42 $
00018 $Revision: 1.3 $
00019
00020 */
00021
00022 #ifndef _POLY2D_H_
00023 #define _POLY2D_H_
00024
00025 /*---------------------------------------------------------------------------
00026 Includes
00027 ---------------------------------------------------------------------------*/
00028
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032
00033 #include "ipow.h"
00034 #include "memory.h"
00035
00036
00037 /*---------------------------------------------------------------------------
00038 New types
00039 ---------------------------------------------------------------------------*/
00040
00041
00042 /*
00043 * The following structure defines a 2d polynomial. 'deg' is the highest
00044 * degree in the polynomial. 'nc' contains the number of coefficients
00045 * in px, py, and c.
00046 * 'px' and 'py' contain the powers of resp. x and y.
00047 * 'c' contains the coefficients themselves.
00048 * For example, if you want to store the following polynomial:
00049 * p(x,y) = p0 + p1.x + p2.y + p3.x.y + p4.x^2 + p5.y^2
00050 * You would have:
00051 * nc = 6 (from 0 to 5 incl.)
00052 * px contains: 0 1 0 1 2 0
00053 * py contains: 0 0 1 1 0 2
00054 * c contains: p0 p1 p2 p3 p4 p5
00055 * So that given x0 and y0, computing the polynomial is done with:
00056
00057 poly2d p ;
00058 int i ;
00059 double x0, y0, poly ;
00060
00061 poly = 0.00 ;
00062 for (i=0 ; i<p.nc ; i++) {
00063 poly += p.c[i] * ipow(x0, p.px[i]) * ipow(y0, p.py[i]) ;
00064 }
00065
00066 or simply:
00067 poly = poly2d_compute(&p, x0, y0);
00068
00069 */
00070
00071 typedef struct _2D_POLY_ {
00072 int nc ; /* number of coefficients in px, py, c */
00073 int * px ; /* powers of x */
00074 int * py ; /* powers of y */
00075 double * c ; /* polynomial coefficients */
00076 } poly2d ;
00077
00078
00079
00080
00081 /*---------------------------------------------------------------------------
00082 Function codes
00083 ---------------------------------------------------------------------------*/
00084
00085
00086 /*---------------------------------------------------------------------------
00087 Function : poly2d_compute()
00088 In : polynomial definition, values of x, y
00089 Out : double
00090 Job : compute the value of a 2d poly at a given point
00091 Notice : to compute several values in a row, use
00092 poly2d_compute_array()
00093 ---------------------------------------------------------------------------*/
00094
00095 double
00096 poly2d_compute(
00097 poly2d * p,
00098 double x,
00099 double y
00100 );
00101
00102
00103 /*---------------------------------------------------------------------------
00104 Function : poly2d_compute_array()
00105 In : polynomial definition, lists of x, y, # of values in each
00106 Out : fills up the z array with correct values
00107 returns 0 if Ok, -1 if error
00108 Job : compute the value of a 2d poly at a list of given points
00109 Notice : arrays x and y are untouched, but z is used as a
00110 return array and filled accordingly. z must have been
00111 allocated before calling this function.
00112 ---------------------------------------------------------------------------*/
00113
00114 int
00115 poly2d_compute_array(
00116 poly2d * p,
00117 double * x,
00118 double * y,
00119 double * z,
00120 int n
00121 );
00122
00123 /*---------------------------------------------------------------------------
00124 Function : poly2d_build_from_string()
00125 In : character string
00126 Out : newly allocated poly2d structure
00127 Job : build a polynomial from a character string
00128 Notice : the format of the string is the following
00129
00130 "dx dy c0 dx dy c1 ... dx dy cn"
00131 "int int double ... int int double"
00132 data are given through triplets. First and second indicate
00133 respectively the exponents of x and y. The third number is the
00134 polynomial coefficient associated to this (x,y) couple.
00135 Example:
00136
00137 to input the following polynomial in x and y:
00138 z = 12.0 + 24.0*x + 36.0*y + 10.0*x*y - 3.0*x^2 - 5.0*y^2
00139 you would provide the following string:
00140
00141 "0 0 12.0 1 0 24.0 0 1 36.0 1 1 10.0 2 0 -3.0 0 2 -5.0"
00142
00143 ---------------------------------------------------------------------------*/
00144
00145 poly2d * poly2d_build_from_string(const char * s);
00146
00147
00148
00149 /*---------------------------------------------------------------------------
00150 Function : poly2d_allocate()
00151 In : number of coefficients in the polynomial
00152 Out : pointer to newly allocated polynomial
00153 Job : allocate space under px, py, c
00154 Notice : free with poly2d_free()
00155 ---------------------------------------------------------------------------*/
00156
00157 poly2d * poly2d_allocate(int nc);
00158
00159
00160
00161 /*---------------------------------------------------------------------------
00162 Function : poly2d_free()
00163 In : pointer to poly2d to free
00164 Out : void
00165 Job : frees space allocated for px, py, and c
00166 Notice : frees the provided pointer also
00167 ---------------------------------------------------------------------------*/
00168
00169 /* <python> */
00170 void poly2d_free(poly2d * p);
00171 /* </python> */
00172
00173
00174 /*---------------------------------------------------------------------------
00175 Function : poly2d_print()
00176 In : pointer to allocated poly2d structure
00177 (optional) name of the poly2d to print out, provide
00178 NULL if you do not want to print it out.
00179 Out : displays the structure on stderr
00180 Job : print out a given poly2d structure on console
00181 Notice : for debugging purposes mainly
00182 ---------------------------------------------------------------------------*/
00183
00184 void poly2d_print(poly2d * p, char * name) ;
00185
00186 /* <python> */
00187 void poly2d_save(poly2d * p, char * name) ;
00188 /* </python> */
00189
00190 /*---------------------------------------------------------------------------
00191 Function : read_poly2d_from_table()
00192 In : table name
00193 Out : poly2d *
00194 Job : Read the 3 first columns of the table, they should be
00195 respectively px*, py*, and c*. Then return an allocated
00196 poly2d*
00197 Notice : used for the arc and startrace calibration tables.
00198 ---------------------------------------------------------------------------*/
00199
00200 poly2d *
00201 read_poly2d_from_table(
00202 char * filename) ;
00203
00204
00205
00206 #endif
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001