pimath 0.0.126 → 0.0.128

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.
Files changed (121) hide show
  1. package/.idea/jsLibraryMappings.xml +6 -0
  2. package/{public/index.html → dist/demo/exercises.html} +2 -2
  3. package/dist/demo/matrices.html +39 -0
  4. package/dist/demo/playground.html +20 -0
  5. package/dist/demo.css +3 -0
  6. package/dist/pimath.js +4239 -7819
  7. package/dist/pimath.umd.cjs +15 -0
  8. package/index.html +15 -0
  9. package/package.json +16 -8
  10. package/public/demo/exercises.html +283 -0
  11. package/public/demo/matrices.html +39 -0
  12. package/public/demo/playground.html +20 -0
  13. package/src/demo/exercises.ts +0 -0
  14. package/src/demo/matrices.ts +61 -0
  15. package/src/demo/playground.ts +153 -0
  16. package/src/{index.ts → main.ts} +1 -1
  17. package/src/maths/algebra/polynom.ts +9 -16
  18. package/src/maths/algebra/rational.ts +8 -4
  19. package/src/maths/geometry/line.ts +22 -25
  20. package/src/maths/geometry/point.ts +43 -29
  21. package/src/maths/randomization/random.ts +7 -0
  22. package/src/maths/randomization/rndGeometryCircle.ts +50 -0
  23. package/src/maths/randomization/rndTypes.ts +10 -4
  24. package/tests/algebra/polynom.test.ts +10 -0
  25. package/tests/geometry/circle.test.ts +222 -1
  26. package/tests/numeric.test.ts +19 -3
  27. package/tsconfig.json +15 -4
  28. package/vite.config.js +23 -0
  29. package/webpack-production.config.js +22 -22
  30. package/webpack.config.js +22 -22
  31. package/dev/pimath.js +0 -7945
  32. package/dev/pimath.js.map +0 -1
  33. package/dist/pimath.js.map +0 -1
  34. package/dist/pimath.min.js +0 -2
  35. package/dist/pimath.min.js.map +0 -1
  36. package/esm/index.d.ts +0 -38
  37. package/esm/index.js +0 -44
  38. package/esm/index.js.map +0 -1
  39. package/esm/maths/algebra/equation.d.ts +0 -119
  40. package/esm/maths/algebra/equation.js +0 -797
  41. package/esm/maths/algebra/equation.js.map +0 -1
  42. package/esm/maths/algebra/linearSystem.d.ts +0 -39
  43. package/esm/maths/algebra/linearSystem.js +0 -279
  44. package/esm/maths/algebra/linearSystem.js.map +0 -1
  45. package/esm/maths/algebra/logicalset.d.ts +0 -28
  46. package/esm/maths/algebra/logicalset.js +0 -158
  47. package/esm/maths/algebra/logicalset.js.map +0 -1
  48. package/esm/maths/algebra/monom.d.ts +0 -206
  49. package/esm/maths/algebra/monom.js +0 -909
  50. package/esm/maths/algebra/monom.js.map +0 -1
  51. package/esm/maths/algebra/polynom.d.ts +0 -157
  52. package/esm/maths/algebra/polynom.js +0 -1305
  53. package/esm/maths/algebra/polynom.js.map +0 -1
  54. package/esm/maths/algebra/rational.d.ts +0 -46
  55. package/esm/maths/algebra/rational.js +0 -195
  56. package/esm/maths/algebra/rational.js.map +0 -1
  57. package/esm/maths/algebra/study/rationalStudy.d.ts +0 -28
  58. package/esm/maths/algebra/study/rationalStudy.js +0 -244
  59. package/esm/maths/algebra/study/rationalStudy.js.map +0 -1
  60. package/esm/maths/algebra/study.d.ts +0 -143
  61. package/esm/maths/algebra/study.js +0 -380
  62. package/esm/maths/algebra/study.js.map +0 -1
  63. package/esm/maths/coefficients/fraction.d.ts +0 -90
  64. package/esm/maths/coefficients/fraction.js +0 -517
  65. package/esm/maths/coefficients/fraction.js.map +0 -1
  66. package/esm/maths/coefficients/nthRoot.d.ts +0 -23
  67. package/esm/maths/coefficients/nthRoot.js +0 -137
  68. package/esm/maths/coefficients/nthRoot.js.map +0 -1
  69. package/esm/maths/geometry/circle.d.ts +0 -45
  70. package/esm/maths/geometry/circle.js +0 -324
  71. package/esm/maths/geometry/circle.js.map +0 -1
  72. package/esm/maths/geometry/line.d.ts +0 -99
  73. package/esm/maths/geometry/line.js +0 -485
  74. package/esm/maths/geometry/line.js.map +0 -1
  75. package/esm/maths/geometry/point.d.ts +0 -34
  76. package/esm/maths/geometry/point.js +0 -167
  77. package/esm/maths/geometry/point.js.map +0 -1
  78. package/esm/maths/geometry/triangle.d.ts +0 -91
  79. package/esm/maths/geometry/triangle.js +0 -276
  80. package/esm/maths/geometry/triangle.js.map +0 -1
  81. package/esm/maths/geometry/vector.d.ts +0 -41
  82. package/esm/maths/geometry/vector.js +0 -198
  83. package/esm/maths/geometry/vector.js.map +0 -1
  84. package/esm/maths/numeric.d.ts +0 -28
  85. package/esm/maths/numeric.js +0 -136
  86. package/esm/maths/numeric.js.map +0 -1
  87. package/esm/maths/numexp.d.ts +0 -19
  88. package/esm/maths/numexp.js +0 -186
  89. package/esm/maths/numexp.js.map +0 -1
  90. package/esm/maths/randomization/random.d.ts +0 -23
  91. package/esm/maths/randomization/random.js +0 -79
  92. package/esm/maths/randomization/random.js.map +0 -1
  93. package/esm/maths/randomization/randomCore.d.ts +0 -7
  94. package/esm/maths/randomization/randomCore.js +0 -22
  95. package/esm/maths/randomization/randomCore.js.map +0 -1
  96. package/esm/maths/randomization/rndFraction.d.ts +0 -12
  97. package/esm/maths/randomization/rndFraction.js +0 -44
  98. package/esm/maths/randomization/rndFraction.js.map +0 -1
  99. package/esm/maths/randomization/rndGeometryLine.d.ts +0 -12
  100. package/esm/maths/randomization/rndGeometryLine.js +0 -46
  101. package/esm/maths/randomization/rndGeometryLine.js.map +0 -1
  102. package/esm/maths/randomization/rndGeometryPoint.d.ts +0 -12
  103. package/esm/maths/randomization/rndGeometryPoint.js +0 -61
  104. package/esm/maths/randomization/rndGeometryPoint.js.map +0 -1
  105. package/esm/maths/randomization/rndHelpers.d.ts +0 -23
  106. package/esm/maths/randomization/rndHelpers.js +0 -98
  107. package/esm/maths/randomization/rndHelpers.js.map +0 -1
  108. package/esm/maths/randomization/rndMonom.d.ts +0 -12
  109. package/esm/maths/randomization/rndMonom.js +0 -53
  110. package/esm/maths/randomization/rndMonom.js.map +0 -1
  111. package/esm/maths/randomization/rndPolynom.d.ts +0 -13
  112. package/esm/maths/randomization/rndPolynom.js +0 -75
  113. package/esm/maths/randomization/rndPolynom.js.map +0 -1
  114. package/esm/maths/randomization/rndTypes.d.ts +0 -34
  115. package/esm/maths/randomization/rndTypes.js +0 -3
  116. package/esm/maths/randomization/rndTypes.js.map +0 -1
  117. package/esm/maths/shutingyard.d.ts +0 -59
  118. package/esm/maths/shutingyard.js +0 -443
  119. package/esm/maths/shutingyard.js.map +0 -1
  120. package/public/matrices.html +0 -100
  121. package/public/playground.html +0 -168
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE html>
2
+ <html lang="fr">
3
+
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta content="width=device-width, initial-scale=1" name="viewport">
7
+ <title>Getting Started</title>
8
+
9
+ <script type="module" src="../../src/main.ts"></script>
10
+
11
+ <!-- KaTeX -->
12
+ <link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css"
13
+ integrity="sha384-R4558gYOUz8mP9YWpZJjofhk+zx0AS11p36HnD2ZKj/6JR5z27gSSULCNHIRReVs" rel="stylesheet">
14
+
15
+ <!-- The loading of KaTeX is deferred to speed up page rendering -->
16
+ <script crossorigin="anonymous"
17
+ integrity="sha384-z1fJDqw8ZApjGO3/unPWUPsIymfsJmyrDVWC8Tv/a1HeOtGmkwNd/7xUS0Xcnvsx"
18
+ src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js"></script>
19
+
20
+ <!-- To automatically render math in text elements, include the auto-render extension: -->
21
+ <script crossorigin="anonymous"
22
+ integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR"
23
+ onload="renderMathInElement(document.body);"
24
+ src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/contrib/auto-render.min.js"></script>
25
+
26
+ <link href="../demo.css" rel="stylesheet">
27
+ </head>
28
+
29
+ <body>
30
+
31
+ <div id="app">
32
+ </div>
33
+
34
+ <script type="module" src="../../src/demo/matrices.ts">
35
+ </script>
36
+
37
+ </body>
38
+
39
+ </html>
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Getting Started</title>
5
+ <script type="module" src="../../dist/pimath.js"></script>
6
+
7
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
8
+
9
+ <!-- The loading of KaTeX is deferred to speed up page rendering -->
10
+ <script src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>
11
+ <script src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"></script>
12
+ </head>
13
+ <body>
14
+
15
+ <div id="app"></div>
16
+
17
+ <script type="module" src="../../src/demo/playground.ts">
18
+ </script>
19
+ </body>
20
+ </html>
File without changes
@@ -0,0 +1,61 @@
1
+ function detMatrice(M: number[][]): { matrix: number[][], determinant: number } {
2
+ return {
3
+ matrix: M,
4
+ determinant: detnxn(M)
5
+ }
6
+ }
7
+
8
+ function det2x2(M: number[][]): number {
9
+ return M[0][0] * M[1][1] - M[1][0] * M[0][1]
10
+ }
11
+
12
+ function subMatrix(M: number[][], row: number, col: number) {
13
+ let subM = []
14
+
15
+ for (let r = 0; r < M.length; r++) {
16
+ if (r === row) {
17
+ continue
18
+ }
19
+
20
+ let subMrow = []
21
+ for (let c = 0; c < M[r].length; c++) {
22
+ if (c === col) {
23
+ continue
24
+ }
25
+ subMrow.push(M[r][c])
26
+ }
27
+ subM.push(subMrow)
28
+ }
29
+ return subM
30
+ }
31
+
32
+ function detnxn(M: number[][]) {
33
+ let result = 0
34
+
35
+ if (M.length === 2) {
36
+ result = det2x2(M)
37
+ } else {
38
+ for (let i = 0; i < M.length; i++) {
39
+ if (M[i][0] !== 0) {
40
+ result += M[i][0] * Math.pow(-1, i) * detnxn(subMatrix(M, i, 0))
41
+
42
+
43
+ }
44
+ }
45
+ }
46
+
47
+ return result
48
+ }
49
+
50
+ const M = detMatrice([
51
+ [0, 2, -1, 4, 0],
52
+ [3, 5, 0, 0, -2],
53
+ [0, -3, 1, 0, 0],
54
+ [0, 0, -4, 3, -3],
55
+ [-1, 0, 0, 1, 2]
56
+ ])
57
+
58
+ document.getElementById('app').innerHTML = `<p>\\[${M.matrix} = ${M.determinant}\\]</p>`;
59
+
60
+ // @ts-ignore
61
+ renderMathInElement(document.getElementById('app'))
@@ -0,0 +1,153 @@
1
+ import {Point} from "../maths/geometry/point.ts";
2
+ import {Line} from "../maths/geometry/line.ts";
3
+
4
+ let A = new Point(0, 2),
5
+ B = new Point(2, 3),
6
+ C = new Point(1 / 2, 4),
7
+ D = new Point(2, -1 / 2);
8
+
9
+ let L1 = new Line(A, B).simplifyDirection(),
10
+ L2 = new Line(C, D).simplifyDirection();
11
+
12
+ document.getElementById('app').innerHTML = `<p>\\( ${L1.tex.parametric} \\)</p>`;
13
+ document.getElementById('app').innerHTML += `<p>\\( ${L2.tex.parametric} \\)</p>`;
14
+
15
+ let I = L1.intersection(L2);
16
+ if (I.hasIntersection) {
17
+ document.getElementById('app').innerHTML += `<p>\\[ ${L1.intersection(L2).point.tex} \\]</p>`
18
+ } else if (I.isParallel) {
19
+ document.getElementById('app').innerHTML += `<p>Elles sont parallèles</p>`
20
+ } else if (I.isSame) {
21
+ document.getElementById('app').innerHTML += `<p>Elles sont confondues</p>`
22
+ }
23
+
24
+
25
+ // @ts-ignore
26
+ renderMathInElement(document.getElementById('app'), {fleqn: true});
27
+ /*let p;
28
+ p = new Pi.Polynom('3x(6x+9)+6(6x+9)');
29
+ document.getElementById('app').innerHTML = `<p>${p.raw}</p>`;
30
+ document.getElementById('app').innerHTML += `<p>${p.display}</p>`;
31
+
32
+ let v1 = new Pi.Vector('3 4'),
33
+ v2 = new Pi.Vector('-2 5');
34
+
35
+ console.log(v1);
36
+ console.log(v2);
37
+ console.log(Pi.Vector.scalarProduct(v1, v2));
38
+
39
+
40
+ let P = new Pi.Polynom('(x+5)(x-17)(37x+35)');
41
+ let Q = new Pi.Polynom('1');
42
+ P.factorize(100)
43
+
44
+ P.factors.forEach(n=> {
45
+ console.log(n.tex)
46
+ Q.multiply(n);
47
+ })
48
+
49
+ // Check that we have the same polynom.
50
+ console.log(P.tex);
51
+ console.log(Q.tex);
52
+
53
+
54
+
55
+
56
+
57
+ /*let n = new Pi.Polynom(),
58
+ d = new Pi.Polynom();
59
+ n.parse('(x+3)(x+4)');
60
+ d.parse('(x+3)(x-2)')
61
+
62
+ let r = new Pi.Rational(n, d);
63
+ document.getElementById('app').innerHTML = `<p>${r.tex}</p>`*/
64
+
65
+
66
+ /*
67
+ let M = new Pi.Monom().random('x', 2, false, false);
68
+ console.log(M.displayWithSign);
69
+
70
+ let S = new Pi.LinearSystem().parse(
71
+ 'x-3y=-2',
72
+ '4x+7x=1'
73
+ );
74
+ S.solve();
75
+ document.getElementById('app').innerHTML = `<p>${S.tex}</p>`;
76
+ document.getElementById('app').innerHTML += `<p>${S.texSolution}</p>`;
77
+ let S = new Pi.LinearSystem().generate(3,-5,2);
78
+ document.getElementById('app').innerHTML = `<p>${S.tex}</p>`;
79
+ S.solve();
80
+ S.log;
81
+ S.tex;
82
+
83
+ S = new Pi.LinearSystem().generate(-1,8,-2);
84
+ document.getElementById('app').innerHTML += `<p>${S.tex}</p>`;
85
+ S.solve();
86
+ S.log;
87
+
88
+ let P = new Pi.Polynom('3x^2+5yx-2');
89
+ console.log(P.tex);
90
+ console.log(P.numberOfVars);
91
+ P.replaceBy('y', new Pi.Polynom('2x+1'));
92
+ console.log(P.tex);
93
+
94
+ let A = new Pi.Equation('2x+3y=5');
95
+ console.log(A.tex);
96
+
97
+ A.isolate('x');
98
+ console.log(A.tex);
99
+
100
+ A.isolate('y');
101
+ console.log(A.tex);
102
+
103
+ let P = new Pi.Polynom().rndSimple(2).makeItComplicate();
104
+ console.log(P.tex);
105
+ console.log(P.texString);
106
+
107
+ let A = new Pi.Fraction().parse('2/5');
108
+ console.log(A.frac);
109
+
110
+ let F = new Pi.Fraction().parse('18/5');
111
+ let N = new Pi.Root().parse(F).reduce();
112
+ console.log(N.tex);
113
+
114
+ let E = new Pi.Equation().create(new Pi.Polynom().parse('x^2+6x-8'), new Pi.Polynom().zero());
115
+ E.solve();
116
+ console.log(E.solutions);
117
+
118
+ let D = 42;
119
+ console.log(Pi.Numeric.dividers(D));
120
+
121
+ let X = new Pi.Polynom().rndFactorable(2, false);
122
+ console.log(X.tex);
123
+ X.factors.forEach(function(P, i){
124
+ console.log(P.tex);
125
+ });
126
+
127
+ let EQ = new Pi.Equation('2x+3>=5x-2');
128
+ EQ.solve();
129
+ console.log(EQ.solution);
130
+
131
+ EQ.parseString('2x+3<5x-2');
132
+ EQ.solve();
133
+ console.log(EQ.solution);
134
+
135
+ EQ.parseString('7x+3>5x-2');
136
+ EQ.solve();
137
+ console.log(EQ.solution);
138
+
139
+ EQ.parseString('7x+3=<5x-2');
140
+ EQ.solve();
141
+ console.log(EQ.solution);
142
+
143
+ EQ.parseString('7x+3=<7x-2');
144
+ EQ.solve();
145
+ console.log(EQ.solution);
146
+
147
+ EQ.parseString('7x+3>7x-2');
148
+ EQ.solve();
149
+ console.log(EQ.solution);
150
+
151
+ EQ.parseString('x^2+6x+9>=0');
152
+ EQ.solve();
153
+ console.log(EQ.solution);*/
@@ -39,4 +39,4 @@ export const PiMath = {
39
39
  }
