1 /*
  2     Copyright 2008-2017
  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 dual licensed under the GNU LGPL or MIT License.
 13 
 14     You can redistribute it and/or modify it under the terms of the
 15 
 16       * GNU Lesser General Public License as published by
 17         the Free Software Foundation, either version 3 of the License, or
 18         (at your option) any later version
 19       OR
 20       * MIT License: https://github.com/jsxgraph/jsxgraph/blob/master/LICENSE.MIT
 21 
 22     JSXGraph is distributed in the hope that it will be useful,
 23     but WITHOUT ANY WARRANTY; without even the implied warranty of
 24     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 25     GNU Lesser General Public License for more details.
 26 
 27     You should have received a copy of the GNU Lesser General Public License and
 28     the MIT License along with JSXGraph. If not, see <http://www.gnu.org/licenses/>
 29     and <http://opensource.org/licenses/MIT/>.
 30  */
 31 
 32 
 33 /*global JXG: true, define: true*/
 34 /*jslint nomen: true, plusplus: true*/
 35 
 36 /* depends:
 37  jxg
 38  math/geometry
 39  math/math
 40  base/coords
 41  base/constants
 42  utils/type
 43   elements:
 44    point
 45    curve
 46    circumcentre
 47    transform
 48  */
 49 
 50 define([
 51     'jxg', 'math/geometry', 'math/math', 'math/statistics', 'base/coords', 'base/constants', 'utils/type', 'base/point', 'base/curve',
 52     'base/transformation', 'element/composition'
 53 ], function (JXG, Geometry, Mat, Statistics, Coords, Const, Type, Point, Curve, Transform, Compositions) {
 54 
 55     "use strict";
 56 
 57     /**
 58      * @class A circular sector is a subarea of the area enclosed by a circle. It is enclosed by two radii and an arc.
 59      * @pseudo
 60      * @name Sector
 61      * @augments JXG.Curve
 62      * @constructor
 63      * @type JXG.Curve
 64      * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
 65      *
 66      * First possiblity of input parameters are:
 67      * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p1 A sector is defined by three points: The sector's center <tt>p1</tt>,
 68      * a second point <tt>p2</tt> defining the radius and a third point <tt>p3</tt> defining the angle of the sector. The
 69      * Sector is always drawn counter clockwise from <tt>p2</tt> to <tt>p3</tt>
 70      *
 71      * Second possibility of input parameters are:
 72      * @param {JXG.Line_JXG.Line_array,number_array,number_number,function} line, line2, coords1 or direction1, coords2 or direction2, radius The sector is defined by two lines.
 73      * The two legs which define the sector are given by two coordinates arrays which are project initially two the two lines or by two directions (+/- 1).
 74      * The last parameter is the radius of the sector.
 75      *
 76      *
 77      * @example
 78      * // Create a sector out of three free points
 79      * var p1 = board.create('point', [1.5, 5.0]),
 80      *     p2 = board.create('point', [1.0, 0.5]),
 81      *     p3 = board.create('point', [5.0, 3.0]),
 82      *
 83      *     a = board.create('sector', [p1, p2, p3]);
 84      * </pre><div class="jxgbox" id="49f59123-f013-4681-bfd9-338b89893156" style="width: 300px; height: 300px;"></div>
 85      * <script type="text/javascript">
 86      * (function () {
 87      *   var board = JXG.JSXGraph.initBoard('49f59123-f013-4681-bfd9-338b89893156', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
 88      *     p1 = board.create('point', [1.5, 5.0]),
 89      *     p2 = board.create('point', [1.0, 0.5]),
 90      *     p3 = board.create('point', [5.0, 3.0]),
 91      *
 92      *     a = board.create('sector', [p1, p2, p3]);
 93      * })();
 94      * </script><pre>
 95      *
 96      * @example
 97      * // Create a sector out of two lines, two directions and a radius
 98      * var p1 = board.create('point', [-1, 4]),
 99      *  p2 = board.create('point', [4, 1]),
100      *  q1 = board.create('point', [-2, -3]),
101      *  q2 = board.create('point', [4,3]),
102      *
103      *  li1 = board.create('line', [p1,p2], {strokeColor:'black', lastArrow:true}),
104      *  li2 = board.create('line', [q1,q2], {lastArrow:true}),
105      *
106      *  sec1 = board.create('sector', [li1, li2, [5.5, 0], [4, 3], 3]),
107      *  sec2 = board.create('sector', [li1, li2, 1, -1, 4]);
108      *
109      * </pre><div class="jxgbox" id="bb9e2809-9895-4ff1-adfa-c9c71d50aa53" style="width: 300px; height: 300px;"></div>
110      * <script type="text/javascript">
111      * (function () {
112      *   var board = JXG.JSXGraph.initBoard('bb9e2809-9895-4ff1-adfa-c9c71d50aa53', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
113      *     p1 = board.create('point', [-1, 4]),
114      *     p2 = board.create('point', [4, 1]),
115      *     q1 = board.create('point', [-2, -3]),
116      *     q2 = board.create('point', [4,3]),
117      *
118      *     li1 = board.create('line', [p1,p2], {strokeColor:'black', lastArrow:true}),
119      *     li2 = board.create('line', [q1,q2], {lastArrow:true}),
120      *
121      *     sec1 = board.create('sector', [li1, li2, [5.5, 0], [4, 3], 3]),
122      *     sec2 = board.create('sector', [li1, li2, 1, -1, 4]);
123      * })();
124      * </script><pre>
125      */
126     JXG.createSector = function (board, parents, attributes) {
127         var el, i, attr,
128             type = 'invalid',
129             s, v,
130             attrPoints = ['center', 'radiuspoint', 'anglepoint'],
131             points;
132 
133         // Three points?
134         if (parents[0].elementClass === Const.OBJECT_CLASS_LINE &&
135                 parents[1].elementClass === Const.OBJECT_CLASS_LINE &&
136                 (Type.isArray(parents[2]) || Type.isNumber(parents[2])) &&
137                 (Type.isArray(parents[3]) || Type.isNumber(parents[3])) &&
138                 (Type.isNumber(parents[4]) || Type.isFunction(parents[4]))) {
139 
140             type = '2lines';
141 
142         } else {
143             points = Type.providePoints(board, parents, attributes, 'sector', attrPoints);
144             if (points === false) {
145                 throw new Error("JSXGraph: Can't create Sector with parent types '" +
146                     (typeof parents[0]) + "' and '" + (typeof parents[1]) + "' and '" +
147                     (typeof parents[2]) + "'.");
148             }
149 
150             type = '3points';
151         }
152 
153         attr = Type.copyAttributes(attributes, board.options, 'sector');
154         el = board.create('curve', [[0], [0]], attr);
155         el.type = Const.OBJECT_TYPE_SECTOR;
156         el.elType = 'sector';
157 
158         if (type === '2lines') {
159             el.Radius = function () {
160                 return Type.evaluate(parents[4]);
161             };
162 
163             el.line1 = board.select(parents[0]);
164             el.line2 = board.select(parents[1]);
165 
166             el.line1.addChild(el);
167             el.line2.addChild(el);
168             el.setParents(parents);
169 
170             el.point1 = {visProp: {}};
171             el.point2 = {visProp: {}};
172             el.point3 = {visProp: {}};
173 
174             /* Intersection point */
175             s = Geometry.meetLineLine(el.line1.stdform, el.line2.stdform, 0, board);
176 
177             if (Type.isArray(parents[2])) {
178                 /* project p1 to l1 */
179                 if (parents[2].length === 2) {
180                     parents[2] = [1].concat(parents[2]);
181                 }
182                 /*
183                 v = [0, el.line1.stdform[1], el.line1.stdform[2]];
184                 v = Mat.crossProduct(v, parents[2]);
185                 v = Geometry.meetLineLine(v, el.line1.stdform, 0, board);
186                 */
187                 v = Geometry.projectPointToLine({coords: {usrCoords: parents[2]}}, el.line1, board);
188                 v = Statistics.subtract(v.usrCoords, s.usrCoords);
189                 el.direction1 = (Mat.innerProduct(v, [0, el.line1.stdform[2], -el.line1.stdform[1]], 3) >= 0) ? +1 : -1;
190             } else {
191                 el.direction1 = (parents[2] >= 0) ? 1 : -1;
192             }
193 
194             if (Type.isArray(parents[3])) {
195                 /* project p2 to l2 */
196                 if (parents[3].length === 2) {
197                     parents[3] = [1].concat(parents[3]);
198                 }
199                 /*
200                 v = [0, el.line2.stdform[1], el.line2.stdform[2]];
201                 v = Mat.crossProduct(v, parents[3]);
202                 v = Geometry.meetLineLine(v, el.line2.stdform, 0, board);
203                 */
204                 v = Geometry.projectPointToLine({coords: {usrCoords: parents[3]}}, el.line2, board);
205                 v = Statistics.subtract(v.usrCoords, s.usrCoords);
206                 el.direction2 = (Mat.innerProduct(v, [0, el.line2.stdform[2], -el.line2.stdform[1]], 3) >= 0) ? +1 : -1;
207             } else {
208                 el.direction2 = (parents[3] >= 0) ? 1 : -1;
209             }
210 
211             el.updateDataArray = function () {
212                 var r, l1, l2,
213                     A = [0, 0, 0],
214                     B = [0, 0, 0],
215                     C = [0, 0, 0],
216                     ar;
217 
218                 l1 = this.line1;
219                 l2 = this.line2;
220 
221                 // Intersection point of the lines
222                 B = Mat.crossProduct(l1.stdform, l2.stdform);
223 
224                 if (Math.abs(B[0]) > Mat.eps * Mat.eps) {
225                     B[1] /= B[0];
226                     B[2] /= B[0];
227                     B[0] /= B[0];
228                 }
229                 // First point
230                 r = this.direction1 * this.Radius();
231                 A = Statistics.add(B, [0, r * l1.stdform[2], -r * l1.stdform[1]]);
232 
233                 // Second point
234                 r = this.direction2 * this.Radius();
235                 C = Statistics.add(B, [0, r * l2.stdform[2], -r * l2.stdform[1]]);
236 
237                 this.point2.coords = new Coords(Const.COORDS_BY_USER, A, el.board);
238                 this.point1.coords = new Coords(Const.COORDS_BY_USER, B, el.board);
239                 this.point3.coords = new Coords(Const.COORDS_BY_USER, C, el.board);
240 
241                 if (Math.abs(A[0]) < Mat.eps || Math.abs(B[0]) < Mat.eps || Math.abs(C[0]) < Mat.eps) {
242                     this.dataX = [NaN];
243                     this.dataY = [NaN];
244                     return;
245                 }
246 
247                 ar = Geometry.bezierArc(A, B, C, true, 1);
248 
249                 this.dataX = ar[0];
250                 this.dataY = ar[1];
251 
252                 this.bezierDegree = 3;
253             };
254 
255             el.methodMap = JXG.deepCopy(el.methodMap, {
256                 radius: 'getRadius',
257                 getRadius: 'getRadius',
258                 setRadius: 'setRadius'
259             });
260 
261             el.prepareUpdate().update();
262 
263         // end '2lines'
264 
265         } else if (type === '3points') {
266 
267             /**
268             * Midpoint of the sector.
269             * @memberOf Sector.prototype
270             * @name point1
271             * @type JXG.Point
272             */
273             el.point1 = points[0];
274 
275             /**
276             * This point together with {@link Sector#point1} defines the radius..
277             * @memberOf Sector.prototype
278             * @name point2
279             * @type JXG.Point
280             */
281             el.point2 = points[1];
282 
283             /**
284             * Defines the sector's angle.
285             * @memberOf Sector.prototype
286             * @name point3
287             * @type JXG.Point
288             */
289             el.point3 = points[2];
290 
291             /* Add arc as child to defining points */
292             el.point1.addChild(el);
293             el.point2.addChild(el);
294             el.point3.addChild(el);
295 
296             // useDirection is necessary for circumCircleSectors
297             el.useDirection = attributes.usedirection;
298             el.setParents(points);
299 
300             /**
301             * Defines the sectors orientation in case of circumCircleSectors.
302             * @memberOf Sector.prototype
303             * @name point4
304             * @type JXG.Point
305             */
306             if (Type.exists(points[3])) {
307                 el.point4 = points[3];
308                 el.point4.addChild(el);
309             }
310 
311             el.methodMap = JXG.deepCopy(el.methodMap, {
312                 arc: 'arc',
313                 center: 'center',
314                 radiuspoint: 'radiuspoint',
315                 anglepoint: 'anglepoint',
316                 radius: 'getRadius',
317                 getRadius: 'getRadius',
318                 setRadius: 'setRadius'
319             });
320 
321             /**
322             * documented in JXG.Curve
323             * @ignore
324             */
325             el.updateDataArray = function () {
326                 var ar, det, p0c, p1c, p2c,
327                     A = this.point2,
328                     B = this.point1,
329                     C = this.point3,
330                     phi, sgn = 1,
331                     vp_s = Type.evaluate(this.visProp.selection);
332 
333                 if (!A.isReal || !B.isReal || !C.isReal) {
334                     this.dataX = [NaN];
335                     this.dataY = [NaN];
336                     return;
337                 }
338 
339                 phi = Geometry.rad(A, B, C);
340                 if ((vp_s === 'minor' && phi > Math.PI) ||
341                         (vp_s === 'major' && phi < Math.PI)) {
342                     sgn = -1;
343                 }
344 
345                 // This is true for circumCircleSectors. In that case there is
346                 // a fourth parent element: [midpoint, point1, point3, point2]
347                 if (this.useDirection && Type.exists(this.point4)) {
348                     p0c = this.point2.coords.usrCoords;
349                     p1c = this.point4.coords.usrCoords;
350                     p2c = this.point3.coords.usrCoords;
351                     det = (p0c[1] - p2c[1]) * (p0c[2] - p1c[2]) - (p0c[2] - p2c[2]) * (p0c[1] - p1c[1]);
352 
353                     if (det >= 0.0) {
354                         C = this.point2;
355                         A = this.point3;
356                     }
357                 }
358 
359                 A = A.coords.usrCoords;
360                 B = B.coords.usrCoords;
361                 C = C.coords.usrCoords;
362 
363                 ar = Geometry.bezierArc(A, B, C, true, sgn);
364 
365                 this.dataX = ar[0];
366                 this.dataY = ar[1];
367                 this.bezierDegree = 3;
368             };
369 
370             /**
371             * Returns the radius of the sector.
372             * @memberOf Sector.prototype
373             * @name Radius
374             * @function
375             * @returns {Number} The distance between {@link Sector#point1} and {@link Sector#point2}.
376             */
377             el.Radius = function () {
378                 return this.point2.Dist(this.point1);
379             };
380 
381             attr = Type.copyAttributes(attributes, board.options, 'sector', 'arc');
382             attr.withLabel = false;
383             attr.name += '_arc';
384             el.arc = board.create('arc', [el.point1, el.point2, el.point3], attr);
385             el.addChild(el.arc);
386         }   // end '3points'
387 
388         el.center = el.point1;
389         el.radiuspoint = el.point2;
390         el.anglepoint = el.point3;
391 
392         // Default hasPoint method. Documented in geometry element
393         el.hasPointCurve = function (x, y) {
394             var angle, alpha, beta,
395                 prec,
396                 checkPoint = new Coords(Const.COORDS_BY_SCREEN, [x, y], this.board),
397                 r = this.Radius(),
398                 dist = this.center.coords.distance(Const.COORDS_BY_USER, checkPoint),
399                 has,
400                 vp_s = Type.evaluate(this.visProp.selection);
401 
402             prec = this.board.options.precision.hasPoint / Math.min(this.board.unitX, this.board.unitY);
403             has = (Math.abs(dist - r) < prec);
404             if (has) {
405                 angle = Geometry.rad(this.point2, this.center, checkPoint.usrCoords.slice(1));
406                 alpha = 0;
407                 beta = Geometry.rad(this.point2, this.center, this.point3);
408 
409                 if ((vp_s === 'minor' && beta > Math.PI) ||
410                         (vp_s === 'major' && beta < Math.PI)) {
411                     alpha = beta;
412                     beta = 2 * Math.PI;
413                 }
414 
415                 if (angle < alpha || angle > beta) {
416                     has = false;
417                 }
418             }
419 
420             return has;
421         };
422 
423         /**
424         * Checks whether (x,y) is within the area defined by the sector.
425         * @memberOf Sector.prototype
426         * @name hasPointSector
427         * @function
428         * @param {Number} x Coordinate in x direction, screen coordinates.
429         * @param {Number} y Coordinate in y direction, screen coordinates.
430         * @returns {Boolean} True if (x,y) is within the sector defined by the arc, False otherwise.
431         */
432         el.hasPointSector = function (x, y) {
433             var angle,
434                 checkPoint = new Coords(Const.COORDS_BY_SCREEN, [x, y], this.board),
435                 r = this.Radius(),
436                 dist = this.point1.coords.distance(Const.COORDS_BY_USER, checkPoint),
437                 alpha,
438                 beta,
439                 has = (dist < r),
440                 vp_s = Type.evaluate(this.visProp.selection);
441 
442             if (has) {
443                 angle = Geometry.rad(this.radiuspoint, this.center, checkPoint.usrCoords.slice(1));
444                 alpha = 0.0;
445                 beta = Geometry.rad(this.radiuspoint, this.center, this.anglepoint);
446 
447                 if ((vp_s === 'minor' && beta > Math.PI) ||
448                         (vp_s === 'major' && beta < Math.PI)) {
449                     alpha = beta;
450                     beta = 2 * Math.PI;
451                 }
452                 //if (angle > Geometry.rad(this.point2, this.point1, this.point3)) {
453                 if (angle < alpha || angle > beta) {
454                     has = false;
455                 }
456             }
457             return has;
458         };
459 
460         el.hasPoint = function (x, y) {
461             if (Type.evaluate(this.visProp.highlightonsector) ||
462                     Type.evaluate(this.visProp.hasinnerpoints)) {
463                 return this.hasPointSector(x, y);
464             }
465 
466             return this.hasPointCurve(x, y);
467         };
468 
469         // documented in GeometryElement
470         el.getTextAnchor = function () {
471             return this.point1.coords;
472         };
473 
474         // documented in GeometryElement
475         // this method is very similar to arc.getLabelAnchor()
476         // there are some additions in the arc version though, mainly concerning
477         // "major" and "minor" arcs. but maybe these methods can be merged.
478         el.getLabelAnchor = function () {
479             var coords, vecx, vecy, len,
480                 angle = Geometry.rad(this.point2, this.point1, this.point3),
481                 dx = 13 / this.board.unitX,
482                 dy = 13 / this.board.unitY,
483                 p2c = this.point2.coords.usrCoords,
484                 pmc = this.point1.coords.usrCoords,
485                 bxminusax = p2c[1] - pmc[1],
486                 byminusay = p2c[2] - pmc[2],
487                 vp_s = Type.evaluate(this.visProp.selection);
488 
489             // If this is uncommented, the angle label can not be dragged
490             //if (Type.exists(this.label)) {
491             //    this.label.relativeCoords = new Coords(Const.COORDS_BY_SCREEN, [0, 0], this.board);
492             //}
493 
494             if ((vp_s === 'minor' && angle > Math.PI) ||
495                     (vp_s === 'major' && angle < Math.PI)) {
496                 angle = -(2 * Math.PI - angle);
497             }
498 
499             coords = new Coords(Const.COORDS_BY_USER, [
500                 pmc[1] + Math.cos(angle * 0.5) * bxminusax - Math.sin(angle * 0.5) * byminusay,
501                 pmc[2] + Math.sin(angle * 0.5) * bxminusax + Math.cos(angle * 0.5) * byminusay
502             ], this.board);
503 
504             vecx = coords.usrCoords[1] - pmc[1];
505             vecy = coords.usrCoords[2] - pmc[2];
506 
507             len = Math.sqrt(vecx * vecx + vecy * vecy);
508             vecx = vecx * (len + dx) / len;
509             vecy = vecy * (len + dy) / len;
510 
511             return new Coords(Const.COORDS_BY_USER, [pmc[1] + vecx, pmc[2] + vecy], this.board);
512         };
513 
514         /**
515          * Overwrite the Radius method of the sector.
516          * Used in {@link GeometryElement#setAttribute}.
517          * @param {Number, Function} value New radius.
518          */
519         el.setRadius = function (value) {
520             el.Radius = function () {
521                 return Type.evaluate(value);
522             };
523         };
524 
525         /**
526          * @deprecated
527          * @ignore
528          */
529         el.getRadius = function () {
530             JXG.deprecated('Sector.getRadius()', 'Sector.Radius()');
531             return this.Radius();
532         };
533 
534         /**
535          * Moves the sector by the difference of two coordinates.
536          * @param {Number} method The type of coordinates used here. Possible values are {@link JXG.COORDS_BY_USER} and {@link JXG.COORDS_BY_SCREEN}.
537          * @param {Array} coords coordinates in screen/user units
538          * @param {Array} oldcoords previous coordinates in screen/user units
539          * @returns {JXG.Curve} this element
540          */
541         if (type === '3points') {
542             el.setPositionDirectly = function (method, coords, oldcoords) {
543                 var dc, t, i, len,
544                     c = new Coords(method, coords, this.board),
545                     oldc = new Coords(method, oldcoords, this.board);
546 
547                 if (!el.point1.draggable() || !el.point2.draggable() || !el.point3.draggable()) {
548                     return this;
549                 }
550 
551                 dc = Statistics.subtract(c.usrCoords, oldc.usrCoords);
552                 t = this.board.create('transform', dc.slice(1), {type: 'translate'});
553                 t.applyOnce([el.point1, el.point2, el.point3]);
554 
555                 return this;
556             };
557         }
558 
559         el.prepareUpdate().update();
560 
561         return el;
562     };
563 
564     JXG.registerElement('sector', JXG.createSector);
565 
566 
567     /**
568      * @class A circumcircle sector is different from a {@link Sector} mostly in the way the parent elements are interpreted.
569      * At first, the circum centre is determined from the three given points. Then the sector is drawn from <tt>p1</tt> through
570      * <tt>p2</tt> to <tt>p3</tt>.
571      * @pseudo
572      * @name CircumcircleSector
573      * @augments Sector
574      * @constructor
575      * @type Sector
576      * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
577      * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p1 A circumcircle sector is defined by the circumcircle which is determined
578      * by these three given points. The circumcircle sector is always drawn from <tt>p1</tt> through <tt>p2</tt> to <tt>p3</tt>.
579      * @example
580      * // Create an arc out of three free points
581      * var p1 = board.create('point', [1.5, 5.0]),
582      *     p2 = board.create('point', [1.0, 0.5]),
583      *     p3 = board.create('point', [5.0, 3.0]),
584      *
585      *     a = board.create('circumcirclesector', [p1, p2, p3]);
586      * </pre><div class="jxgbox" id="695cf0d6-6d7a-4d4d-bfc9-34c6aa28cd04" style="width: 300px; height: 300px;"></div>
587      * <script type="text/javascript">
588      * (function () {
589  *   var board = JXG.JSXGraph.initBoard('695cf0d6-6d7a-4d4d-bfc9-34c6aa28cd04', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
590  *     p1 = board.create('point', [1.5, 5.0]),
591  *     p2 = board.create('point', [1.0, 0.5]),
592  *     p3 = board.create('point', [5.0, 3.0]),
593  *
594  *     a = board.create('circumcirclesector', [p1, p2, p3]);
595  * })();
596      * </script><pre>
597      */
598     JXG.createCircumcircleSector = function (board, parents, attributes) {
599         var el, mp, attr, points, i;
600 
601         points = Type.providePoints(board, parents, attributes, 'point');
602         if (points === false) {
603             throw new Error("JSXGraph: Can't create circumcircle sector with parent types '" +
604                 (typeof parents[0]) + "' and '" + (typeof parents[1]) + "' and '" + (typeof parents[2]) + "'.");
605         }
606 
607         mp = board.create('circumcenter', points.slice(0, 3), attr);
608         mp.dump = false;
609 
610         attr = Type.copyAttributes(attributes, board.options, 'circumcirclesector');
611         el = board.create('sector', [mp, points[0], points[2], points[1]], attr);
612 
613         el.elType = 'circumcirclesector';
614         el.setParents(points);
615 
616         /**
617          * Center of the circumcirclesector
618          * @memberOf CircumcircleSector.prototype
619          * @name center
620          * @type Circumcenter
621          */
622         el.center = mp;
623         el.subs = {
624             center: mp
625         };
626 
627         return el;
628     };
629 
630     JXG.registerElement('circumcirclesector', JXG.createCircumcircleSector);
631 
632     /**
633      * @class A minor sector is a sector of a circle having measure less than or equal to
634      * 180 degrees (pi radians). It is defined by a center, one point that
635      * defines the radius, and a third point that defines the angle of the sector.
636      * @pseudo
637      * @name MinorSector
638      * @augments Curve
639      * @constructor
640      * @type JXG.Curve
641      * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
642      * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p3 . Minor sector is a sector of a circle around p1 having measure less than or equal to
643      * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3.
644      * @example
645      * // Create sector out of three free points
646      * var p1 = board.create('point', [2.0, 2.0]);
647      * var p2 = board.create('point', [1.0, 0.5]);
648      * var p3 = board.create('point', [3.5, 1.0]);
649      *
650      * var a = board.create('minorsector', [p1, p2, p3]);
651      * </pre><div class="jxgbox" id="af27ddcc-265f-428f-90dd-d31ace945800" style="width: 300px; height: 300px;"></div>
652      * <script type="text/javascript">
653      * (function () {
654      *   var board = JXG.JSXGraph.initBoard('af27ddcc-265f-428f-90dd-d31ace945800', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
655      *       p1 = board.create('point', [2.0, 2.0]),
656      *       p2 = board.create('point', [1.0, 0.5]),
657      *       p3 = board.create('point', [3.5, 1.0]),
658      *
659      *       a = board.create('minorsector', [p1, p2, p3]);
660      * })();
661      * </script><pre>
662      */
663     JXG.createMinorSector = function (board, parents, attributes) {
664         attributes.selection = 'minor';
665         return JXG.createSector(board, parents, attributes);
666     };
667 
668     JXG.registerElement('minorsector', JXG.createMinorSector);
669 
670     /**
671      * @class A major sector is a sector of a circle having measure greater than or equal to
672      * 180 degrees (pi radians). It is defined by a center, one point that
673      * defines the radius, and a third point that defines the angle of the sector.
674      * @pseudo
675      * @name MajorSector
676      * @augments Curve
677      * @constructor
678      * @type JXG.Curve
679      * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
680      * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p3 . Major sector is a sector of a circle around p1 having measure greater than or equal to
681      * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3.
682      * @example
683      * // Create an arc out of three free points
684      * var p1 = board.create('point', [2.0, 2.0]);
685      * var p2 = board.create('point', [1.0, 0.5]);
686      * var p3 = board.create('point', [3.5, 1.0]);
687      *
688      * var a = board.create('majorsector', [p1, p2, p3]);
689      * </pre><div class="jxgbox" id="83c6561f-7561-4047-b98d-036248a00932" style="width: 300px; height: 300px;"></div>
690      * <script type="text/javascript">
691      * (function () {
692      *   var board = JXG.JSXGraph.initBoard('83c6561f-7561-4047-b98d-036248a00932', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
693      *       p1 = board.create('point', [2.0, 2.0]),
694      *       p2 = board.create('point', [1.0, 0.5]),
695      *       p3 = board.create('point', [3.5, 1.0]),
696      *
697      *       a = board.create('majorsector', [p1, p2, p3]);
698      * })();
699      * </script><pre>
700      */
701     JXG.createMajorSector = function (board, parents, attributes) {
702         attributes.selection = 'major';
703         return JXG.createSector(board, parents, attributes);
704     };
705 
706     JXG.registerElement('majorsector', JXG.createMajorSector);
707 
708     /**
709      * @class The angle element is used to denote an angle defined by three points. Visually it is just a {@link Sector}
710      * element with a radius not defined by the parent elements but by an attribute <tt>radius</tt>. As opposed to the sector,
711      * an angle has two angle points and no radius point.
712      * Sector is displayed if type=="sector".
713      * If type=="square", instead of a sector a parallelogram is displayed.
714      * In case of type=="auto", a square is displayed if the angle is near orthogonal.
715      * If no name is provided the angle label is automatically set to a lower greek letter.
716      * @pseudo
717      * @name Angle
718      * @augments Sector
719      * @constructor
720      * @type Sector
721      * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
722      * First possiblity of input parameters are:
723      * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p1 An angle is always drawn counterclockwise from <tt>p1</tt> to
724      * <tt>p3</tt> around <tt>p2</tt>.
725      *
726      * Second possibility of input parameters are:
727      * @param {JXG.Line_JXG.Line_array|number_array|number} line, line2, coords1 or direction1, coords2 or direction2, radius The angle is defined by two lines.
728      * The two legs which define the angle are given by two coordinate arrays.
729      * The points given by these coordinate arrays are projected initially (i.e. only once) onto the two lines.
730      * The other possibility is to supply directions (+/- 1).
731      *
732      * @example
733      * // Create an angle out of three free points
734      * var p1 = board.create('point', [5.0, 3.0]),
735      *     p2 = board.create('point', [1.0, 0.5]),
736      *     p3 = board.create('point', [1.5, 5.0]),
737      *
738      *     a = board.create('angle', [p1, p2, p3]),
739      *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
740      * </pre><div class="jxgbox" id="a34151f9-bb26-480a-8d6e-9b8cbf789ae5" style="width: 300px; height: 300px;"></div>
741      * <script type="text/javascript">
742      * (function () {
743      *   var board = JXG.JSXGraph.initBoard('a34151f9-bb26-480a-8d6e-9b8cbf789ae5', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
744      *     p1 = board.create('point', [5.0, 3.0]),
745      *     p2 = board.create('point', [1.0, 0.5]),
746      *     p3 = board.create('point', [1.5, 5.0]),
747      *
748      *     a = board.create('angle', [p1, p2, p3]),
749      *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
750      * })();
751      * </script><pre>
752      *
753      * @example
754      * // Create an angle out of two lines and two directions
755      * var p1 = board.create('point', [-1, 4]),
756      *  p2 = board.create('point', [4, 1]),
757      *  q1 = board.create('point', [-2, -3]),
758      *  q2 = board.create('point', [4,3]),
759      *
760      *  li1 = board.create('line', [p1,p2], {strokeColor:'black', lastArrow:true}),
761      *  li2 = board.create('line', [q1,q2], {lastArrow:true}),
762      *
763      *  a1 = board.create('angle', [li1, li2, [5.5, 0], [4, 3]], { radius:1 }),
764      *  a2 = board.create('angle', [li1, li2, 1, -1], { radius:2 });
765      *
766      *
767      * </pre><div class="jxgbox" id="3a667ddd-63dc-4594-b5f1-afac969b371f" style="width: 300px; height: 300px;"></div>
768      * <script type="text/javascript">
769      * (function () {
770      *   var board = JXG.JSXGraph.initBoard('3a667ddd-63dc-4594-b5f1-afac969b371f', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
771      *     p1 = board.create('point', [-1, 4]),
772      *     p2 = board.create('point', [4, 1]),
773      *     q1 = board.create('point', [-2, -3]),
774      *     q2 = board.create('point', [4,3]),
775      *
776      *     li1 = board.create('line', [p1,p2], {strokeColor:'black', lastArrow:true}),
777      *     li2 = board.create('line', [q1,q2], {lastArrow:true}),
778      *
779      *     a1 = board.create('angle', [li1, li2, [5.5, 0], [4, 3]], { radius:1 }),
780      *     a2 = board.create('angle', [li1, li2, 1, -1], { radius:2 });
781      * })();
782      * </script><pre>
783      */
784     JXG.createAngle = function (board, parents, attributes) {
785         var el, radius, text, attr, attrsub,
786             i, dot, points,
787             type = 'invalid';
788 
789         // Two lines or three points?
790         if (parents[0].elementClass === Const.OBJECT_CLASS_LINE &&
791                 parents[1].elementClass === Const.OBJECT_CLASS_LINE &&
792                 (Type.isArray(parents[2]) || Type.isNumber(parents[2])) &&
793                 (Type.isArray(parents[3]) || Type.isNumber(parents[3]))) {
794 
795             type = '2lines';
796         } else {
797             points = Type.providePoints(board, parents, attributes, 'point');
798             if (points === false) {
799                 throw new Error("JSXGraph: Can't create angle with parent types '" +
800                     (typeof parents[0]) + "' and '" + (typeof parents[1]) + "' and '" + (typeof parents[2]) + "'.");
801             }
802             type = '3points';
803         }
804 
805         attr = Type.copyAttributes(attributes, board.options, 'angle');
806 
807         //  If empty, create a new name
808         if (!Type.exists(attr.name) || attr.name === '') {
809             attr.name = board.generateName({type: Const.OBJECT_TYPE_ANGLE});
810         }
811 
812         if (Type.exists(attr.radius)) {
813             radius = attr.radius;
814         } else {
815             radius = 0;
816         }
817 
818         if (type === '2lines') {
819             parents.push(radius);
820             el = board.create('sector', parents, attr);
821             el.updateDataArraySector = el.updateDataArray;
822 
823             // TODO
824             el.setAngle = function (val) {};
825             el.free = function (val) {};
826 
827         } else {
828             el = board.create('sector', [points[1], points[0], points[2]], attr);
829             el.arc.visProp.priv = true;
830 
831             /**
832              * The point defining the radius of the angle element. Alias for {@link Angle.prototype#radiuspoint}.
833              * @type JXG.Point
834              * @name point
835              * @memberOf Angle.prototype
836              */
837             el.point = el.point2 = el.radiuspoint = points[0];
838 
839             /**
840              * Helper point for angles of type 'square'.
841              * @type JXG.Point
842              * @name pointsquare
843              * @memberOf Angle.prototype
844              */
845             el.pointsquare = el.point3 = el.anglepoint = points[2];
846 
847             el.Radius = function () {
848                 return Type.evaluate(radius);
849             };
850 
851             el.updateDataArraySector = function () {
852                 var A = this.point2,
853                     B = this.point1,
854                     C = this.point3,
855                     r = this.Radius(),
856                     d = B.Dist(A),
857                     ar,
858                     phi,
859                     sgn = 1,
860                     vp_s = Type.evaluate(this.visProp.selection);
861 
862                 phi = Geometry.rad(A, B, C);
863                 if ((vp_s === 'minor' && phi > Math.PI) ||
864                         (vp_s === 'major' && phi < Math.PI)) {
865                     sgn = -1;
866                 }
867 
868                 A = A.coords.usrCoords;
869                 B = B.coords.usrCoords;
870                 C = C.coords.usrCoords;
871 
872                 A = [1, B[1] + (A[1] - B[1]) * r / d, B[2] + (A[2] - B[2]) * r / d];
873                 C = [1, B[1] + (C[1] - B[1]) * r / d, B[2] + (C[2] - B[2]) * r / d];
874 
875                 ar = Geometry.bezierArc(A, B, C, true, sgn);
876 
877                 this.dataX = ar[0];
878                 this.dataY = ar[1];
879                 this.bezierDegree = 3;
880             };
881 
882             /**
883             * Set an angle to a prescribed value given in radians. This is only possible if the third point of the angle, i.e.
884             * the anglepoint is a free point.
885             * @name setAngle
886             * @function
887             * @param {Number|Function} val Number or Function which returns the size of the angle in Radians
888             * @returns {Object} Pointer to the angle element..
889             * @memberOf Angle.prototype
890             *
891             * @example
892             * var p1, p2, p3, c, a, s;
893             *
894             * p1 = board.create('point',[0,0]);
895             * p2 = board.create('point',[5,0]);
896             * p3 = board.create('point',[0,5]);
897             *
898             * c1 = board.create('circle',[p1, p2]);
899             *
900             * a = board.create('angle',[p2, p1, p3], {radius:3});
901             *
902             * a.setAngle(function() {
903             *     return Math.PI / 3;
904             * });
905             * board.update();
906             *
907             * </pre><div id="987c-394f-11e6-af4a-901b0e1b8723" class="jxgbox" style="width: 300px; height: 300px;"></div>
908             * <script type="text/javascript">
909             *     (function() {
910             *         var board = JXG.JSXGraph.initBoard('987c-394f-11e6-af4a-901b0e1b8723',
911             *             {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
912             *     var p1, p2, p3, c, a, s;
913             *
914             *     p1 = board.create('point',[0,0]);
915             *     p2 = board.create('point',[5,0]);
916             *     p3 = board.create('point',[0,5]);
917             *
918             *     c1 = board.create('circle',[p1, p2]);
919             *
920             *     a = board.create('angle',[p2, p1, p3], {radius: 3});
921             *
922             *     a.setAngle(function() {
923             *         return Math.PI / 3;
924             *     });
925             *     board.update();
926             *
927             *     })();
928             *
929             * </script><pre>
930             *
931             * @example
932             * var p1, p2, p3, c, a, s;
933             *
934             * p1 = board.create('point',[0,0]);
935             * p2 = board.create('point',[5,0]);
936             * p3 = board.create('point',[0,5]);
937             *
938             * c1 = board.create('circle',[p1, p2]);
939             *
940             * a = board.create('angle',[p2, p1, p3], {radius:3});
941             * s = board.create('slider',[[-2,1], [2,1], [0, Math.PI*0.5, 2*Math.PI]]);
942             *
943             * a.setAngle(function() {
944             *     return s.Value();
945             * });
946             * board.update();
947             *
948             * </pre><div id="99957b1c-394f-11e6-af4a-901b0e1b8723" class="jxgbox" style="width: 300px; height: 300px;"></div>
949             * <script type="text/javascript">
950             *     (function() {
951             *         var board = JXG.JSXGraph.initBoard('99957b1c-394f-11e6-af4a-901b0e1b8723',
952             *             {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
953             *     var p1, p2, p3, c, a, s;
954             *
955             *     p1 = board.create('point',[0,0]);
956             *     p2 = board.create('point',[5,0]);
957             *     p3 = board.create('point',[0,5]);
958             *
959             *     c1 = board.create('circle',[p1, p2]);
960             *
961             *     a = board.create('angle',[p2, p1, p3], {radius: 3});
962             *     s = board.create('slider',[[-2,1], [2,1], [0, Math.PI*0.5, 2*Math.PI]]);
963             *
964             *     a.setAngle(function() {
965             *         return s.Value();
966             *     });
967             *     board.update();
968             *
969             *     })();
970             *
971             * </script><pre>
972             *
973             */
974             el.setAngle = function (val) {
975                 var t,
976                     p = this.anglepoint,
977                     q = this.radiuspoint;
978 
979                 if (p.draggable()) {
980                     t = this.board.create('transform', [val, this.center], {type: 'rotate'});
981                     p.addTransform(q, t);
982                     p.isDraggable = false;
983                     p.setParents(q);
984                 }
985                 return this;
986             };
987 
988             /**
989             * Frees an angle from a prescribed value. This is only relevant if the angle size has been set by
990             * setAngle() previously. The anglepoint is set to a free point.
991             * @name free
992             * @function
993             * @returns {Object} Pointer to the angle element..
994             * @memberOf Angle.prototype
995             */
996             el.free = function () {
997                 var p = this.anglepoint;
998                 if (p.transformations.length > 0) {
999                     p.transformations.pop();
1000                     p.isDraggable = true;
1001                     p.parents = [];
1002                 }
1003                 return this;
1004             };
1005 
1006             el.setParents(points); // Important: This overwrites the parents order in underlying sector
1007 
1008         } // end '3points'
1009 
1010         // GEONExT compatible labels.
1011         if (Type.exists(el.visProp.text)) {
1012             el.label.setText(Type.evaluate(el.visProp.text));
1013         }
1014 
1015         el.elType = 'angle';
1016         el.type = Const.OBJECT_TYPE_ANGLE;
1017         el.subs = {};
1018 
1019         el.updateDataArraySquare = function () {
1020             var A, B, C,
1021                 r = this.Radius(),
1022                 d1, d2,
1023                 v, l1, l2;
1024 
1025 
1026             if (type === '2lines') {
1027                 // This is necessary to update this.point1, this.point2, this.point3.
1028                 this.updateDataArraySector();
1029             }
1030 
1031             A = this.point2;
1032             B = this.point1;
1033             C = this.point3;
1034 
1035             A = A.coords.usrCoords;
1036             B = B.coords.usrCoords;
1037             C = C.coords.usrCoords;
1038 
1039             d1 = Geometry.distance(A, B, 3);
1040             d2 = Geometry.distance(C, B, 3);
1041 
1042             // In case of type=='2lines' this is redundant, because r == d1 == d2
1043             A = [1, B[1] + (A[1] - B[1]) * r / d1, B[2] + (A[2] - B[2]) * r / d1];
1044             C = [1, B[1] + (C[1] - B[1]) * r / d2, B[2] + (C[2] - B[2]) * r / d2];
1045 
1046             v = Mat.crossProduct(C, B);
1047             l1 = [-A[1] * v[1] - A[2] * v[2], A[0] * v[1], A[0] * v[2]];
1048             v = Mat.crossProduct(A, B);
1049             l2 = [-C[1] * v[1] - C[2] * v[2], C[0] * v[1], C[0] * v[2]];
1050 
1051             v = Mat.crossProduct(l1, l2);
1052             v[1] /= v[0];
1053             v[2] /= v[0];
1054 
1055             this.dataX = [B[1], A[1], v[1], C[1], B[1]];
1056             this.dataY = [B[2], A[2], v[2], C[2], B[2]];
1057 
1058             this.bezierDegree = 1;
1059         };
1060 
1061         el.updateDataArrayNone = function () {
1062             this.dataX = [NaN];
1063             this.dataY = [NaN];
1064             this.bezierDegree = 1;
1065         };
1066 
1067         el.updateDataArray = function () {
1068             var type = Type.evaluate(this.visProp.type),
1069                 deg = Geometry.trueAngle(this.point2, this.point1, this.point3),
1070                 vp_s = Type.evaluate(this.visProp.selection);
1071 
1072             if ((vp_s === 'minor' && deg > 180.0) ||
1073                     (vp_s === 'major' && deg < 180.0)) {
1074                 deg = 360.0 - deg;
1075             }
1076 
1077             if (Math.abs(deg - 90.0) < Type.evaluate(this.visProp.orthosensitivity) + Mat.eps) {
1078                 type = Type.evaluate(this.visProp.orthotype);
1079             }
1080 
1081             if (type === 'none') {
1082                 this.updateDataArrayNone();
1083             } else if (type === 'square') {
1084                 this.updateDataArraySquare();
1085             } else if (type === 'sector') {
1086                 this.updateDataArraySector();
1087             } else if (type === 'sectordot') {
1088                 this.updateDataArraySector();
1089                 if (!this.dot.visProp.visible) {
1090                     this.dot.setAttribute({visible: true});
1091                 }
1092             }
1093 
1094             if (!this.visProp.visible || (type !== 'sectordot' && this.dot.visProp.visible)) {
1095                 this.dot.setAttribute({visible: false});
1096             }
1097         };
1098 
1099         /**
1100          * Indicates a right angle. Invisible by default, use <tt>dot.visible: true</tt> to show.
1101          * Though this dot indicates a right angle, it can be visible even if the angle is not a right
1102          * one.
1103          * @type JXG.Point
1104          * @name dot
1105          * @memberOf Angle.prototype
1106          */
1107         attrsub = Type.copyAttributes(attributes, board.options, 'angle', 'dot');
1108         el.dot = board.create('point', [function () {
1109             var A, B, r, d, a2, co, si, mat,
1110                 point1, point2, point3,
1111                 vp_s;
1112 
1113             if (Type.exists(el.dot) && !el.dot.visProp.visible) {
1114                 return [0, 0];
1115             }
1116 
1117             A = el.point2.coords.usrCoords;
1118             B = el.point1.coords.usrCoords;
1119             r = el.Radius();
1120             d = Geometry.distance(A, B, 3);
1121             a2 = Geometry.rad(el.point2, el.point1, el.point3);
1122 
1123             vp_s = Type.evaluate(el.visProp.selection);
1124             if ((vp_s === 'minor' && a2 > Math.PI) ||
1125                     (vp_s === 'major' && a2 < Math.PI)) {
1126                 a2 = -(2 * Math.PI - a2);
1127             }
1128             a2 *= 0.5;
1129 
1130             co = Math.cos(a2);
1131             si = Math.sin(a2);
1132 
1133             A = [1, B[1] + (A[1] - B[1]) * r / d, B[2] + (A[2] - B[2]) * r / d];
1134 
1135             mat = [
1136                 [1, 0, 0],
1137                 [B[1] - 0.5 * B[1] * co + 0.5 * B[2] * si, co * 0.5, -si * 0.5],
1138                 [B[2] - 0.5 * B[1] * si - 0.5 * B[2] * co, si * 0.5,  co * 0.5]
1139             ];
1140             return Mat.matVecMult(mat, A);
1141         }], attrsub);
1142 
1143         el.dot.dump = false;
1144         el.subs.dot = el.dot;
1145 
1146         if (type === '2lines') {
1147             for (i = 0; i < 2; i++) {
1148                 board.select(parents[i]).addChild(el.dot);
1149             }
1150         } else {
1151             for (i = 0; i < 3; i++) {
1152                 board.select(points[i]).addChild(el.dot);
1153             }
1154         }
1155 
1156         // documented in GeometryElement
1157         el.getLabelAnchor = function () {
1158             var vec, dx = 12, dy = 12,
1159                 A, B, r, d, a2, co, si, mat,
1160                 vp_s = Type.evaluate(el.visProp.selection);
1161 
1162             // If this is uncommented, the angle label can not be dragged
1163             //if (Type.exists(this.label)) {
1164             //    this.label.relativeCoords = new Coords(Const.COORDS_BY_SCREEN, [0, 0], this.board);
1165             //}
1166 
1167             if (Type.exists(this.label.visProp.fontSize)) {
1168                 dx = dy = Type.evaluate(this.label.visProp.fontSize);
1169             }
1170             dx /= this.board.unitX;
1171             dy /= this.board.unitY;
1172 
1173             A = el.point2.coords.usrCoords;
1174             B = el.point1.coords.usrCoords;
1175             r = el.Radius();
1176             d = Geometry.distance(A, B, 3);
1177             a2 = Geometry.rad(el.point2, el.point1, el.point3);
1178             if ((vp_s === 'minor' && a2 > Math.PI) ||
1179                     (vp_s === 'major' && a2 < Math.PI)) {
1180                 a2 = -(2 * Math.PI - a2);
1181             }
1182             a2 *= 0.5;
1183             co = Math.cos(a2);
1184             si = Math.sin(a2);
1185 
1186             A = [1, B[1] + (A[1] - B[1]) * r / d, B[2] + (A[2] - B[2]) * r / d];
1187 
1188             mat = [
1189                 [1, 0, 0],
1190                 [B[1] - 0.5 * B[1] * co + 0.5 * B[2] * si, co * 0.5, -si * 0.5],
1191                 [B[2] - 0.5 * B[1] * si - 0.5 * B[2] * co, si * 0.5,  co * 0.5]
1192             ];
1193             vec = Mat.matVecMult(mat, A);
1194             vec[1] /= vec[0];
1195             vec[2] /= vec[0];
1196             vec[0] /= vec[0];
1197 
1198             d = Geometry.distance(vec, B, 3);
1199             vec = [vec[0], B[1] + (vec[1] - B[1]) * (r + dx) / d,  B[2] + (vec[2] - B[2]) * (r + dx) / d];
1200 
1201             return new Coords(Const.COORDS_BY_USER, vec, this.board);
1202         };
1203 
1204         /**
1205          * Returns the value of the angle in Radians.
1206          * @memberOf Angle.prototype
1207          * @name Value
1208          * @function
1209          * @returns {Number} The angle value in Radians
1210          */
1211         el.Value = function () {
1212             return Geometry.rad(this.point2, this.point1, this.point3);
1213         };
1214 
1215         el.methodMap = Type.deepCopy(el.methodMap, {
1216             Value: 'Value',
1217             setAngle: 'setAngle',
1218             free: 'free'
1219         });
1220 
1221         return el;
1222     };
1223 
1224     JXG.registerElement('angle', JXG.createAngle);
1225 
1226     /**
1227      * @class A non-reflex angle is the acute or obtuse instance of an angle.
1228      * It is defined by a center, one point that
1229      * defines the radius, and a third point that defines the angle of the sector.
1230      * @pseudo
1231      * @name NonReflexAngle
1232      * @augments Angle
1233      * @constructor
1234      * @type Sector
1235      * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
1236      * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p3 . Minor sector is a sector of a circle around p1 having measure less than or equal to
1237      * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3.
1238      * @example
1239      * // Create a non-reflex angle out of three free points
1240      * var p1 = board.create('point', [5.0, 3.0]),
1241      *     p2 = board.create('point', [1.0, 0.5]),
1242      *     p3 = board.create('point', [1.5, 5.0]),
1243      *
1244      *     a = board.create('nonreflexangle', [p1, p2, p3], {radius: 2}),
1245      *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
1246      * </pre><div class="jxgbox" id="d0ab6d6b-63a7-48b2-8749-b02bb5e744f9" style="width: 300px; height: 300px;"></div>
1247      * <script type="text/javascript">
1248      * (function () {
1249      *   var board = JXG.JSXGraph.initBoard('d0ab6d6b-63a7-48b2-8749-b02bb5e744f9', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
1250      *     p1 = board.create('point', [5.0, 3.0]),
1251      *     p2 = board.create('point', [1.0, 0.5]),
1252      *     p3 = board.create('point', [1.5, 5.0]),
1253      *
1254      *     a = board.create('nonreflexangle', [p1, p2, p3], {radius: 2}),
1255      *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
1256      * })();
1257      * </script><pre>
1258      */
1259     JXG.createNonreflexAngle = function (board, parents, attributes) {
1260         var el;
1261 
1262         attributes.selection = 'minor';
1263         el = JXG.createAngle(board, parents, attributes);
1264 
1265         el.Value = function () {
1266             var v = Geometry.rad(this.point2, this.point1, this.point3);
1267             return (v < Math.PI) ? v : 2.0 * Math.PI - v;
1268         };
1269         return el;
1270     };
1271 
1272     JXG.registerElement('nonreflexangle', JXG.createNonreflexAngle);
1273 
1274     /**
1275      * @class A reflex angle is the neither acute nor obtuse instance of an angle.
1276      * It is defined by a center, one point that
1277      * defines the radius, and a third point that defines the angle of the sector.
1278      * @pseudo
1279      * @name ReflexAngle
1280      * @augments Angle
1281      * @constructor
1282      * @type Sector
1283      * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown.
1284      * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p3 . Minor sector is a sector of a circle around p1 having measure less than or equal to
1285      * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3.
1286      * @example
1287      * // Create a non-reflex angle out of three free points
1288      * var p1 = board.create('point', [5.0, 3.0]),
1289      *     p2 = board.create('point', [1.0, 0.5]),
1290      *     p3 = board.create('point', [1.5, 5.0]),
1291      *
1292      *     a = board.create('reflexangle', [p1, p2, p3], {radius: 2}),
1293      *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
1294      * </pre><div class="jxgbox" id="f2a577f2-553d-4f9f-a895-2d6d4b8c60e8" style="width: 300px; height: 300px;"></div>
1295      * <script type="text/javascript">
1296      * (function () {
1297      * var board = JXG.JSXGraph.initBoard('f2a577f2-553d-4f9f-a895-2d6d4b8c60e8', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}),
1298      *     p1 = board.create('point', [5.0, 3.0]),
1299      *     p2 = board.create('point', [1.0, 0.5]),
1300      *     p3 = board.create('point', [1.5, 5.0]),
1301      *
1302      *     a = board.create('reflexangle', [p1, p2, p3], {radius: 2}),
1303      *     t = board.create('text', [4, 4, function() { return JXG.toFixed(a.Value(), 2); }]);
1304      * })();
1305      * </script><pre>
1306      */
1307     JXG.createReflexAngle = function (board, parents, attributes) {
1308         var el;
1309 
1310         attributes.selection = 'major';
1311         el = JXG.createAngle(board, parents, attributes);
1312 
1313         el.Value = function () {
1314             var v = Geometry.rad(this.point2, this.point1, this.point3);
1315             return (v >= Math.PI) ? v : 2.0 * Math.PI - v;
1316         };
1317         return el;
1318     };
1319 
1320     JXG.registerElement('reflexangle', JXG.createReflexAngle);
1321 
1322     return {
1323         createSector: JXG.createSector,
1324         createCircumcircleSector: JXG.createCircumcircleSector,
1325         createMinorSector: JXG.createMinorSector,
1326         createMajorSector: JXG.createMajorSector,
1327         createAngle: JXG.createAngle,
1328         createReflexAngle: JXG.createReflexAngle,
1329         createNonreflexAngle: JXG.createNonreflexAngle
1330     };
1331 });
1332