      1 /*
      2     Copyright 2008,2009
      3         Matthias Ehmann,
      4         Michael Gerhaeuser,
      5         Carsten Miller,
      6         Bianca Valentin,
      7         Alfred Wassermann,
      8         Peter Wilfahrt
      9
     10     This file is part of JSXGraph.
     11
     12     JSXGraph is free software: you can redistribute it and/or modify
     13     it under the terms of the GNU Lesser General Public License as published by
     14     the Free Software Foundation, either version 3 of the License, or
     15     (at your option) any later version.
     16
     17     JSXGraph is distributed in the hope that it will be useful,
     18     but WITHOUT ANY WARRANTY; without even the implied warranty of
     19     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     20     GNU Lesser General Public License for more details.
     21
     22     You should have received a copy of the GNU Lesser General Public License
     23     along with JSXGraph.  If not, see <http://www.gnu.org/licenses/>.
     24 */
     25
     26 JXG.extend(JXG.Board.prototype, /** @lends JXG.Board.prototype */ {
     27     angle: function(A, B, C){ return JXG.Math.Geometry.angle(A,B,C); },
     28     rad: function(A, B, C){ return JXG.Math.Geometry.rad(A,B,C); },
     29     distance: function(arr1, arr2){ return JXG.Math.Geometry.distance(arr1,arr2); },
     30     pow: function(a, b){ return JXG.Math.pow(a,b); },
     31     round: function(x, n){ return (x).toFixed(n); },
     32     cosh: function(x){ return JXG.Math.cosh(x); },
     33     sinh: function(x){ return JXG.Math.sinh(x); },
     34     sgn: function(x) { return (x==0 ? 0 : x/(Math.abs(x))); },
     35     D: function(f,obj){ return JXG.Math.Numerics.D(f,obj); },
     36     I: function(interval,f){ return JXG.Math.Numerics.I(interval,f); },
     37     root: function(f,x,obj){ return JXG.Math.Numerics.root(f,x,obj); },
     38     lagrangePolynomial: function(p){ return JXG.Math.Numerics.lagrangePolynomial(p); },
     39     neville: function(p){ return JXG.Math.Numerics.Neville(p); },
     40     riemannsum: function(f,n,type,start,end){ return JXG.Math.Numerics.riemannsum(f,n,type,start,end); },
     41
     42     abs: Math.abs,
     43     acos: Math.acos,
     44     asin: Math.asin,
     45     atan: Math.atan,
     46     ceil: Math.ceil,
     47     cos: Math.cos,
     48     exp: Math.exp,
     49     floor: Math.floor,
     50     log: Math.log,
     51     max: Math.max,
     52     min: Math.min,
     53     random: Math.random,
     54     sin: Math.sin,
     55     sqrt: Math.sqrt,
     56     tan: Math.tan,
     57     trunc: Math.ceil,
     58
     59     factorial: function(n){ return JXG.Math.factorial(n); },
     60     binomial: function(n,k){ return JXG.Math.binomial(n,k); },
     61
     62     getElement: function (el) {return JXG.getReference(this,el); },
     63
     64     /**
     65      * GUI interface
     66      **/
     67     intersectionOptions: ['point',[[JXG.OBJECT_CLASS_LINE,JXG.OBJECT_CLASS_LINE],[JXG.OBJECT_CLASS_LINE,JXG.OBJECT_CLASS_CIRCLE],
     68                                    [JXG.OBJECT_CLASS_CIRCLE,JXG.OBJECT_CLASS_CIRCLE]]],
     69     intersection: function(el1,el2,i,j){
     70         el1 = JXG.getReference(this,el1);
     71         el2 = JXG.getReference(this,el2);
     72         // curve - curve
     73         if (el1.elementClass==JXG.OBJECT_CLASS_CURVE &&
     74             el2.elementClass==JXG.OBJECT_CLASS_CURVE) {
     75             return function(){return JXG.Math.Geometry.meetCurveCurve(el1,el2,i,j,el1.board); };
     76         // arc - line   (arcs are of class curve, but are intersected like circles)
     77         } else if ((el1.type==JXG.OBJECT_TYPE_ARC && el2.elementClass==JXG.OBJECT_CLASS_LINE) ||
     78                    (el2.type==JXG.OBJECT_TYPE_ARC && el1.elementClass==JXG.OBJECT_CLASS_LINE)) {
     79             return function(){return JXG.Math.Geometry.meet(el1.stdform,el2.stdform,i,el1.board); };
     80         // curve - line (this includes intersections between conic sections and lines
     81         } else if ((el1.elementClass==JXG.OBJECT_CLASS_CURVE && el2.elementClass==JXG.OBJECT_CLASS_LINE)||
     82                    (el2.elementClass==JXG.OBJECT_CLASS_CURVE && el1.elementClass==JXG.OBJECT_CLASS_LINE)) {
     83             return function(){return JXG.Math.Geometry.meetCurveLine(el1,el2,i,el1.board); };
     84         // All other combinations of circles and lines
     85         } else {
     86             return function(){return JXG.Math.Geometry.meet(el1.stdform,el2.stdform,i,el1.board); };
     87         }
     88     }, //returns a single point of intersection
     89     intersectionFunc: function(el1,el2,i,j){ return this.intersection(el1,el2,i,j); },
     90
     91     /**
     92     * Intersectionof  circles and line
     93     */
     94     otherIntersection: function(el1,el2,el){
     95         el1 = JXG.getReference(this,el1);
     96         el2 = JXG.getReference(this,el2);
     97         return function(){
     98             var c = JXG.Math.Geometry.meet(el1.stdform,el2.stdform,0,el1.board);
     99             if (Math.abs(el.X()-c.usrCoords[1])>JXG.Math.eps ||
    100                 Math.abs(el.Y()-c.usrCoords[2])>JXG.Math.eps ||
    101                 Math.abs(el.Z()-c.usrCoords[0])>JXG.Math.eps) {
    102                 return c;
    103             } else {
    104                 return JXG.Math.Geometry.meet(el1.stdform,el2.stdform,1,el1.board);
    105             }
    106         };
    107     }, //returns a single point of intersection
    108
    109
    110     pointFunc: function(){return [null];},
    111     pointOptions: ['point',[[JXG.OBJECT_CLASS_POINT]]],
    112
    113     lineFunc: function(){return arguments;},
    114     lineOptions: ['line',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT]]],
    115
    116     linesegmentFunc: function(){return arguments;},
    117     linesegmentOptions: ['line',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT]]],
    118     linesegmentAtts: {straightFirst : false, straightLast : false },
    119
    120     arrowFunc: function(){return arguments;},
    121     arrowOptions: ['arrow',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT]]],
    122
    123     circleFunc: function(){return arguments;},
    124     circleOptions: ['circle',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT],[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_LINE],
    125                               [JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_CIRCLE]]],
    126
    127     arrowparallelOptions: ['arrowparallel',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_LINE]]],
    128     arrowparallelFunc: function(){return arguments;},
    129
    130     bisectorOptions: ['bisector',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT]]],
    131     bisectorFunc: function(){return arguments;},
    132
    133     circumcircleOptions: ['circumcircle',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT]]],
    134     circumcircleFunc: function(){return arguments;},
    135
    136     circumcirclemidpointOptions: ['circumcirclemidpoint',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT]]],
    137     circumcirclemidpointFunc: function(){return arguments;},
    138
    139     integralOptions: ['integral',[[]]],
    140     integralFunc: function(){return arguments;},
    141
    142     midpointOptions: ['midpoint',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT],[JXG.OBJECT_CLASS_LINE]]],
    143     midpointFunc: function(){return arguments;},
    144
    145     mirrorpointOptions: ['mirrorpoint',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT]]],
    146     mirrorpointFunc: function(){return arguments;},
    147
    148     normalOptions: ['normal',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_LINE]]],
    149     normalFunc: function(){return arguments;},
    150
    151     parallelOptions: ['parallel',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_LINE]]],
    152     parallelFunc: function(){return arguments;},
    153
    154     parallelpointOptions: ['parallelpoint',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_POINT]]],
    155     parallelpointFunc: function(){return arguments;},
    156
    157     perpendicularOptions: ['perpendicular',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_LINE]]],
    158     perpendicularFunc: function(){return arguments;},
    159
    160     perpendicularpointOptions: ['perpendicularpoint',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_LINE]]],
    161     perpendicularpointFunc: function(){return arguments;},
    162
    163     reflectionOptions: ['reflection',[[JXG.OBJECT_CLASS_POINT,JXG.OBJECT_CLASS_LINE]]],
    164     reflectionFunc: function(){return arguments;}
    165 });
    166
    167 // Some shortcuts
    168 JXG.Point.prototype.setPositionX = function (method, x) {
    169     var y = (method==JXG.COORDS_BY_USER)?this.coords.usrCoords[2]:this.coords.scrCoords[2];
    170     this.setPosition(method,x,y);
    171 };
    172 JXG.Point.prototype.setPositionY = function (method, y) {
    173     var x = (method==JXG.COORDS_BY_USER)?this.coords.usrCoords[1]:this.coords.scrCoords[1];
    174     this.setPosition(method,x,y);
    175 };
    176