~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to Externals/MathMLSolver/include/MathMLSolverFunctionExtensions.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
Import upstream version 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
Copyright (c) 2007 netAllied GmbH, Tettnang
 
3
 
 
4
Permission is hereby granted, free of charge, to any person
 
5
obtaining a copy of this software and associated documentation
 
6
files (the "Software"), to deal in the Software without
 
7
restriction, including without limitation the rights to use,
 
8
copy, modify, merge, publish, distribute, sublicense, and/or sell
 
9
copies of the Software, and to permit persons to whom the
 
10
Software is furnished to do so, subject to the following
 
11
conditions:
 
12
 
 
13
The above copyright notice and this permission notice shall be
 
14
included in all copies or substantial portions of the Software.
 
15
 
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 
18
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
19
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 
20
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
21
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
22
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
23
OTHER DEALINGS IN THE SOFTWARE.
 
24
******************************************************************************/
 
25
 
 
26
#ifndef __MATHML_SOLVER_FUNCTION_EXTENTIONS_H__
 
27
#define __MATHML_SOLVER_FUNCTION_EXTENTIONS_H__
 
28
 
 
29
#include "MathMLSolverPrerequisites.h"
 
30
#include "MathMLParserConstants.h"
 
31
 
 
32
#include <cmath>
 
33
 
 
34
#include "MathMLSymbolTable.h"
 
35
 
 
36
namespace MathML
 
