1 /* 2 Copyright 2008-2016 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 332 if (!A.isReal || !B.isReal || !C.isReal) { 333 this.dataX = [NaN]; 334 this.dataY = [NaN]; 335 return; 336 } 337 338 phi = Geometry.rad(A, B, C); 339 if ((this.visProp.selection === 'minor' && phi > Math.PI) || 340 (this.visProp.selection === 'major' && phi < Math.PI)) { 341 sgn = -1; 342 } 343 344 // This is true for circumCircleSectors. In that case there is 345 // a fourth parent element: [midpoint, point1, point3, point2] 346 if (this.useDirection && Type.exists(this.point4)) { 347 p0c = this.point2.coords.usrCoords; 348 p1c = this.point4.coords.usrCoords; 349 p2c = this.point3.coords.usrCoords; 350 det = (p0c[1] - p2c[1]) * (p0c[2] - p1c[2]) - (p0c[2] - p2c[2]) * (p0c[1] - p1c[1]); 351 352 if (det >= 0.0) { 353 C = this.point2; 354 A = this.point3; 355 } 356 } 357 358 A = A.coords.usrCoords; 359 B = B.coords.usrCoords; 360 C = C.coords.usrCoords; 361 362 ar = Geometry.bezierArc(A, B, C, true, sgn); 363 364 this.dataX = ar[0]; 365 this.dataY = ar[1]; 366 this.bezierDegree = 3; 367 }; 368 369 /** 370 * Returns the radius of the sector. 371 * @memberOf Sector.prototype 372 * @name Radius 373 * @function 374 * @returns {Number} The distance between {@link Sector#point1} and {@link Sector#point2}. 375 */ 376 el.Radius = function () { 377 return this.point2.Dist(this.point1); 378 }; 379 380 attr = Type.copyAttributes(attributes, board.options, 'sector', 'arc'); 381 attr.withLabel = false; 382 attr.name += '_arc'; 383 el.arc = board.create('arc', [el.point1, el.point2, el.point3], attr); 384 el.addChild(el.arc); 385 } // end '3points' 386 387 el.center = el.point1; 388 el.radiuspoint = el.point2; 389 el.anglepoint = el.point3; 390 391 // Default hasPoint method. Documented in geometry element 392 el.hasPointCurve = function (x, y) { 393 var angle, alpha, beta, 394 prec = this.board.options.precision.hasPoint / (this.board.unitX), 395 checkPoint = new Coords(Const.COORDS_BY_SCREEN, [x, y], this.board), 396 r = this.Radius(), 397 dist = this.center.coords.distance(Const.COORDS_BY_USER, checkPoint), 398 has = (Math.abs(dist - r) < prec); 399 400 if (has) { 401 angle = Geometry.rad(this.point2, this.center, checkPoint.usrCoords.slice(1)); 402 alpha = 0; 403 beta = Geometry.rad(this.point2, this.center, this.point3); 404 405 if ((this.visProp.selection === 'minor' && beta > Math.PI) || 406 (this.visProp.selection === 'major' && beta < Math.PI)) { 407 alpha = beta; 408 beta = 2 * Math.PI; 409 } 410 411 if (angle < alpha || angle > beta) { 412 has = false; 413 } 414 } 415 416 return has; 417 }; 418 419 /** 420 * Checks whether (x,y) is within the area defined by the sector. 421 * @memberOf Sector.prototype 422 * @name hasPointSector 423 * @function 424 * @param {Number} x Coordinate in x direction, screen coordinates. 425 * @param {Number} y Coordinate in y direction, screen coordinates. 426 * @returns {Boolean} True if (x,y) is within the sector defined by the arc, False otherwise. 427 */ 428 el.hasPointSector = function (x, y) { 429 var angle, 430 checkPoint = new Coords(Const.COORDS_BY_SCREEN, [x, y], this.board), 431 r = this.Radius(), 432 dist = this.point1.coords.distance(Const.COORDS_BY_USER, checkPoint), 433 alpha, 434 beta, 435 has = (dist < r); 436 437 if (has) { 438 angle = Geometry.rad(this.radiuspoint, this.center, checkPoint.usrCoords.slice(1)); 439 alpha = 0.0; 440 beta = Geometry.rad(this.radiuspoint, this.center, this.anglepoint); 441 442 if ((this.visProp.selection === 'minor' && beta > Math.PI) || 443 (this.visProp.selection === 'major' && beta < Math.PI)) { 444 alpha = beta; 445 beta = 2 * Math.PI; 446 } 447 //if (angle > Geometry.rad(this.point2, this.point1, this.point3)) { 448 if (angle < alpha || angle > beta) { 449 has = false; 450 } 451 } 452 return has; 453 }; 454 455 el.hasPoint = function (x, y) { 456 if (this.visProp.highlightonsector || this.visProp.hasinnerpoints) { 457 return this.hasPointSector(x, y); 458 } 459 460 return this.hasPointCurve(x, y); 461 }; 462 463 // documented in GeometryElement 464 el.getTextAnchor = function () { 465 return this.point1.coords; 466 }; 467 468 // documented in GeometryElement 469 // this method is very similar to arc.getLabelAnchor() 470 // there are some additions in the arc version though, mainly concerning 471 // "major" and "minor" arcs. but maybe these methods can be merged. 472 el.getLabelAnchor = function () { 473 var coords, vecx, vecy, len, 474 angle = Geometry.rad(this.point2, this.point1, this.point3), 475 dx = 13 / this.board.unitX, 476 dy = 13 / this.board.unitY, 477 p2c = this.point2.coords.usrCoords, 478 pmc = this.point1.coords.usrCoords, 479 bxminusax = p2c[1] - pmc[1], 480 byminusay = p2c[2] - pmc[2]; 481 482 // If this is uncommented, the angle label can not be dragged 483 //if (Type.exists(this.label)) { 484 // this.label.relativeCoords = new Coords(Const.COORDS_BY_SCREEN, [0, 0], this.board); 485 //} 486 487 if ((this.visProp.selection === 'minor' && angle > Math.PI) || 488 (this.visProp.selection === 'major' && angle < Math.PI)) { 489 angle = -(2 * Math.PI - angle); 490 } 491 492 coords = new Coords(Const.COORDS_BY_USER, [ 493 pmc[1] + Math.cos(angle * 0.5) * bxminusax - Math.sin(angle * 0.5) * byminusay, 494 pmc[2] + Math.sin(angle * 0.5) * bxminusax + Math.cos(angle * 0.5) * byminusay 495 ], this.board); 496 497 vecx = coords.usrCoords[1] - pmc[1]; 498 vecy = coords.usrCoords[2] - pmc[2]; 499 500 len = Math.sqrt(vecx * vecx + vecy * vecy); 501 vecx = vecx * (len + dx) / len; 502 vecy = vecy * (len + dy) / len; 503 504 return new Coords(Const.COORDS_BY_USER, [pmc[1] + vecx, pmc[2] + vecy], this.board); 505 }; 506 507 /** 508 * Overwrite the Radius method of the sector. 509 * Used in {@link GeometryElement#setAttribute}. 510 * @param {Number, Function} value New radius. 511 */ 512 el.setRadius = function (value) { 513 el.Radius = function () { 514 return Type.evaluate(value); 515 }; 516 }; 517 518 /** 519 * @deprecated 520 * @ignore 521 */ 522 el.getRadius = function () { 523 JXG.deprecated('Sector.getRadius()', 'Sector.Radius()'); 524 return this.Radius(); 525 }; 526 527 /** 528 * Moves the sector by the difference of two coordinates. 529 * @param {Number} method The type of coordinates used here. Possible values are {@link JXG.COORDS_BY_USER} and {@link JXG.COORDS_BY_SCREEN}. 530 * @param {Array} coords coordinates in screen/user units 531 * @param {Array} oldcoords previous coordinates in screen/user units 532 * @returns {JXG.Curve} this element 533 */ 534 if (type === '3points') { 535 el.setPositionDirectly = function (method, coords, oldcoords) { 536 var dc, t, i, len, 537 c = new Coords(method, coords, this.board), 538 oldc = new Coords(method, oldcoords, this.board); 539 540 if (!el.point1.draggable() || !el.point2.draggable() || !el.point3.draggable()) { 541 return this; 542 } 543 544 dc = Statistics.subtract(c.usrCoords, oldc.usrCoords); 545 t = this.board.create('transform', dc.slice(1), {type: 'translate'}); 546 t.applyOnce([el.point1, el.point2, el.point3]); 547 548 return this; 549 }; 550 } 551 552 el.prepareUpdate().update(); 553 554 return el; 555 }; 556 557 JXG.registerElement('sector', JXG.createSector); 558 559 560 /** 561 * @class A circumcircle sector is different from a {@link Sector} mostly in the way the parent elements are interpreted. 562 * At first, the circum centre is determined from the three given points. Then the sector is drawn from <tt>p1</tt> through 563 * <tt>p2</tt> to <tt>p3</tt>. 564 * @pseudo 565 * @name CircumcircleSector 566 * @augments Sector 567 * @constructor 568 * @type Sector 569 * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown. 570 * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p1 A circumcircle sector is defined by the circumcircle which is determined 571 * by these three given points. The circumcircle sector is always drawn from <tt>p1</tt> through <tt>p2</tt> to <tt>p3</tt>. 572 * @example 573 * // Create an arc out of three free points 574 * var p1 = board.create('point', [1.5, 5.0]), 575 * p2 = board.create('point', [1.0, 0.5]), 576 * p3 = board.create('point', [5.0, 3.0]), 577 * 578 * a = board.create('circumcirclesector', [p1, p2, p3]); 579 * </pre><div class="jxgbox"id="695cf0d6-6d7a-4d4d-bfc9-34c6aa28cd04" style="width: 300px; height: 300px;"></div> 580 * <script type="text/javascript"> 581 * (function () { 582 * var board = JXG.JSXGraph.initBoard('695cf0d6-6d7a-4d4d-bfc9-34c6aa28cd04', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}), 583 * p1 = board.create('point', [1.5, 5.0]), 584 * p2 = board.create('point', [1.0, 0.5]), 585 * p3 = board.create('point', [5.0, 3.0]), 586 * 587 * a = board.create('circumcirclesector', [p1, p2, p3]); 588 * })(); 589 * </script><pre> 590 */ 591 JXG.createCircumcircleSector = function (board, parents, attributes) { 592 var el, mp, attr, points, i; 593 594 points = Type.providePoints(board, parents, attributes, 'point'); 595 if (points === false) { 596 throw new Error("JSXGraph: Can't create circumcircle sector with parent types '" + 597 (typeof parents[0]) + "' and '" + (typeof parents[1]) + "' and '" + (typeof parents[2]) + "'."); 598 } 599 600 mp = board.create('circumcenter', points.slice(0, 3), attr); 601 mp.dump = false; 602 603 attr = Type.copyAttributes(attributes, board.options, 'circumcirclesector'); 604 el = board.create('sector', [mp, points[0], points[2], points[1]], attr); 605 606 el.elType = 'circumcirclesector'; 607 el.setParents(points); 608 609 /** 610 * Center of the circumcirclesector 611 * @memberOf CircumcircleSector.prototype 612 * @name center 613 * @type Circumcenter 614 */ 615 el.center = mp; 616 el.subs = { 617 center: mp 618 }; 619 620 return el; 621 }; 622 623 JXG.registerElement('circumcirclesector', JXG.createCircumcircleSector); 624 625 /** 626 * @class A minor sector is a sector of a circle having measure less than or equal to 627 * 180 degrees (pi radians). It is defined by a center, one point that 628 * defines the radius, and a third point that defines the angle of the sector. 629 * @pseudo 630 * @name MinorSector 631 * @augments Curve 632 * @constructor 633 * @type JXG.Curve 634 * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown. 635 * @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 636 * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3. 637 * @example 638 * // Create sector out of three free points 639 * var p1 = board.create('point', [2.0, 2.0]); 640 * var p2 = board.create('point', [1.0, 0.5]); 641 * var p3 = board.create('point', [3.5, 1.0]); 642 * 643 * var a = board.create('minorsector', [p1, p2, p3]); 644 * </pre><div class="jxgbox"id="af27ddcc-265f-428f-90dd-d31ace945800" style="width: 300px; height: 300px;"></div> 645 * <script type="text/javascript"> 646 * (function () { 647 * var board = JXG.JSXGraph.initBoard('af27ddcc-265f-428f-90dd-d31ace945800', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}), 648 * p1 = board.create('point', [2.0, 2.0]), 649 * p2 = board.create('point', [1.0, 0.5]), 650 * p3 = board.create('point', [3.5, 1.0]), 651 * 652 * a = board.create('minorsector', [p1, p2, p3]); 653 * })(); 654 * </script><pre> 655 */ 656 JXG.createMinorSector = function (board, parents, attributes) { 657 attributes.selection = 'minor'; 658 return JXG.createSector(board, parents, attributes); 659 }; 660 661 JXG.registerElement('minorsector', JXG.createMinorSector); 662 663 /** 664 * @class A major sector is a sector of a circle having measure greater than or equal to 665 * 180 degrees (pi radians). It is defined by a center, one point that 666 * defines the radius, and a third point that defines the angle of the sector. 667 * @pseudo 668 * @name MajorSector 669 * @augments Curve 670 * @constructor 671 * @type JXG.Curve 672 * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown. 673 * @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 674 * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3. 675 * @example 676 * // Create an arc out of three free points 677 * var p1 = board.create('point', [2.0, 2.0]); 678 * var p2 = board.create('point', [1.0, 0.5]); 679 * var p3 = board.create('point', [3.5, 1.0]); 680 * 681 * var a = board.create('majorsector', [p1, p2, p3]); 682 * </pre><div class="jxgbox"id="83c6561f-7561-4047-b98d-036248a00932" style="width: 300px; height: 300px;"></div> 683 * <script type="text/javascript"> 684 * (function () { 685 * var board = JXG.JSXGraph.initBoard('83c6561f-7561-4047-b98d-036248a00932', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}), 686 * p1 = board.create('point', [2.0, 2.0]), 687 * p2 = board.create('point', [1.0, 0.5]), 688 * p3 = board.create('point', [3.5, 1.0]), 689 * 690 * a = board.create('majorsector', [p1, p2, p3]); 691 * })(); 692 * </script><pre> 693 */ 694 JXG.createMajorSector = function (board, parents, attributes) { 695 attributes.selection = 'major'; 696 return JXG.createSector(board, parents, attributes); 697 }; 698 699 JXG.registerElement('majorsector', JXG.createMajorSector); 700 701 /** 702 * @class The angle element is used to denote an angle defined by three points. Visually it is just a {@link Sector} 703 * element with a radius not defined by the parent elements but by an attribute <tt>radius</tt>. As opposed to the sector, 704 * an angle has two angle points and no radius point. 705 * Sector is displayed if type=="sector". 706 * If type=="square", instead of a sector a parallelogram is displayed. 707 * In case of type=="auto", a square is displayed if the angle is near orthogonal. 708 * If no name is provided the angle label is automatically set to a lower greek letter. 709 * @pseudo 710 * @name Angle 711 * @augments Sector 712 * @constructor 713 * @type Sector 714 * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown. 715 * First possiblity of input parameters are: 716 * @param {JXG.Point_JXG.Point_JXG.Point} p1,p2,p1 An angle is always drawn counterclockwise from <tt>p1</tt> to 717 * <tt>p3</tt> around <tt>p2</tt>. 718 * 719 * Second possibility of input parameters are: 720 * @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. 721 * The two legs which define the angle are given by two coordinate arrays. 722 * The points given by these coordinate arrays are projected initially (i.e. only once) onto the two lines. 723 * The other possibility is to supply directions (+/- 1). 724 * 725 * @example 726 * // Create an angle out of three free points 727 * var p1 = board.create('point', [5.0, 3.0]), 728 * p2 = board.create('point', [1.0, 0.5]), 729 * p3 = board.create('point', [1.5, 5.0]), 730 * 731 * a = board.create('angle', [p1, p2, p3]), 732 * t = board.create('text', [4, 4, function() { return a.Value().toFixed(2); }]); 733 * </pre><div class="jxgbox"id="a34151f9-bb26-480a-8d6e-9b8cbf789ae5" style="width: 300px; height: 300px;"></div> 734 * <script type="text/javascript"> 735 * (function () { 736 * var board = JXG.JSXGraph.initBoard('a34151f9-bb26-480a-8d6e-9b8cbf789ae5', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}), 737 * p1 = board.create('point', [5.0, 3.0]), 738 * p2 = board.create('point', [1.0, 0.5]), 739 * p3 = board.create('point', [1.5, 5.0]), 740 * 741 * a = board.create('angle', [p1, p2, p3]), 742 * t = board.create('text', [4, 4, function() { return a.Value().toFixed(2); }]); 743 * })(); 744 * </script><pre> 745 * 746 * @example 747 * // Create an angle out of two lines and two directions 748 * var p1 = board.create('point', [-1, 4]), 749 * p2 = board.create('point', [4, 1]), 750 * q1 = board.create('point', [-2, -3]), 751 * q2 = board.create('point', [4,3]), 752 * 753 * li1 = board.create('line', [p1,p2], {strokeColor:'black', lastArrow:true}), 754 * li2 = board.create('line', [q1,q2], {lastArrow:true}), 755 * 756 * a1 = board.create('angle', [li1, li2, [5.5, 0], [4, 3]], { radius:1 }), 757 * a2 = board.create('angle', [li1, li2, 1, -1], { radius:2 }); 758 * 759 * 760 * </pre><div class="jxgbox"id="3a667ddd-63dc-4594-b5f1-afac969b371f" style="width: 300px; height: 300px;"></div> 761 * <script type="text/javascript"> 762 * (function () { 763 * var board = JXG.JSXGraph.initBoard('3a667ddd-63dc-4594-b5f1-afac969b371f', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}), 764 * p1 = board.create('point', [-1, 4]), 765 * p2 = board.create('point', [4, 1]), 766 * q1 = board.create('point', [-2, -3]), 767 * q2 = board.create('point', [4,3]), 768 * 769 * li1 = board.create('line', [p1,p2], {strokeColor:'black', lastArrow:true}), 770 * li2 = board.create('line', [q1,q2], {lastArrow:true}), 771 * 772 * a1 = board.create('angle', [li1, li2, [5.5, 0], [4, 3]], { radius:1 }), 773 * a2 = board.create('angle', [li1, li2, 1, -1], { radius:2 }); 774 * })(); 775 * </script><pre> 776 */ 777 JXG.createAngle = function (board, parents, attributes) { 778 var el, radius, text, attr, attrsub, 779 i, dot, points, 780 type = 'invalid'; 781 782 // Two lines or three points? 783 if (parents[0].elementClass === Const.OBJECT_CLASS_LINE && 784 parents[1].elementClass === Const.OBJECT_CLASS_LINE && 785 (Type.isArray(parents[2]) || Type.isNumber(parents[2])) && 786 (Type.isArray(parents[3]) || Type.isNumber(parents[3]))) { 787 788 type = '2lines'; 789 } else { 790 points = Type.providePoints(board, parents, attributes, 'point'); 791 if (points === false) { 792 throw new Error("JSXGraph: Can't create angle with parent types '" + 793 (typeof parents[0]) + "' and '" + (typeof parents[1]) + "' and '" + (typeof parents[2]) + "'."); 794 } 795 type = '3points'; 796 } 797 798 attr = Type.copyAttributes(attributes, board.options, 'angle'); 799 800 // If empty, create a new name 801 if (!Type.exists(attr.name) || attr.name === '') { 802 attr.name = board.generateName({type: Const.OBJECT_TYPE_ANGLE}); 803 } 804 805 if (Type.exists(attr.radius)) { 806 radius = attr.radius; 807 } else { 808 radius = 0; 809 } 810 811 if (type === '2lines') { 812 parents.push(radius); 813 el = board.create('sector', parents, attr); 814 el.updateDataArraySector = el.updateDataArray; 815 816 // TODO 817 el.setAngle = function (val) {}; 818 el.free = function (val) {}; 819 820 } else { 821 el = board.create('sector', [points[1], points[0], points[2]], attr); 822 el.arc.visProp.priv = true; 823 824 /** 825 * The point defining the radius of the angle element. Alias for {@link Angle.prototype#radiuspoint}. 826 * @type JXG.Point 827 * @name point 828 * @memberOf Angle.prototype 829 */ 830 el.point = el.point2 = el.radiuspoint = points[0]; 831 832 /** 833 * Helper point for angles of type 'square'. 834 * @type JXG.Point 835 * @name pointsquare 836 * @memberOf Angle.prototype 837 */ 838 el.pointsquare = el.point3 = el.anglepoint = points[2]; 839 840 el.Radius = function () { 841 return Type.evaluate(radius); 842 }; 843 844 el.updateDataArraySector = function () { 845 var A = this.point2, 846 B = this.point1, 847 C = this.point3, 848 r = this.Radius(), 849 d = B.Dist(A), 850 ar, 851 phi, 852 sgn = 1; 853 854 phi = Geometry.rad(A, B, C); 855 if ((this.visProp.selection === 'minor' && phi > Math.PI) || 856 (this.visProp.selection === 'major' && phi < Math.PI)) { 857 sgn = -1; 858 } 859 860 A = A.coords.usrCoords; 861 B = B.coords.usrCoords; 862 C = C.coords.usrCoords; 863 864 A = [1, B[1] + (A[1] - B[1]) * r / d, B[2] + (A[2] - B[2]) * r / d]; 865 C = [1, B[1] + (C[1] - B[1]) * r / d, B[2] + (C[2] - B[2]) * r / d]; 866 867 ar = Geometry.bezierArc(A, B, C, true, sgn); 868 869 this.dataX = ar[0]; 870 this.dataY = ar[1]; 871 this.bezierDegree = 3; 872 }; 873 874 /** 875 * Set an angle to a prescribed value given in radians. This is only possible if the third point of the angle, i.e. 876 * the anglepoint is a free point. 877 * @name setAngle 878 * @function 879 * @param {Number|Function} val Number or Function which returns the size of the angle in Radians 880 * @returns {Object} Pointer to the angle element.. 881 * @memberOf Angle.prototype 882 * 883 * @example 884 * var p1, p2, p3, c, a, s; 885 * 886 * p1 = board.create('point',[0,0]); 887 * p2 = board.create('point',[5,0]); 888 * p3 = board.create('point',[0,5]); 889 * 890 * c1 = board.create('circle',[p1, p2]); 891 * 892 * a = board.create('angle',[p2, p1, p3], {radius:3}); 893 * 894 * a.setAngle(function() { 895 * return Math.PI / 3; 896 * }); 897 * board.update(); 898 * 899 * </pre><div id="987c-394f-11e6-af4a-901b0e1b8723" class="jxgbox" style="width: 300px; height: 300px;"></div> 900 * <script type="text/javascript"> 901 * (function() { 902 * var board = JXG.JSXGraph.initBoard('987c-394f-11e6-af4a-901b0e1b8723', 903 * {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false}); 904 * var p1, p2, p3, c, a, s; 905 * 906 * p1 = board.create('point',[0,0]); 907 * p2 = board.create('point',[5,0]); 908 * p3 = board.create('point',[0,5]); 909 * 910 * c1 = board.create('circle',[p1, p2]); 911 * 912 * a = board.create('angle',[p2, p1, p3], {radius: 3}); 913 * 914 * a.setAngle(function() { 915 * return Math.PI / 3; 916 * }); 917 * board.update(); 918 * 919 * })(); 920 * 921 * </script><pre> 922 * 923 * @example 924 * var p1, p2, p3, c, a, s; 925 * 926 * p1 = board.create('point',[0,0]); 927 * p2 = board.create('point',[5,0]); 928 * p3 = board.create('point',[0,5]); 929 * 930 * c1 = board.create('circle',[p1, p2]); 931 * 932 * a = board.create('angle',[p2, p1, p3], {radius:3}); 933 * s = board.create('slider',[[-2,1], [2,1], [0, Math.PI*0.5, 2*Math.PI]]); 934 * 935 * a.setAngle(function() { 936 * return s.Value(); 937 * }); 938 * board.update(); 939 * 940 * </pre><div id="99957b1c-394f-11e6-af4a-901b0e1b8723" class="jxgbox" style="width: 300px; height: 300px;"></div> 941 * <script type="text/javascript"> 942 * (function() { 943 * var board = JXG.JSXGraph.initBoard('99957b1c-394f-11e6-af4a-901b0e1b8723', 944 * {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false}); 945 * var p1, p2, p3, c, a, s; 946 * 947 * p1 = board.create('point',[0,0]); 948 * p2 = board.create('point',[5,0]); 949 * p3 = board.create('point',[0,5]); 950 * 951 * c1 = board.create('circle',[p1, p2]); 952 * 953 * a = board.create('angle',[p2, p1, p3], {radius: 3}); 954 * s = board.create('slider',[[-2,1], [2,1], [0, Math.PI*0.5, 2*Math.PI]]); 955 * 956 * a.setAngle(function() { 957 * return s.Value(); 958 * }); 959 * board.update(); 960 * 961 * })(); 962 * 963 * </script><pre> 964 * 965 */ 966 el.setAngle = function (val) { 967 var t, 968 p = this.anglepoint, 969 q = this.radiuspoint; 970 971 if (p.draggable()) { 972 t = this.board.create('transform', [val, this.center], {type: 'rotate'}); 973 p.addTransform(q, t); 974 p.isDraggable = false; 975 p.setParents(q); 976 } 977 return this; 978 }; 979 980 /** 981 * Frees an angle from a prescribed value. This is only relevant if the angle size has been set by 982 * setAngle() previously. The anglepoint is set to a free point. 983 * @name free 984 * @function 985 * @returns {Object} Pointer to the angle element.. 986 * @memberOf Angle.prototype 987 */ 988 el.free = function () { 989 var p = this.anglepoint; 990 if (p.transformations.length > 0) { 991 p.transformations.pop(); 992 p.isDraggable = true; 993 p.parents = []; 994 } 995 return this; 996 }; 997 998 el.setParents(points); // Important: This overwrites the parents order in underlying sector 999 1000 } // end '3points' 1001 1002 // GEONExT compatible labels. 1003 if (JXG.exists(el.visProp.text)) { 1004 el.label.setText(el.visProp.text); 1005 } 1006 1007 el.elType = 'angle'; 1008 el.type = Const.OBJECT_TYPE_ANGLE; 1009 el.subs = {}; 1010 1011 el.updateDataArraySquare = function () { 1012 var A, B, C, 1013 r = this.Radius(), 1014 d1, d2, 1015 v, l1, l2; 1016 1017 1018 if (type === '2lines') { 1019 // This is necessary to update this.point1, this.point2, this.point3. 1020 this.updateDataArraySector(); 1021 } 1022 1023 A = this.point2; 1024 B = this.point1; 1025 C = this.point3; 1026 1027 A = A.coords.usrCoords; 1028 B = B.coords.usrCoords; 1029 C = C.coords.usrCoords; 1030 1031 d1 = Geometry.distance(A, B, 3); 1032 d2 = Geometry.distance(C, B, 3); 1033 1034 // In case of type=='2lines' this is redundant, because r == d1 == d2 1035 A = [1, B[1] + (A[1] - B[1]) * r / d1, B[2] + (A[2] - B[2]) * r / d1]; 1036 C = [1, B[1] + (C[1] - B[1]) * r / d2, B[2] + (C[2] - B[2]) * r / d2]; 1037 1038 v = Mat.crossProduct(C, B); 1039 l1 = [-A[1] * v[1] - A[2] * v[2], A[0] * v[1], A[0] * v[2]]; 1040 v = Mat.crossProduct(A, B); 1041 l2 = [-C[1] * v[1] - C[2] * v[2], C[0] * v[1], C[0] * v[2]]; 1042 1043 v = Mat.crossProduct(l1, l2); 1044 v[1] /= v[0]; 1045 v[2] /= v[0]; 1046 1047 this.dataX = [B[1], A[1], v[1], C[1], B[1]]; 1048 this.dataY = [B[2], A[2], v[2], C[2], B[2]]; 1049 1050 this.bezierDegree = 1; 1051 }; 1052 1053 el.updateDataArrayNone = function () { 1054 this.dataX = [NaN]; 1055 this.dataY = [NaN]; 1056 this.bezierDegree = 1; 1057 }; 1058 1059 el.updateDataArray = function () { 1060 var type = this.visProp.type, 1061 deg = Geometry.trueAngle(this.point2, this.point1, this.point3); 1062 1063 if ((this.visProp.selection === 'minor' && deg > 180.0) || 1064 (this.visProp.selection === 'major' && deg < 180.0)) { 1065 deg = 360.0 - deg; 1066 } 1067 1068 if (Math.abs(deg - 90.0) < this.visProp.orthosensitivity + Mat.eps) { 1069 type = this.visProp.orthotype; 1070 } 1071 1072 if (type === 'none') { 1073 this.updateDataArrayNone(); 1074 } else if (type === 'square') { 1075 this.updateDataArraySquare(); 1076 } else if (type === 'sector') { 1077 this.updateDataArraySector(); 1078 } else if (type === 'sectordot') { 1079 this.updateDataArraySector(); 1080 if (!this.dot.visProp.visible) { 1081 this.dot.setAttribute({visible: true}); 1082 } 1083 } 1084 1085 if (!this.visProp.visible || (type !== 'sectordot' && this.dot.visProp.visible)) { 1086 this.dot.setAttribute({visible: false}); 1087 } 1088 }; 1089 1090 /** 1091 * Indicates a right angle. Invisible by default, use <tt>dot.visible: true</tt> to show. 1092 * Though this dot indicates a right angle, it can be visible even if the angle is not a right 1093 * one. 1094 * @type JXG.Point 1095 * @name dot 1096 * @memberOf Angle.prototype 1097 */ 1098 attrsub = Type.copyAttributes(attributes, board.options, 'angle', 'dot'); 1099 el.dot = board.create('point', [function () { 1100 var A, B, r, d, a2, co, si, mat, 1101 point1, point2, point3; 1102 1103 if (Type.exists(el.dot) && !el.dot.visProp.visible) { 1104 return [0, 0]; 1105 } 1106 1107 A = el.point2.coords.usrCoords; 1108 B = el.point1.coords.usrCoords; 1109 r = el.Radius(); 1110 d = Geometry.distance(A, B, 3); 1111 a2 = Geometry.rad(el.point2, el.point1, el.point3); 1112 1113 if ((el.visProp.selection === 'minor' && a2 > Math.PI) || 1114 (el.visProp.selection === 'major' && a2 < Math.PI)) { 1115 a2 = -(2 * Math.PI - a2); 1116 } 1117 a2 *= 0.5; 1118 1119 co = Math.cos(a2); 1120 si = Math.sin(a2); 1121 1122 A = [1, B[1] + (A[1] - B[1]) * r / d, B[2] + (A[2] - B[2]) * r / d]; 1123 1124 mat = [ 1125 [1, 0, 0], 1126 [B[1] - 0.5 * B[1] * co + 0.5 * B[2] * si, co * 0.5, -si * 0.5], 1127 [B[2] - 0.5 * B[1] * si - 0.5 * B[2] * co, si * 0.5, co * 0.5] 1128 ]; 1129 return Mat.matVecMult(mat, A); 1130 }], attrsub); 1131 1132 el.dot.dump = false; 1133 el.subs.dot = el.dot; 1134 1135 if (type === '2lines') { 1136 for (i = 0; i < 2; i++) { 1137 board.select(parents[i]).addChild(el.dot); 1138 } 1139 } else { 1140 for (i = 0; i < 3; i++) { 1141 board.select(points[i]).addChild(el.dot); 1142 } 1143 } 1144 1145 // documented in GeometryElement 1146 el.getLabelAnchor = function () { 1147 var vec, dx = 12, dy = 12, 1148 A, B, r, d, a2, co, si, mat; 1149 1150 // If this is uncommented, the angle label can not be dragged 1151 //if (Type.exists(this.label)) { 1152 // this.label.relativeCoords = new Coords(Const.COORDS_BY_SCREEN, [0, 0], this.board); 1153 //} 1154 1155 if (Type.exists(this.label.visProp.fontSize)) { 1156 dx = this.label.visProp.fontSize; 1157 dy = this.label.visProp.fontSize; 1158 } 1159 dx /= this.board.unitX; 1160 dy /= this.board.unitY; 1161 1162 A = el.point2.coords.usrCoords; 1163 B = el.point1.coords.usrCoords; 1164 r = el.Radius(); 1165 d = Geometry.distance(A, B, 3); 1166 a2 = Geometry.rad(el.point2, el.point1, el.point3); 1167 if ((el.visProp.selection === 'minor' && a2 > Math.PI) || 1168 (el.visProp.selection === 'major' && a2 < Math.PI)) { 1169 a2 = -(2 * Math.PI - a2); 1170 } 1171 a2 *= 0.5; 1172 co = Math.cos(a2); 1173 si = Math.sin(a2); 1174 1175 A = [1, B[1] + (A[1] - B[1]) * r / d, B[2] + (A[2] - B[2]) * r / d]; 1176 1177 mat = [ 1178 [1, 0, 0], 1179 [B[1] - 0.5 * B[1] * co + 0.5 * B[2] * si, co * 0.5, -si * 0.5], 1180 [B[2] - 0.5 * B[1] * si - 0.5 * B[2] * co, si * 0.5, co * 0.5] 1181 ]; 1182 vec = Mat.matVecMult(mat, A); 1183 vec[1] /= vec[0]; 1184 vec[2] /= vec[0]; 1185 vec[0] /= vec[0]; 1186 1187 d = Geometry.distance(vec, B, 3); 1188 vec = [vec[0], B[1] + (vec[1] - B[1]) * (r + dx) / d, B[2] + (vec[2] - B[2]) * (r + dx) / d]; 1189 1190 return new Coords(Const.COORDS_BY_USER, vec, this.board); 1191 }; 1192 1193 /** 1194 * Returns the value of the angle in Radians. 1195 * @memberOf Angle.prototype 1196 * @name Value 1197 * @function 1198 * @returns {Number} The angle value in Radians 1199 */ 1200 el.Value = function () { 1201 return Geometry.rad(this.point2, this.point1, this.point3); 1202 }; 1203 1204 el.methodMap = Type.deepCopy(el.methodMap, { 1205 Value: 'Value', 1206 setAngle: 'setAngle', 1207 free: 'free' 1208 }); 1209 1210 return el; 1211 }; 1212 1213 JXG.registerElement('angle', JXG.createAngle); 1214 1215 /** 1216 * @class A non-reflex angle is the acute or obtuse instance of an angle. 1217 * It is defined by a center, one point that 1218 * defines the radius, and a third point that defines the angle of the sector. 1219 * @pseudo 1220 * @name NonReflexAngle 1221 * @augments Angle 1222 * @constructor 1223 * @type Sector 1224 * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown. 1225 * @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 1226 * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3. 1227 * @example 1228 * // Create a non-reflex angle out of three free points 1229 * var p1 = board.create('point', [5.0, 3.0]), 1230 * p2 = board.create('point', [1.0, 0.5]), 1231 * p3 = board.create('point', [1.5, 5.0]), 1232 * 1233 * a = board.create('nonreflexangle', [p1, p2, p3], {radius: 2}), 1234 * t = board.create('text', [4, 4, function() { return a.Value().toFixed(2); }]); 1235 * </pre><div class="jxgbox"id="d0ab6d6b-63a7-48b2-8749-b02bb5e744f9" style="width: 300px; height: 300px;"></div> 1236 * <script type="text/javascript"> 1237 * (function () { 1238 * var board = JXG.JSXGraph.initBoard('d0ab6d6b-63a7-48b2-8749-b02bb5e744f9', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}), 1239 * p1 = board.create('point', [5.0, 3.0]), 1240 * p2 = board.create('point', [1.0, 0.5]), 1241 * p3 = board.create('point', [1.5, 5.0]), 1242 * 1243 * a = board.create('nonreflexangle', [p1, p2, p3], {radius: 2}), 1244 * t = board.create('text', [4, 4, function() { return a.Value().toFixed(2); }]); 1245 * })(); 1246 * </script><pre> 1247 */ 1248 JXG.createNonreflexAngle = function (board, parents, attributes) { 1249 var el; 1250 1251 attributes.selection = 'minor'; 1252 el = JXG.createAngle(board, parents, attributes); 1253 1254 el.Value = function () { 1255 var v = Geometry.rad(this.point2, this.point1, this.point3); 1256 return (v < Math.PI) ? v : 2.0 * Math.PI - v; 1257 }; 1258 return el; 1259 }; 1260 1261 JXG.registerElement('nonreflexangle', JXG.createNonreflexAngle); 1262 1263 /** 1264 * @class A reflex angle is the neither acute nor obtuse instance of an angle. 1265 * It is defined by a center, one point that 1266 * defines the radius, and a third point that defines the angle of the sector. 1267 * @pseudo 1268 * @name ReflexAngle 1269 * @augments Angle 1270 * @constructor 1271 * @type Sector 1272 * @throws {Error} If the element cannot be constructed with the given parent objects an exception is thrown. 1273 * @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 1274 * 180 degrees (pi radians) and starts at p2. The radius is determined by p2, the angle by p3. 1275 * @example 1276 * // Create a non-reflex angle out of three free points 1277 * var p1 = board.create('point', [5.0, 3.0]), 1278 * p2 = board.create('point', [1.0, 0.5]), 1279 * p3 = board.create('point', [1.5, 5.0]), 1280 * 1281 * a = board.create('reflexangle', [p1, p2, p3], {radius: 2}), 1282 * t = board.create('text', [4, 4, function() { return a.Value().toFixed(2); }]); 1283 * </pre><div class="jxgbox"id="f2a577f2-553d-4f9f-a895-2d6d4b8c60e8" style="width: 300px; height: 300px;"></div> 1284 * <script type="text/javascript"> 1285 * (function () { 1286 * var board = JXG.JSXGraph.initBoard('f2a577f2-553d-4f9f-a895-2d6d4b8c60e8', {boundingbox: [-1, 7, 7, -1], axis: true, showcopyright: false, shownavigation: false}), 1287 * p1 = board.create('point', [5.0, 3.0]), 1288 * p2 = board.create('point', [1.0, 0.5]), 1289 * p3 = board.create('point', [1.5, 5.0]), 1290 * 1291 * a = board.create('reflexangle', [p1, p2, p3], {radius: 2}), 1292 * t = board.create('text', [4, 4, function() { return a.Value().toFixed(2); }]); 1293 * })(); 1294 * </script><pre> 1295 */ 1296 JXG.createReflexAngle = function (board, parents, attributes) { 1297 var el; 1298 1299 attributes.selection = 'major'; 1300 el = JXG.createAngle(board, parents, attributes); 1301 1302 el.Value = function () { 1303 var v = Geometry.rad(this.point2, this.point1, this.point3); 1304 return (v >= Math.PI) ? v : 2.0 * Math.PI - v; 1305 }; 1306 return el; 1307 }; 1308 1309 JXG.registerElement('reflexangle', JXG.createReflexAngle); 1310 1311 return { 1312 createSector: JXG.createSector, 1313 createCircumcircleSector: JXG.createCircumcircleSector, 1314 createMinorSector: JXG.createMinorSector, 1315 createMajorSector: JXG.createMajorSector, 1316 createAngle: JXG.createAngle, 1317 createReflexAngle: JXG.createReflexAngle, 1318 createNonreflexAngle: JXG.createNonreflexAngle 1319 }; 1320 }); 1321