pimath 0.0.17 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dev/index.html +46 -9
- package/dev/pi.js +890 -806
- package/dev/pi.js.map +1 -1
- package/dist/pi.js +1 -1
- package/dist/pi.js.map +1 -1
- package/esm/maths/algebra/equation.d.ts +1 -0
- package/esm/maths/algebra/equation.js +5 -2
- package/esm/maths/algebra/equation.js.map +1 -1
- package/esm/maths/algebra/monom.d.ts +1 -1
- package/esm/maths/algebra/monom.js +27 -18
- package/esm/maths/algebra/monom.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +0 -1
- package/esm/maths/algebra/polynom.js +7 -11
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/geometry/circle.d.ts +16 -1
- package/esm/maths/geometry/circle.js +89 -12
- package/esm/maths/geometry/circle.js.map +1 -1
- package/esm/maths/geometry/line.d.ts +20 -4
- package/esm/maths/geometry/line.js +109 -39
- package/esm/maths/geometry/line.js.map +1 -1
- package/esm/maths/geometry/point.d.ts +1 -0
- package/esm/maths/geometry/point.js +6 -0
- package/esm/maths/geometry/point.js.map +1 -1
- package/esm/maths/geometry/vector.d.ts +0 -1
- package/esm/maths/geometry/vector.js +1 -4
- package/esm/maths/geometry/vector.js.map +1 -1
- package/esm/maths/random/rndFraction.js +8 -2
- package/esm/maths/random/rndFraction.js.map +1 -1
- package/esm/maths/random/rndMonom.js +2 -1
- package/esm/maths/random/rndMonom.js.map +1 -1
- package/esm/maths/random/rndTypes.d.ts +1 -0
- package/package.json +1 -1
- package/src/maths/algebra/equation.ts +7 -2
- package/src/maths/algebra/monom.ts +40 -25
- package/src/maths/algebra/polynom.ts +9 -13
- package/src/maths/geometry/circle.ts +133 -21
- package/src/maths/geometry/line.ts +161 -57
- package/src/maths/geometry/point.ts +9 -0
- package/src/maths/geometry/vector.ts +1 -5
- package/src/maths/random/rndFraction.ts +7 -2
- package/src/maths/random/rndMonom.ts +2 -1
- package/src/maths/random/rndTypes.ts +2 -1
- package/tests/algebra/monom.test.ts +25 -7
- package/tsconfig.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rndMonom.js","sourceRoot":"","sources":["../../../src/maths/random/rndMonom.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AAExC,mCAA+B;AAC/B,4CAAuC;AAKnC,MAAa,QAAS,SAAQ,uBAAU;IAIpC,YAAY,UAA8B;QACtC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,cAAc,GAAG;YAClB,OAAO,EAAE,GAAG;YACZ,MAAM,EAAE,CAAC;YACT,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,KAAK;SACd,CAAA;QAED,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;IACpE,CAAC;IAED,QAAQ,GAAG,GAAU,EAAE;QAEnB,IAAI,CAAC,GAAG,IAAI,aAAK,EAAE,CAAA;QAGnB,CAAC,CAAC,WAAW,GAAG,cAAM,CAAC,QAAQ,CAAC;YAC5B,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YACvB,OAAO,EAAE,IAAI;
|
|
1
|
+
{"version":3,"file":"rndMonom.js","sourceRoot":"","sources":["../../../src/maths/random/rndMonom.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AAExC,mCAA+B;AAC/B,4CAAuC;AAKnC,MAAa,QAAS,SAAQ,uBAAU;IAIpC,YAAY,UAA8B;QACtC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,cAAc,GAAG;YAClB,OAAO,EAAE,GAAG;YACZ,MAAM,EAAE,CAAC;YACT,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,KAAK;SACd,CAAA;QAED,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;IACpE,CAAC;IAED,QAAQ,GAAG,GAAU,EAAE;QAEnB,IAAI,CAAC,GAAG,IAAI,aAAK,EAAE,CAAA;QAGnB,CAAC,CAAC,WAAW,GAAG,cAAM,CAAC,QAAQ,CAAC;YAC5B,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YACvB,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ;SAClC,CAAC,CAAA;QAGF,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;YAEjC,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;gBAC1C,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACrB;YACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC1C,MAAM,CAAC,GAAG,cAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;gBACrD,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;aAC7C;SACJ;aAAM;YACH,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;SACzD;QAED,OAAO,CAAC,CAAA;IACZ,CAAC,CAAA;CACJ;AA5CD,4BA4CC"}
|
package/package.json
CHANGED
|
@@ -37,8 +37,8 @@ export class Equation {
|
|
|
37
37
|
this.parse(equations[0]);
|
|
38
38
|
}
|
|
39
39
|
} else if (equations.length === 2) {
|
|
40
|
-
this.left = equations[0]
|
|
41
|
-
this.right = equations[1]
|
|
40
|
+
this.left = (equations[0] instanceof Polynom) ? equations[0].clone() : new Polynom(equations[0]);
|
|
41
|
+
this.right = (equations[1] instanceof Polynom) ? equations[1].clone() : new Polynom(equations[1]);
|
|
42
42
|
} else {
|
|
43
43
|
// Return default empty equation
|
|
44
44
|
return this;
|
|
@@ -101,6 +101,11 @@ export class Equation {
|
|
|
101
101
|
return `${this._left.tex}${this.signAsTex}${this._right.tex}`;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
get display(): string {
|
|
105
|
+
return `${this._left.display}${this.signAsTex}${this._right.display}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
104
109
|
get raw(): string {
|
|
105
110
|
return `${this._left.raw}${this.signAsTex}${this._right.raw}`;
|
|
106
111
|
}
|
|
@@ -33,10 +33,6 @@ export class Monom {
|
|
|
33
33
|
// ------------------------------------------
|
|
34
34
|
// Getter and setter
|
|
35
35
|
// ------------------------------------------
|
|
36
|
-
get isMonom() {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
36
|
/**
|
|
41
37
|
* Get the coefficient as fraction
|
|
42
38
|
*/
|
|
@@ -311,10 +307,10 @@ export class Monom {
|
|
|
311
307
|
|
|
312
308
|
let stack: Monom[] = [], m, pow, letter, q1, q2
|
|
313
309
|
|
|
314
|
-
if(rpn.length===0){
|
|
310
|
+
if (rpn.length === 0) {
|
|
315
311
|
this.zero()
|
|
316
312
|
return this
|
|
317
|
-
}else if(rpn.length===1){
|
|
313
|
+
} else if (rpn.length === 1) {
|
|
318
314
|
const element = rpn[0]
|
|
319
315
|
|
|
320
316
|
this.one()
|
|
@@ -324,9 +320,8 @@ export class Monom {
|
|
|
324
320
|
this.setLetter(element.token, 1)
|
|
325
321
|
}
|
|
326
322
|
return this
|
|
327
|
-
}else{
|
|
323
|
+
} else {
|
|
328
324
|
// Reset the monom
|
|
329
|
-
this.one()
|
|
330
325
|
for (const element of rpn) {
|
|
331
326
|
if (element.tokenType === 'coefficient') {
|
|
332
327
|
let M = new Monom().one()
|
|
@@ -343,16 +338,15 @@ export class Monom {
|
|
|
343
338
|
q2 = (stack.pop()) || new Monom().zero()
|
|
344
339
|
q1 = (stack.pop()) || new Monom().zero()
|
|
345
340
|
|
|
346
|
-
if(q1.isZero() && q2.isZero()){
|
|
347
|
-
this.opposed()
|
|
348
|
-
break
|
|
349
|
-
}
|
|
350
341
|
stack.push(q1.subtract(q2))
|
|
342
|
+
|
|
351
343
|
break;
|
|
352
344
|
case '*':
|
|
353
345
|
// Get the last element in the stack
|
|
354
|
-
|
|
355
|
-
|
|
346
|
+
q2 = (stack.pop()) || new Monom().one()
|
|
347
|
+
q1 = (stack.pop()) || new Monom().one()
|
|
348
|
+
|
|
349
|
+
stack.push(q1.multiply(q2))
|
|
356
350
|
break
|
|
357
351
|
case '^':
|
|
358
352
|
// get the two last elements in the stack
|
|
@@ -361,16 +355,20 @@ export class Monom {
|
|
|
361
355
|
|
|
362
356
|
letter = m.variables[0]
|
|
363
357
|
|
|
364
|
-
if(letter!==undefined) {
|
|
358
|
+
if (letter !== undefined) {
|
|
365
359
|
m.setLetter(letter, pow)
|
|
366
360
|
}
|
|
367
|
-
|
|
361
|
+
|
|
362
|
+
stack.push(m)
|
|
363
|
+
// this.multiply(m.clone())
|
|
368
364
|
break
|
|
369
365
|
}
|
|
370
366
|
}
|
|
371
367
|
}
|
|
372
368
|
}
|
|
373
369
|
|
|
370
|
+
this.one()
|
|
371
|
+
this.multiply(stack[0])
|
|
374
372
|
return this
|
|
375
373
|
}
|
|
376
374
|
/**
|
|
@@ -388,6 +386,14 @@ export class Monom {
|
|
|
388
386
|
return F;
|
|
389
387
|
};
|
|
390
388
|
|
|
389
|
+
makeSame = (M: Monom):Monom => {
|
|
390
|
+
// Copy the literal parts.
|
|
391
|
+
for (let k in M._literal) {
|
|
392
|
+
this.setLetter(k, M._literal[k].clone());
|
|
393
|
+
}
|
|
394
|
+
return this
|
|
395
|
+
}
|
|
396
|
+
|
|
391
397
|
/**
|
|
392
398
|
* Create a zero value monom
|
|
393
399
|
*/
|
|
@@ -439,6 +445,9 @@ export class Monom {
|
|
|
439
445
|
add = (...M: Monom[]): Monom => {
|
|
440
446
|
for (let m of M) {
|
|
441
447
|
if (this.isSameAs(m)) {
|
|
448
|
+
if(this.isZero()){
|
|
449
|
+
this.makeSame(m)
|
|
450
|
+
}
|
|
442
451
|
this._coefficient.add(m.coefficient);
|
|
443
452
|
} else {
|
|
444
453
|
console.log('Add: Is not similar: ', m.display);
|
|
@@ -454,7 +463,10 @@ export class Monom {
|
|
|
454
463
|
subtract = (...M: Monom[]): Monom => {
|
|
455
464
|
for (let m of M) {
|
|
456
465
|
if (this.isSameAs(m)) {
|
|
457
|
-
this.
|
|
466
|
+
if(this.isZero()){
|
|
467
|
+
this.makeSame(m)
|
|
468
|
+
}
|
|
469
|
+
this._coefficient.add(m.clone().coefficient.opposed());
|
|
458
470
|
} else {
|
|
459
471
|
console.log('Subtract: Is not similar: ', m.display);
|
|
460
472
|
}
|
|
@@ -571,14 +583,17 @@ export class Monom {
|
|
|
571
583
|
M2: string[] = M.variables,
|
|
572
584
|
K: string[] = M1.concat(M2.filter((item) => M1.indexOf(item) < 0));
|
|
573
585
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
586
|
+
// To compare, both must be different than zero.
|
|
587
|
+
if (!this.isZero() && !M.isZero()) {
|
|
588
|
+
for (let key of K) {
|
|
589
|
+
// The setLetter is not available in one of the monom
|
|
590
|
+
if (this._literal[key] === undefined || M.literal[key] === undefined) {
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
// The setLetter does not have the isSame power in each monoms.
|
|
594
|
+
if (!this._literal[key].isEqual(M.literal[key])) {
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
582
597
|
}
|
|
583
598
|
}
|
|
584
599
|
|
|
@@ -34,11 +34,6 @@ export class Polynom {
|
|
|
34
34
|
return this;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
get isPolynom() {
|
|
38
|
-
return true;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
|
|
42
37
|
// ------------------------------------------
|
|
43
38
|
// Getter and setter
|
|
44
39
|
// ------------------------------------------
|
|
@@ -365,9 +360,9 @@ export class Polynom {
|
|
|
365
360
|
add = (...values: any[]): Polynom => {
|
|
366
361
|
|
|
367
362
|
for (let value of values) {
|
|
368
|
-
if (value
|
|
363
|
+
if (value instanceof Polynom) {
|
|
369
364
|
this._monoms = this._monoms.concat(value.monoms);
|
|
370
|
-
} else if (value
|
|
365
|
+
} else if (value instanceof Monom) {
|
|
371
366
|
this._monoms.push(value.clone());
|
|
372
367
|
} else if (Number.isSafeInteger(value)) {
|
|
373
368
|
this._monoms.push(new Monom(value.toString()));
|
|
@@ -382,9 +377,9 @@ export class Polynom {
|
|
|
382
377
|
subtract = (...values: any[]): Polynom => {
|
|
383
378
|
|
|
384
379
|
for (let value of values) {
|
|
385
|
-
if (value
|
|
380
|
+
if (value instanceof Polynom) {
|
|
386
381
|
this._monoms = this._monoms.concat(value.clone().opposed().monoms);
|
|
387
|
-
} else if (value
|
|
382
|
+
} else if (value instanceof Monom) {
|
|
388
383
|
this._monoms.push(value.clone().opposed());
|
|
389
384
|
} else if (Number.isSafeInteger(value)) {
|
|
390
385
|
this._monoms.push(new Monom(value.toString()).opposed());
|
|
@@ -753,7 +748,7 @@ export class Polynom {
|
|
|
753
748
|
* @param P
|
|
754
749
|
*/
|
|
755
750
|
replaceBy = (letter: string, P: Polynom): Polynom => {
|
|
756
|
-
let pow:
|
|
751
|
+
let pow: Fraction;
|
|
757
752
|
const resultPolynom: Polynom = new Polynom().zero();
|
|
758
753
|
|
|
759
754
|
for (const m of this.monoms) {
|
|
@@ -762,10 +757,11 @@ export class Polynom {
|
|
|
762
757
|
} else {
|
|
763
758
|
// We have found a setLetter.
|
|
764
759
|
// Get the power and reset it.
|
|
765
|
-
pow =
|
|
760
|
+
pow = m.literal[letter].clone();
|
|
766
761
|
delete m.literal[letter];
|
|
767
762
|
|
|
768
|
-
|
|
763
|
+
// TODO: replaceBy works only with positive and natural pow
|
|
764
|
+
resultPolynom.add(P.clone().pow(Math.abs(pow.numerator)).multiply(m));
|
|
769
765
|
}
|
|
770
766
|
}
|
|
771
767
|
|
|
@@ -1100,7 +1096,7 @@ export class Polynom {
|
|
|
1100
1096
|
// Reduce the polynom.
|
|
1101
1097
|
const M = this.clone().reduce();
|
|
1102
1098
|
for (const m of M._monoms) {
|
|
1103
|
-
if (m.degree(letter)
|
|
1099
|
+
if (m.degree(letter).isEqual(degree)) {
|
|
1104
1100
|
return m.clone();
|
|
1105
1101
|
}
|
|
1106
1102
|
}
|
|
@@ -1,47 +1,159 @@
|
|
|
1
1
|
import {Point} from "./point";
|
|
2
|
-
import {Fraction} from "../coefficients
|
|
3
|
-
import {Equation} from "../algebra
|
|
4
|
-
import {
|
|
2
|
+
import {Fraction} from "../coefficients";
|
|
3
|
+
import {Equation, Monom, Polynom} from "../algebra";
|
|
4
|
+
import {Line} from "./line";
|
|
5
|
+
import {Vector} from "./vector";
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
export class Circle {
|
|
8
9
|
private _center: Point;
|
|
9
10
|
private _radius: Fraction;
|
|
11
|
+
private _squareRadius: Fraction;
|
|
12
|
+
private _cartesian: Equation;
|
|
10
13
|
private _exists: boolean;
|
|
14
|
+
|
|
11
15
|
constructor(...values: any) {
|
|
12
16
|
this._exists = false
|
|
13
17
|
|
|
14
|
-
if(values!==undefined){
|
|
18
|
+
if (values !== undefined) {
|
|
19
|
+
this.parse(...values)
|
|
20
|
+
}
|
|
15
21
|
}
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
|
|
24
|
+
get center(): Point {
|
|
25
|
+
return this._center;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get radius(): { tex: string, display: string } {
|
|
29
|
+
if (this._squareRadius.isSquare()) {
|
|
30
|
+
return {
|
|
31
|
+
tex: this._squareRadius.clone().sqrt().tex,
|
|
32
|
+
display: this._squareRadius.clone().sqrt().display,
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
return {
|
|
36
|
+
tex: `\\sqrt{${this._squareRadius.tex}}`,
|
|
37
|
+
display: `sqrt(${this._squareRadius.display})`
|
|
38
|
+
}
|
|
21
39
|
}
|
|
40
|
+
return this._squareRadius
|
|
22
41
|
}
|
|
23
42
|
|
|
24
43
|
get tex(): string {
|
|
25
44
|
let cx, cy
|
|
26
|
-
if(this._center.x.isZero()){
|
|
45
|
+
if (this._center.x.isZero()) {
|
|
27
46
|
cx = 'x^2'
|
|
28
|
-
}else{
|
|
29
|
-
cx = `\\left(x
|
|
47
|
+
} else {
|
|
48
|
+
cx = `\\left(x${this._center.x.isNegative() ? '+' : '-'}${this._center.x.clone().abs().tex}\\right)^2`
|
|
30
49
|
}
|
|
31
|
-
if(this._center.y.isZero()){
|
|
50
|
+
if (this._center.y.isZero()) {
|
|
32
51
|
cy = 'y^2'
|
|
33
|
-
}else{
|
|
34
|
-
cy = `\\left(y
|
|
52
|
+
} else {
|
|
53
|
+
cy = `\\left(y${this._center.y.isNegative() ? '+' : '-'}${this._center.y.clone().abs().tex}\\right)^2`
|
|
54
|
+
}
|
|
55
|
+
return `${cx}+${cy}=${this._squareRadius.tex}`
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get developed(): string {
|
|
59
|
+
return this._cartesian.tex
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
// TODO: reformat code for better display.
|
|
64
|
+
get display(): string {
|
|
65
|
+
return this._cartesian.display
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get cartesian(): Equation {
|
|
69
|
+
return this._cartesian
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private parse(...values: any) {
|
|
73
|
+
if (values.length === 1 && typeof values[0] === 'string') {
|
|
74
|
+
this.checkCircle(new Equation(values[0]))
|
|
75
|
+
} else if (values.length >= 2) {
|
|
76
|
+
this._center = new Point(values[0])
|
|
77
|
+
|
|
78
|
+
if (values[1] instanceof Point) {
|
|
79
|
+
// Go through this point
|
|
80
|
+
this._squareRadius = new Vector(this._center, values[1]).normSquare
|
|
81
|
+
} else {
|
|
82
|
+
if (values[2] === true) {
|
|
83
|
+
this._squareRadius = new Fraction(values[1])
|
|
84
|
+
} else {
|
|
85
|
+
this._radius = new Fraction(values[1])
|
|
86
|
+
this._squareRadius = this._radius.clone().pow(2)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
this._cartesian = (new Equation(
|
|
90
|
+
new Polynom(`(x-(${this._center.x.display}))^2+(y-(${this._center.y.display}))^2`),
|
|
91
|
+
new Polynom(`${this._squareRadius.display}`)
|
|
92
|
+
)).moveLeft()
|
|
35
93
|
}
|
|
36
|
-
return `${cx}+${cy}=${this._radius.pow(2).tex}`
|
|
37
94
|
}
|
|
38
95
|
|
|
39
|
-
get developed():string {
|
|
40
|
-
let equ = new Equation(
|
|
41
|
-
new Polynom(`(x-(${this._center.x.display}))^2+(y-(${this._center.y.display}))^2`),
|
|
42
|
-
new Polynom(`${this._radius.pow(2).display}`)
|
|
43
|
-
)
|
|
44
96
|
|
|
45
|
-
|
|
97
|
+
checkCircle = (P: Equation): boolean => {
|
|
98
|
+
if (P.degree('x').value === 2 && P.degree('y').value === 2) {
|
|
99
|
+
// Both must be of degree 2.
|
|
100
|
+
let x2 = P.left.monomByDegree(2, 'x'),
|
|
101
|
+
y2 = P.left.monomByDegree(2, 'y'),
|
|
102
|
+
x1: Monom, y1: Monom, c: Monom
|
|
103
|
+
|
|
104
|
+
// Both square monoms must have the same coefficient.
|
|
105
|
+
if (x2.coefficient.isEqual(y2.coefficient)) {
|
|
106
|
+
P.divide(x2.coefficient)
|
|
107
|
+
|
|
108
|
+
x1 = P.left.monomByDegree(1, 'x')
|
|
109
|
+
y1 = P.left.monomByDegree(1, 'y')
|
|
110
|
+
|
|
111
|
+
c = P.left.monomByDegree(0)
|
|
112
|
+
|
|
113
|
+
this._center = new Point(
|
|
114
|
+
x1.coefficient.clone().divide(2).opposed(),
|
|
115
|
+
y1.coefficient.clone().divide(2).opposed()
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
this._squareRadius = c.coefficient.clone().opposed()
|
|
119
|
+
.add(this._center.x.clone().pow(2))
|
|
120
|
+
.add(this._center.y.clone().pow(2))
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return false
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Get the relative position between circle and line. It corresponds to the number of intersection.
|
|
130
|
+
* @param {Line} L
|
|
131
|
+
* @returns {number}
|
|
132
|
+
*/
|
|
133
|
+
relativePosition = (L: Line): number => {
|
|
134
|
+
let distance = L.distanceTo(this.center),
|
|
135
|
+
radius = Math.sqrt(this._squareRadius.value)
|
|
136
|
+
|
|
137
|
+
if (distance.value - radius > 0.0000000001) {
|
|
138
|
+
return 0 // external
|
|
139
|
+
} else if (Math.abs(distance.value - radius) < 0.0000000001) {
|
|
140
|
+
return 1 // tangent
|
|
141
|
+
} else {
|
|
142
|
+
return 2 // external
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
lineIntersection = (L: Line): Point[] => {
|
|
147
|
+
let P1: Point, P2: Point
|
|
148
|
+
|
|
149
|
+
const equ = this._cartesian.clone(),
|
|
150
|
+
yLine = L.equation.clone().isolate('y')
|
|
151
|
+
|
|
152
|
+
if (yLine instanceof Equation) {
|
|
153
|
+
equ.replaceBy('y', yLine.right)
|
|
154
|
+
equ.solve()
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return []
|
|
46
158
|
}
|
|
47
159
|
}
|