40
40
  };
41
41
 
42
- // (<any>window).Pi = PiMath
42
+ // (<any>window).PiMath = PiMath
@@ -23,6 +23,13 @@ export interface IEuclidian {
23
23
  */
24
24
  export class Polynom {
25
25
  private _rawString: string;
26
+ private _dirty_factors: boolean
27
+ private _dirty_zeroes: boolean
28
+ private _euclidianCache: { [Key: string]: IEuclidian }
29
+ private _factors: Polynom[];
30
+ private _monoms: Monom[];
31
+ private _texString: string;
32
+ private _zeroes: ISolution[]
26
33
 
27
34
  /**
28
35
  *
@@ -40,8 +47,6 @@ export class Polynom {
40
47
  return this;
41
48
  }
42
49
 
43
- private _dirty_factors: boolean
44
-
45
50
  // ------------------------------------------
46
51
  get dirty_factors(): boolean {
47
52
  return this._dirty_factors;
@@ -51,8 +56,6 @@ export class Polynom {
51
56
  this._dirty_factors = value;
52
57
  }
53
58
 
54
- private _dirty_zeroes: boolean
55
-
56
59
  get dirty_zeroes(): boolean {
57
60
  return this._dirty_zeroes;
58
61
  }
@@ -61,8 +64,6 @@ export class Polynom {
61
64
  this._dirty_zeroes = value;
62
65
  }
63
66
 
64
- private _euclidianCache: { [Key: string]: IEuclidian }
65
-
66
67
  get euclidianCache(): { [p: string]: IEuclidian } {
67
68
  return this._euclidianCache;
68
69
  }
@@ -71,8 +72,6 @@ export class Polynom {
71
72
  this._euclidianCache = value;
72
73
  }
73
74
 
74
- private _factors: Polynom[];
75
-
76
75
  get factors(): Polynom[] {
77
76
  return this.factorize()
78
77
  }
@@ -82,8 +81,6 @@ export class Polynom {
82
81
  this._factors = value;
83
82
  }
84
83
 
85
- private _monoms: Monom[];
86
-
87
84
  // ------------------------------------------
88
85
  get monoms() {
89
86
  return this._monoms;
@@ -93,14 +90,10 @@ export class Polynom {
93
90
  this._monoms = M;
94
91
  }
95
92
 
96
- private _texString: string;
97
-
98
93
  get texString(): string {
99
94
  return this._texString;
100
95
  }
101
96
 
102
- private _zeroes: ISolution[]
103
-
104
97
  get zeroes(): ISolution[] {
105
98
  return this.getZeroes()
106
99
  }
@@ -495,11 +488,11 @@ export class Polynom {
495
488
  // Get the greatest monom divided by the max monom of the divider
496
489
  newM = reminder.monomByDegree(undefined, letter).clone().divide(maxMP);
497
490
 
498
- if (newM.isZero()) break;
491
+ if (newM.isZero()) continue;
499
492
 
500
493
  // Get the new quotient and reminder.
501
494
  quotient.add(newM);
502
- reminder.subtract(P.clone().multiply(newM));
495
+ reminder.subtract(P.clone().multiply(newM)).reduce();
503
496
 
504
497
  // Check if the reminder is zero.
505
498
  if (newM.degree(letter).isZero()) break
@@ -62,6 +62,10 @@ export class Rational {
62
62
  return `\\frac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`
63
63
  }
64
64
 
65
+ get displayFactors(): string {
66
+ return `(${this._numerator.displayFactors})/(${this._denominator.displayFactors})`;
67
+ }
68
+
65
69
  get plotFunction(): string {
66
70
  return `(${this._numerator.plotFunction})/(${this._denominator.plotFunction})`
67
71
  }
@@ -131,12 +135,12 @@ export class Rational {
131
135
  this._numerator.factorize();
132
136
  for (let f of this._numerator.factors) {
133
137
 
134
- if(f.degree().isZero()){
138
+ if (f.degree().isZero()) {
135
139
  // Do the simplify only if the factor can divide the denominator
136
- if(this._denominator.commonMonom().coefficient.clone().divide(f.monomByDegree().coefficient).isNatural()){
140
+ if (this._denominator.commonMonom().coefficient.clone().divide(f.monomByDegree().coefficient).isNatural()) {
137
141
  this.simplify(f);
138
142
  }
139
- }else {
143
+ } else {
140
144
  this.simplify(f);
141
145
  }
142
146
  }
@@ -234,7 +238,7 @@ export class Rational {
234
238
  return this._numerator.evaluateAsNumeric(values) / this._denominator.evaluateAsNumeric(values)
235
239
  }
236
240
 
237
- study = (config?:StudyConfig|string): RationalStudy => {
241
+ study = (config?: StudyConfig | string): RationalStudy => {
238
242
  return new RationalStudy(this, config)
239
243
  }
240
244
  }
@@ -9,7 +9,6 @@ import {Fraction} from "../coefficients/fraction";
9
9
  import {Equation} from "../algebra/equation";
10
10
  import {Polynom} from "../algebra/polynom";
11
11
  import {Random} from "../randomization/random";
12
- import {LinearSystem} from "../algebra/linearSystem";
13
12
  import {Monom} from "../algebra/monom";
14
13
 
15
14
  export enum LinePropriety {
@@ -26,7 +25,20 @@ export class Line {
26
25
  private _referencePropriety: LinePropriety
27
26
  private _referenceLine: Line
28
27
  private _reduceBeforeDisplay: boolean
28
+ // ax + by + c = 0
29
+ private _a: Fraction;
30
+ private _b: Fraction;
31
+ private _c: Fraction;
32
+ private _OA: Point;
33
+ private _d: Vector;
34
+ private _n: Vector;
35
+ private _exists: boolean
29
36
 
37
+ /**
38
+ * Value can be a mix of:
39
+ *
40
+ * @param values
41
+ */
30
42
  constructor(...values: unknown[]) {
31
43
 
32
44
  this._exists = false;
@@ -39,19 +51,17 @@ export class Line {
39
51
  return this;
40
52
  }
41
53
 
42
- // ax + by + c = 0
43
- private _a: Fraction;
44
-
45
54
  get a(): Fraction {
46
55
  return this._a;
47
56
  }
48
57
 
58
+ // ------------------------------------------
59
+ // Getter and setter
60
+
49
61
  set a(value: Fraction) {
50
62
  this._a = value;
51
63
  }
52
64
 
53
- private _b: Fraction;
54
-
55
65
  get b(): Fraction {
56
66
  return this._b;
57
67
  }
@@ -60,21 +70,14 @@ export class Line {
60
70
  this._b = value;
61
71
  }
62
72
 
63
- private _c: Fraction;
64
-
65
73
  get c(): Fraction {
66
74
  return this._c;
67
75
  }
68
76
 
69
- // ------------------------------------------
70
- // Getter and setter
71
-
72
77
  set c(value: Fraction) {
73
78
  this._c = value;
74
79
  }
75
80
 
76
- private _OA: Point;
77
-
78
81
  get OA(): Point {
79
82
  return this._OA;
80
83
  }
@@ -83,8 +86,6 @@ export class Line {
83
86
  this._OA = value;
84
87
  }
85
88
 
86
- private _d: Vector;
87
-
88
89
  get d(): Vector {
89
90
  return this._d;
90
91
  }
@@ -93,14 +94,10 @@ export class Line {
93
94
  this._d = value;
94
95
  }
95
96
 
96
- private _n: Vector;
97
-
98
97
  get n(): Vector {
99
98
  return this._n;
100
99
  }
101
100
 
102
- private _exists: boolean
103
-
104
101
  get exists(): boolean {
105
102
  return this._exists;
106
103
  }
@@ -108,19 +105,19 @@ export class Line {
108
105
  // ------------------------------------------
109
106
  get equation(): Equation {
110
107
  let equ = new Equation(new Polynom().parse('xy', this._a, this._b, this._c), new Polynom('0'))
111
- if(this._reduceBeforeDisplay) {
108
+ if (this._reduceBeforeDisplay) {
112
109
  return equ.simplify();
113
- }else{
110
+ } else {
114
111
  return equ
115
112
  }
116
113
  }
117
114
 
118
115
  get system(): { x: Equation, y: Equation } {
119
116
  let e1 = new Equation(
120
- new Polynom('x'),
121
- new Polynom(this._OA.x)
122
- .add(new Monom('k').multiplyByNumber(this._d.x))
123
- ),
117
+ new Polynom('x'),
118
+ new Polynom(this._OA.x)
119
+ .add(new Monom('k').multiplyByNumber(this._d.x))
120
+ ),
124
121
  e2 = new Equation(
125
122
  new Polynom('y'),
126
123
  new Polynom(this._OA.y)
@@ -73,6 +73,20 @@ export class Point {
73
73
 
74
74
  // ------------------------------------------
75
75
  // Creation / parsing functions
76
+
77
+ get key(): string {
78
+ return `${this.x.display};${this.y.display}`
79
+ }
80
+
81
+ // ------------------------------------------
82
+ static pmatrix = (a: any, b: any, c?: any): string => {
83
+ if (c === undefined) {
84
+ return `\\begin{pmatrix} ${a.tex ? a.tex : a} \\\\ ${b.tex ? b.tex : b} \\end{pmatrix}`;
85
+ } else {
86
+ return `\\begin{pmatrix} ${a.tex ? a.tex : a} \\\\ ${b.tex ? b.tex : b} \\\\ ${c.tex ? c.tex : c} \\end{pmatrix}`;
87
+ }
88
+ };
89
+
76
90
  // ------------------------------------------
77
91
  parse = (...values: unknown[]): Point => {
78
92
  // Initialize the value.
@@ -103,9 +117,9 @@ export class Point {
103
117
  }
104
118
 
105
119
  // Value given as an object with {x: value, y: value}
106
- if(values[0] instanceof PointXY){
107
- this._x = new Fraction(values[0].x).reduce()
108
- this._y = new Fraction(values[0].y).reduce()
120
+ if (values[0] instanceof PointXY) {
121
+ this._x = new Fraction(values[0].x).reduce()
122
+ this._y = new Fraction(values[0].y).reduce()
109
123
  return this
110
124
  } else {
111
125
  return this.zero()
@@ -138,6 +152,8 @@ export class Point {
138
152
  this.zero();
139
153
  return this;
140
154
  }
155
+ // ------------------------------------------
156
+ // Display functions
141
157
 
142
158
  middleOf = (P1: Point, P2: Point): Point => {
143
159
  this._x = P1.x.clone().add(P2.x).divide(2);
@@ -146,17 +162,6 @@ export class Point {
146
162
  return this;
147
163
  }
148
164
  // ------------------------------------------
149
- // Display functions
150
- // ------------------------------------------
151
- texValues = (numberOfDigits: number): string => {
152
- let pts = [];
153
-
154
- pts.push(this._x.value.toFixed(numberOfDigits === undefined ? 2 : numberOfDigits));
155
- pts.push(this._y.value.toFixed(numberOfDigits === undefined ? 2 : numberOfDigits));
156
-
157
- return `\\left(${pts.join(';')}\\right)`
158
- }
159
- // ------------------------------------------
160
165
  // Mathematical operations
161
166
  // ------------------------------------------
162
167
 
@@ -166,36 +171,45 @@ export class Point {
166
171
 
167
172
  // ------------------------------------------
168
173
  // Static functions
174
+
175
+ translate = (value: { x: number | Fraction, y: number | Fraction }): Point => {
176
+ this._x = this._x.add(value.x)
177
+ this._y = this._y.add(value.y)
178
+ return this
179
+ }
180
+
169
181
  // ------------------------------------------
170
- static pmatrix = (a: any, b: any, c?: any): string => {
171
- if (c === undefined) {
172
- return `\\begin{pmatrix} ${a.tex ? a.tex : a} \\\\ ${b.tex ? b.tex : b} \\end{pmatrix}`;
173
- } else {
174
- return `\\begin{pmatrix} ${a.tex ? a.tex : a} \\\\ ${b.tex ? b.tex : b} \\\\ ${c.tex ? c.tex : c} \\end{pmatrix}`;
175
- }
176
- };
182
+ texValues = (numberOfDigits: number): string => {
183
+ let pts = [];
184
+
185
+ pts.push(this._x.value.toFixed(numberOfDigits === undefined ? 2 : numberOfDigits));
186
+ pts.push(this._y.value.toFixed(numberOfDigits === undefined ? 2 : numberOfDigits));
187
+
188
+ return `\\left(${pts.join(';')}\\right)`
189
+ }
177
190
 
178
- distanceTo = (item:Point|Line): { value: number, fraction: Fraction, tex: string } => {
191
+ distanceTo = (item: Point | Line): { value: number, fraction: Fraction, tex: string } => {
179
192
  let value = 0, fraction = new Fraction(), tex = ''
180
193
 
181
- if(item instanceof Line){
194
+ if (item instanceof Line) {
182
195
  return item.distanceTo(this)
183
- }else if(item instanceof Point){
196
+ } else if (item instanceof Point) {
184
197
  let V = new Vector(this, item)
185
198
 
186
199
  value = V.norm
187
200
  fraction = V.normSquare.sqrt()
188
201
  tex = V.normSquare.isSquare() ? fraction.tex : `\\sqrt{\\frac{ ${V.normSquare.numerator} }{ ${V.normSquare.denominator} }}`
189
202
  }
190
- return { value, fraction, tex }
203
+ return {value, fraction, tex}
191
204
  }
192
205
 
193
- get key(): string {
194
- return `${this.x.display};${this.y.display}`
195
- }
196
206
  isInListOfPoints = (list: Point[]): boolean => {
197
- const keyList = list.map(x=>x.key)
207
+ const keyList = list.map(x => x.key)
198
208
 
199
209
  return keyList.includes(this.key)
200
210
  }
211
+
212
+ isEqual = (pt: Point): boolean => {
213
+ return this.x.isEqual(pt.x) && this.y.isEqual(pt.y)
214
+ }
201
215
  }
@@ -3,6 +3,7 @@ import {rndMonom} from "./rndMonom";
3
3
  import {rndHelpers} from "./rndHelpers";
4
4
  import {
5
5
  randomCoefficientConfig,
6
+ randomGeometryCircleConfig,
6
7
  randomGeometryLineConfig,
7
8
  randomGeometryPointConfig,
8
9
  randomMonomConfig,
@@ -16,6 +17,8 @@ import {Line} from "../geometry/line";
16
17
  import {rndGeometryLine} from "./rndGeometryLine";
17
18
  import {Point} from "../geometry/point";
18
19
  import {rndGeometryPoint} from "./rndGeometryPoint";
20
+ import {Circle} from "../geometry/circle";
21
+ import {rndGeometryCircle} from "./rndGeometryCircle";
19
22
 
20
23
  export * from "./rndTypes"
21
24
 
@@ -69,5 +72,9 @@ export namespace Random {
69
72
  return (new rndGeometryPoint(config).generate())
70
73
  }
71
74
 
75
+ export function circle(config?: randomGeometryCircleConfig): Circle {
76
+ return (new rndGeometryCircle(config).generate())
77
+ }
78
+
72
79
  }
73
80
  }