37
{
 
38
    /** Forward Declarations. */
 
39
    class Error;
 
40
    class ErrorHandler;
 
41
 
 
42
    /** Extensions for additional functions for the solver */
 
43
    class _MATHML_SOLVER_EXPORT SolverFunctionExtentions
 
44
    {
 
45
    public:
 
46
        /** C-tor. */
 
47
        SolverFunctionExtentions()
 
48
        {}
 
49
 
 
50
        /** D-tor. */
 
51
        virtual ~SolverFunctionExtentions()
 
52
        {}
 
53
 
 
54
    private:
 
55
        /** Method for retrieving information about the sign of a value.
 
56
        @return Returns 1 for values > 0 or -1 for values < 0, otherwise 0.
 
57
        */
 
58
        inline static double sign ( double value )
 
59
        {
 
60
            if ( value > 0 )
 
61
            {
 
62
                return 1;
 
63
            }
 
64
 
 
65
            if ( value < 0 )
 
66
            {
 
67
                return -1;
 
68
            }
 
69
 
 
70
            return 0;
 
71
        }
 
72
 
 
73
    public:
 
74
        /** Adds all trigonometric and basic functions to the given symbolTable.
 
75
        @param symbolTable The symbol table for adding functions.
 
76
        */
 
77
        static void addAllExtensionFunctions( MathML::SymbolTable& symbolTable );
 
78
 
 
79
    public:
 
80
 
 
81
        //-------------------------------------------------------------------------------------------
 
82
        inline static void sin( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
83
        {
 
84
            result.setValue( ::sin( paramlist.at( 0 ).getDoubleValue() ) );
 
85
        }
 
86
 
 
87
        //-------------------------------------------------------------------------------------------
 
88
        inline static void cos( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
89
        {
 
90
            result.setValue( ::cos( paramlist.at( 0 ).getDoubleValue() ) );
 
91
        }
 
92
 
 
93
        //-------------------------------------------------------------------------------------------
 
94
        inline static void tan( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
95
        {
 
96
            result.setValue( ::tan( paramlist.at( 0 ).getDoubleValue() ) );
 
97
        }
 
98
 
 
99
        //-------------------------------------------------------------------------------------------
 
100
        inline static void abs( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
101
        {
 
102
            result.setValue( ( double ) ::abs( paramlist.at( 0 ).getDoubleValue() ) );
 
103
        }
 
104
 
 
105
        //-------------------------------------------------------------------------------------------
 
106
        inline static void logn( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
107
        {
 
108
            result.setValue( ::log( paramlist.at( 0 ).getDoubleValue() ) );
 
109
        }
 
110
 
 
111
        //-------------------------------------------------------------------------------------------
 
112
        inline static void exp( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
113
        {
 
114
            result.setValue( ::exp( paramlist.at( 0 ).getDoubleValue() ) );
 
115
        }
 
116
 
 
117
        //-------------------------------------------------------------------------------------------
 
118
        inline static void pow( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
119
        {
 
120
            result.setValue( ::pow( paramlist.at( 0 ).getDoubleValue(), paramlist.at( 1 ).getDoubleValue() ) );
 
121
        }
 
122
 
 
123
        /** Reciprocal value of cosinus ( 1 / cosinus ). */
 
124
        inline static void sec( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
125
        {
 
126
            double cosinus = ::cos( paramlist.at( 0 ).getDoubleValue() );
 
127
            result.setValue( 1. / cosinus );
 
128
        }
 
129
 
 
130
        /** Reciprocal value of sinus ( 1 / sinus ). */
 
131
        inline static void cosec( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
132
        {
 
133
            double sinus = ::sin( paramlist.at( 0 ).getDoubleValue() );
 
134
            result.setValue( 1. / sinus );
 
135
        }
 
136
 
 
137
        /** Reciprocal value of tangens ( 1 / tangens ). */
 
138
        inline static void cotan( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
139
        {
 
140
            double tangens = ::tan( paramlist.at( 0 ).getDoubleValue() );
 
141
            result.setValue( 1. / tangens );
 
142
        }
 
143
 
 
144
        /** Inverse function of sinus. */
 
145
        inline static void arcsin( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
146
        {
 
147
            double para = paramlist.at( 0 ).getDoubleValue();
 
148
            result.setValue( ::asin( para ) );
 
149
        }
 
150
 
 
151
        /** Inverse function of cosinus. */
 
152
        inline static void arccos( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
153
        {
 
154
            double para = paramlist.at( 0 ).getDoubleValue();
 
155
            result.setValue( ::acos( para ) );
 
156
        }
 
157
 
 
158
        /** Inverse function of tangens. */
 
159
        inline static void arctan( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
160
        {
 
161
            double para = paramlist.at( 0 ).getDoubleValue();
 
162
            result.setValue( ::atan( para ) );
 
163
        }
 
164
 
 
165
        /** Reciprocal value of secant ( arctan(x / sqrt(x * x - 1)) + sign(x - 1) * (2 * arctan(1)) ). */
 
166
        inline static void arcsec( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
167
        {
 
168
            double x = paramlist.at( 0 ).getDoubleValue();
 
169
            result.setValue( ::atan( ( double ) ( x / ::sqrt( x * x - 1 ) ) ) + sign( x - 1 ) * ( 2 * ::atan( ( double ) 1 ) ) );
 
170
        }
 
171
 
 
172
        /** Reciprocal value of cosecant ( arctan(x / sqrt(x * x - 1)) + (sign(x) - 1) * (2 * arctan(1)) ). */
 
173
        inline static void arccsc( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
174
        {
 
175
            double x = paramlist.at( 0 ).getDoubleValue();
 
176
            result.setValue( ::atan( ( double ) ( x / ::sqrt( x * x - 1 ) ) ) + ( sign( x ) - 1 ) * ( 2 * ::atan( ( double ) 1 ) ) );
 
177
        }
 
178
 
 
179
        /** Reciprocal value of cotangens ( arctan(x) + 2 * arctan(1) ). */
 
180
        inline static void arccotan( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
181
        {
 
182
            double x = paramlist.at( 0 ).getDoubleValue();
 
183
            result.setValue( ::atan( x ) + 2 * ::atan( ( double ) 1 ) );
 
184
        }
 
185
 
 
186
 
 
187
 
 
188
        /** Sinus hyperbolicus. */
 
189
        inline static void sinh( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
190
        {
 
191
            double para = paramlist.at( 0 ).getDoubleValue();
 
192
            result.setValue( ::sinh( para ) );
 
193
        }
 
194
 
 
195
        /** Cosinus hyperbolicus. */
 
196
        inline static void cosh( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
197
        {
 
198
            double para = paramlist.at( 0 ).getDoubleValue();
 
199
            result.setValue( ::cosh( para ) );
 
200
        }
 
201
 
 
202
        /** Tangens hyperbolicus. */
 
203
        inline static void tanh( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler)
 
204
        {
 
205
            double para = paramlist.at( 0 ).getDoubleValue();
 
206
            result.setValue( ::tanh( para ) );
 
207
        }
 
208
 
 
209
        /** Hyperbolicus of reciprocal value of cosinus ( 2 / (exp(x) + exp(-x)) ). */
 
210
        inline static void sech( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
211
        {
 
212
            double x = paramlist.at( 0 ).getDoubleValue();
 
213
            result.setValue( 2 / ( ::exp( x ) + ::exp( -x ) ) );
 
214
        }
 
215
 
 
216
        /** Hyperbolicus of reciprocal value of sinus ( 2 / (exp(x) - exp(-x)) ). */
 
217
        inline static void cosech( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
218
        {
 
219
            double x = paramlist.at( 0 ).getDoubleValue();
 
220
            result.setValue( 2 / ( ::exp( x ) - ::exp( -x ) ) );
 
221
        }
 
222
 
 
223
        /** Hyperbolicus of reciprocal value of tangens ( (exp(x) + exp(-x)) / (exp(x) - exp(-x)) ). */
 
224
        inline static void cotanh( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
225
        {
 
226
            double x = paramlist.at( 0 ).getDoubleValue();
 
227
            result.setValue( ( ::exp( x ) + ::exp( -x ) ) / ( ::exp( x ) - ::exp( -x ) ) );
 
228
        }
 
229
 
 
230
 
 
231
        /** Hyperbolicus of inverse function of sinus. ( log(x + sqrt(x * x + 1)) ) */
 
232
        inline static void arcsinh( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
233
        {
 
234
            double x = paramlist.at( 0 ).getDoubleValue();
 
235
            result.setValue( ::log( x + ::sqrt( x * x + 1 ) ) );
 
236
        }
 
237
 
 
238
        /** Hyperbolicus of inverse function of cosinus. ( log(x + sqrt(x * x - 1)) ) */
 
239
        inline static void arccosh( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
240
        {
 
241
            double x = paramlist.at( 0 ).getDoubleValue();
 
242
            result.setValue( ::log( x + ::sqrt( x * x - 1 ) ) );
 
243
        }
 
244
 
 
245
        /** Hyperbolicus of inverse function of tangens. ( log((1 + x) / (1 - x)) / 2 ) */
 
246
        inline static void arctanh( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
247
        {
 
248
            double x = paramlist.at( 0 ).getDoubleValue();
 
249
            result.setValue( ::log( ( 1 + x ) / ( 1 - x ) ) / 2 );
 
250
        }
 
251
 
 
252
        /** Hyperbolicus of reciprocal value of secant. ( log((sqrt(-x * x + 1) + 1) / x) ) */
 
253
        inline static void arcsech( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
254
        {
 
255
            double x = paramlist.at( 0 ).getDoubleValue();
 
256
            result.setValue( ::log( ( ::sqrt( -x * x + 1 ) + 1 ) / x ) );
 
257
        }
 
258
 
 
259
        /** Hyperbolicus of reciprocal value of cosecant. ( log((sign(x) * sqrt(x * x + 1) + 1) / x) ) */
 
260
        inline static void arccsch( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
261
        {
 
262
            double x = paramlist.at( 0 ).getDoubleValue();
 
263
            result.setValue( ::log( ( sign( x ) * ::sqrt( x * x + 1 ) + 1 ) / x ) );
 
264
        }
 
265
 
 
266
        /** Hyperbolicus of reciprocal value of cotangens. ( log((x + 1) / (x - 1)) / 2 ) */
 
267
        inline static void arccotanh( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
268
        {
 
269
            double x = paramlist.at( 0 ).getDoubleValue();
 
270
            result.setValue( ::log( ( x + 1 ) / ( x - 1 ) ) / 2 );
 
271
        }
 
272
 
 
273
 
 
274
 
 
275
        /** Modulo: Remaining of a / b. */
 
276
        inline static void rem( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
277
        {
 
278
            double para1 = paramlist.at( 0 ).getDoubleValue();
 
279
            double para2 = paramlist.at( 1 ).getDoubleValue();
 
280
            result.setValue( ( long ) para1 % ( long ) para2 );
 
281
        }
 
282
 
 
283
        /** GCD (greatest common divisor): see _gcd(..) -> eucidean algorithm. */
 
284
        inline static void gcd( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
285
        {
 
286
            double current = paramlist.at( 0 ).getDoubleValue();
 
287
 
 
288
            for ( unsigned int i = 1; i < paramlist.size(); ++i )
 
289
            {
 
290
                double paraI = paramlist.at( i ).getDoubleValue();
 
291
                current = _gcd( ( long ) paraI, ( long ) current );
 
292
            }
 
293
 
 
294
            result.setValue( current );
 
295
        }
 
296
 
 
297
        /** LCM (least common multiple): see _lcm(..) -> lcm(a,b) = (a * b) / gcd(a,b). */
 
298
        inline static void lcm( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
299
        {
 
300
            double current = paramlist.at( 0 ).getDoubleValue();
 
301
 
 
302
            for ( unsigned int i = 1; i < paramlist.size(); ++i )
 
303
            {
 
304
                double paraI = paramlist.at( i ).getDoubleValue();
 
305
                current = _lcm( paraI, current );
 
306
            }
 
307
 
 
308
            result.setValue( current );
 
309
        }
 
310
 
 
311
        //-------------------------------------------------------------------------------------------
 
312
        inline static void floor( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
313
        {
 
314
            double para = paramlist.at( 0 ).getDoubleValue();
 
315
            result.setValue( ::floor( para ) );
 
316
        }
 
317
 
 
318
        //-------------------------------------------------------------------------------------------
 
319
        inline static void ceiling( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
320
        {
 
321
            double para = paramlist.at( 0 ).getDoubleValue();
 
322
            result.setValue( ::ceil( para ) );
 
323
        }
 
324
 
 
325
        //-------------------------------------------------------------------------------------------
 
326
        inline static void min( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
327
        {
 
328
            double current = paramlist.at( 0 ).getDoubleValue();
 
329
 
 
330
            for ( unsigned int i = 1; i < paramlist.size(); ++i )
 
331
            {
 
332
                double paraI = paramlist.at( i ).getDoubleValue();
 
333
                current = std::min( current, paraI );
 
334
            }
 
335
 
 
336
            result.setValue( current );
 
337
        }
 
338
 
 
339
        //-------------------------------------------------------------------------------------------
 
340
        inline static void max( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
341
        {
 
342
            double current = paramlist.at( 0 ).getDoubleValue();
 
343
 
 
344
            for ( unsigned int i = 1; i < paramlist.size(); ++i )
 
345
            {
 
346
                double paraI = paramlist.at( i ).getDoubleValue();
 
347
                current = std::max( current, paraI );
 
348
            }
 
349
 
 
350
            result.setValue( current );
 
351
        }
 
352
 
 
353
        //-------------------------------------------------------------------------------------------
 
354
        static void factorial( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler );
 
355
        
 
356
        //-------------------------------------------------------------------------------------------
 
357
        inline static void root( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
358
        {
 
359
            double r = paramlist.at( 0 ).getDoubleValue();
 
360
            double x = paramlist.at( 1 ).getDoubleValue();
 
361
 
 
362
            if ( r == 2.0 )
 
363
            {
 
364
                result.setValue( std::sqrt( x ) );
 
365
            }
 
366
 
 
367
            else
 
368
            {
 
369
                result.setValue( ::pow( x, 1 / r ) );
 
370
            }
 
371
        }
 
372
 
 
373
        //-------------------------------------------------------------------------------------------
 
374
        inline static void log( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
375
        {
 
376
            double base = paramlist.at( 0 ).getDoubleValue();
 
377
            double x = paramlist.at( 1 ).getDoubleValue();
 
378
            result.setValue( std::log( x ) / std::log( base ) );
 
379
        }
 
380
 
 
381
        //-------------------------------------------------------------------------------------------
 
382
        inline static void _xor( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
383
        {
 
384
            bool a = paramlist.at( 0 ).getBoolValue();
 
385
            bool b = paramlist.at( 1 ).getBoolValue();
 
386
            result.setValue( ( bool ) ( a ^ b ) );
 
387
        }
 
388
 
 
389
 
 
390
        //-------------------------------------------------------------------------------------------
 
391
                /**
 
392
                @see sas(..)
 
393
                @return The side of the sas result.
 
394
                */
 
395
        inline static void sass( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
396
        {
 
397
            double para1 = paramlist.at( 0 ).getDoubleValue();
 
398
            double para2 = paramlist.at( 1 ).getDoubleValue();
 
399
            double para3 = paramlist.at( 2 ).getDoubleValue();
 
400
            SASResult sasRresult;
 
401
            sas( sasRresult, para1, para2, para3 );
 
402
            result.setValue( sasRresult.c );
 
403
        }
 
404
                /**
 
405
                @see sas(..)
 
406
                @return The side of the sas result.
 
407
                */
 
408
                inline static double sass(double a, double gamma, double b)
 
409
                {
 
410
                        SASResult sasRresult = sas( a, gamma, b );                      
 
411
                        return sasRresult.c;
 
412
                }
 
413
 
 
414
        /**
 
415
                @see sas(..)
 
416
                @return The alpha angle of the sas result.
 
417
                */
 
418
        inline static void sasa( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
419
        {
 
420
            double para1 = paramlist.at( 0 ).getDoubleValue();
 
421
            double para2 = paramlist.at( 1 ).getDoubleValue();
 
422
            double para3 = paramlist.at( 2 ).getDoubleValue();
 
423
            SASResult sasRresult;
 
424
            sas( sasRresult, para1, para2, para3 );
 
425
            result.setValue( sasRresult.alpha );
 
426
        }
 
427
 
 
428
                /**
 
429
                @see sas(..)
 
430
                @return The alpha angle of the sas result.
 
431
                */
 
432
                inline static double sasa(double a, double gamma, double b)
 
433
                {
 
434
                        SASResult sasRresult = sas( a, gamma, b );                      
 
435
                        return sasRresult.alpha;
 
436
                }
 
437
 
 
438
                /**
 
439
                @see sas(..)
 
440
                @return The alpha angle value of the sss result.
 
441
                */
 
442
        inline static void sssa( MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler )
 
443
        {
 
444
            double para1 = paramlist.at( 0 ).getDoubleValue();
 
445
            double para2 = paramlist.at( 1 ).getDoubleValue();
 
446
            double para3 = paramlist.at( 2 ).getDoubleValue();
 
447
            SSSResult sssResult;
 
448
            sss(sssResult, para1, para2, para3 );
 
449
            result.setValue( sssResult.alpha );
 
450
        }
 
451
                
 
452
                /**
 
453
                @see sas(..)
 
454
                @return The alpha angle value of the sss result.
 
455
                */
 
456
                inline static double sssa(double a, double b, double c)
 
457
                {
 
458
                        SSSResult sssResult = sss(a, b, c);
 
459
                        return sssResult.alpha;
 
460
                }
 
461
 
 
462
                /**
 
463
                @todo dof implementation
 
464
                @param i The index of the DOF to return the axis angle.
 
465
                @return The current axis angle of the specified DOF.
 
466
                */
 
467
                inline static void dof(MathML::AST::ConstantExpression& result, const ScalarList& paramlist, ErrorHandler* errorHandler)
 
468
                {                       
 
469
                        result.setValue(paramlist.at( 0 ).getDoubleValue());
 
470
                }
 
471
                
 
472
                /**
 
473
                @todo dof implementation
 
474
                @param i The index of the DOF to return the axis angle.
 
475
                @return The current axis angle of the specified DOF.
 
476
                */
 
477
                inline static double dof(unsigned int i)
 
478
                {                       
 
479
                        return i;
 
480
                }
 
481
 
 
482
 
 
483
    private:
 
484
        /** GCD (euclidean algorithm). */
 
485
        inline static long _gcd( long a, long b )
 
486
        {
 
487
            if ( b == 0 )
 
488
            {
 
489
                return a;
 
490
            }
 
491
 
 
492
            else
 
493
                return _gcd( b, ( a % b ) );
 
494
        }
 
495
 
 
496
        /** LCM (least common multiple): lcm(a,b) = (a * b) / gcd(a,b). */
 
497
        inline static double _lcm( double a, double b )
 
498
        {
 
499
            return ( a * b ) / _gcd( ( long ) a, ( long ) b );
 
500
        }
 
501
 
 
502
 
 
503
        //------------------------------------
 
504
        //--- typedefs for SSS, SAS methods
 
505
        //------------------------------------
 
506
 
 
507
        struct SASResult
 
508
        {
 
509
            double alpha;
 
510
            double beta;
 
511
            double c;
 
512
        };
 
513
 
 
514
        struct SSSResult
 
515
        {
 
516
            double alpha;
 
517
            double beta;
 
518
            double gamma;
 
519
        };
 
520
 
 
521
 
 
522
        /**
 
523
        * Trigonemtry function for not orthogonal triangles. Takes two sides and
 
524
        * one angle as input and calculates all missing data.
 
525
        * <ol>
 
526
        * <li>Calculates the opposite side (c) of the given angle gamma.</li>
 
527
        * <li>Calculates the angle alpha.</li>
 
528
        * <li>Calculates the angle beta.</li>
 
529
        * </ol>
 
530
        * 
 
531
        * @param result Result values by reference: c, alpha and beta
 
532
        * @param a in mm
 
533
        * @param gamma in rad
 
534
        * @param b in mm
 
535
        */
 
536
        inline static void sas( SASResult& result, double a, double gamma, double b )
 
537
        {
 
538
            result.c = ::sqrt( ::pow( a, 2 ) + ::pow( b, 2 ) - 2 * a * b * ::cos( gamma ) );
 
539
            result.alpha = ::asin( a * ::sin( gamma ) / result.c );
 
540
            result.beta = PI_NUMBER - result.alpha - gamma;
 
541
        }
 
542
 
 
543
                /**
 
544
                * Trigonemtry function for not orthogonal triangles. Takes two sides and
 
545
                * one angle as input and calculates all missing data.
 
546
                * <ol>
 
547
                * <li>Calculates the opposite side (c) of the given angle gamma.</li>
 
548
                * <li>Calculates the angle alpha.</li>
 
549
                * <li>Calculates the angle beta.</li>
 
550
                * </ol>
 
551
                * 
 
552
                * @param a in mm
 
553
                * @param gamma in rad
 
554
                * @param b in mm
 
555
                * @return Result values by value: c, alpha and beta
 
556
                */
 
557
                inline static SASResult sas(double a, double gamma, double b)
 
558
                {
 
559
                        SASResult result;
 
560
                        sas(result, a, gamma, b);
 
561
                        return result;
 
562
                }
 
563
 
 
564
        /**
 
565
        * Trigonemtry function for not orthogonal triangles. Takes three sides as
 
566
        * input and calculates all angles.
 
567
        * 
 
568
        * @param result Result values by reference: alpha, beta, and gamma
 
569
        * @param a first side in mm
 
570
        * @param b second side in mm
 
571
        * @param c third side in mm
 
572
        */
 
573
        inline static void sss( SSSResult& result, double a, double b, double c )
 
574
        {
 
575
            // alpha = acos( (b≤ + c≤ - a≤) / 2 * b * c )
 
576
            result.alpha = ::acos( ( ::pow( b, 2 ) + ::pow( c, 2 ) - ::pow( a, 2 ) ) / ( 2 * b * c ) );
 
577
            // beta = asin( b * sin(alpha) / a )
 
578
            result.beta = ::asin( b * ::sin( result.alpha ) / a );
 
579
            // gamma = PI - alpha - beta
 
580
            result.gamma = PI_NUMBER - result.alpha - result.beta;
 
581
        }
 
582
 
 
583
                /**
 
584
                * Trigonemtry function for not orthogonal triangles. Takes three sides as
 
585
                * input and calculates all angles.
 
586
                * 
 
587
                * @param a first side in mm
 
588
                * @param b second side in mm
 
589
                * @param c third side in mm
 
590
                * @return Result values by value: alpha, beta, and gamma
 
591
                */
 
592
                inline static SSSResult sss(double a, double b, double c)
 
593
                {
 
594
                        SSSResult result;
 
595
                        sss(result, a, b, c);
 
596
                        return result;
 
597
                }
 
598
    };
 
599
 
 
600
 
 
601
} // namespace MathML
 
602
 
 
603
#endif // __MATHML_SOLVER_FUNCTION_EXTENTIONS_H__