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 /**
 27  * @fileoverview Example file for a centroid implemented as an extension to JSXGraph. 
 28  */
 29  
 30 /**
 31  * Creates a new centroid point using three points and the given attributes.
 32  * @param {JXG.Board} board The board the triangle is put on.
 33  * @param {Array} parents Array of three points defining the triangle.
 34  * @param {Object} attributes Visual properties that are assigned to the constructed lines.
 35  * @type JXG.Point
 36  * @return An object of type JXG.Point;
 37  */
 38 JXG.createCentroid = function(board, parents, attributes) {
 39     
 40     if(JXG.isPoint(parents[0]) && JXG.isPoint(parents[1]) && JXG.isPoint(parents[2])) {
 41         var p1 = parents[0], p2 = parents[1], p3 = parents[2];
 42         
 43         var cent = board.create('point', [function () {return (p1.X() + p2.X() + p3.X())/3;}, function () {return (p1.Y() + p2.Y() + p3.Y())/3;}], attributes);
 44         p1.addChild(cent);
 45         p2.addChild(cent);
 46         p3.addChild(cent);
 47         cent.p1 = p1;
 48         cent.p2 = p2;
 49         cent.p3 = p3;
 50 
 51         cent.generatePolynom = function() {
 52             /* TODO generate polynom*/
 53         };
 54         
 55         return cent;
 56     } else {
 57         throw new Error("JSXGraph: Can't create centroid with parent types '" + (typeof parents[0]) + "' and '" + (typeof parents[1]) + "' and '" + (typeof parents[2]) + "'.");    
 58     }
 59 };
 60 
 61 JXG.JSXGraph.registerElement('centroid', JXG.createCentroid);
 62