pimath 0.1.40 → 0.2.1
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/dist/pimath.js +3106 -2873
- package/dist/pimath.js.map +1 -1
- package/package.json +13 -11
- package/src/algebra/equation.ts +113 -111
- package/src/algebra/equationSolver.ts +69 -120
- package/src/algebra/factor.ts +6 -7
- package/src/algebra/linearSystem.ts +97 -46
- package/src/algebra/logicalset.ts +51 -52
- package/src/algebra/monom.ts +23 -61
- package/src/algebra/operations.ts +0 -1
- package/src/algebra/polyFactor.ts +5 -5
- package/src/algebra/polynom.ts +69 -216
- package/src/analyze/index.ts +4 -0
- package/src/analyze/solution.ts +92 -29
- package/src/analyze/tableOfSigns.ts +1 -1
- package/src/coefficients/fraction.ts +189 -149
- package/src/coefficients/index.ts +1 -1
- package/src/coefficients/root.ts +66 -19
- package/src/geometry/TupleN.ts +128 -0
- package/src/geometry/circle.ts +308 -238
- package/src/geometry/geomMath.ts +4 -3
- package/src/geometry/index.ts +1 -0
- package/src/geometry/line.ts +221 -245
- package/src/geometry/line3.ts +78 -73
- package/src/geometry/plane3.ts +64 -55
- package/src/geometry/point.ts +57 -19
- package/src/geometry/triangle.ts +376 -248
- package/src/geometry/vector.ts +113 -229
- package/src/index.ts +13 -12
- package/src/numeric.ts +6 -9
- package/src/pimath.interface.ts +30 -28
- package/src/randomization/algebra/rndPolynom.ts +29 -15
- package/src/randomization/coefficient/rndFraction.ts +3 -3
- package/src/randomization/geometry/rndLine.ts +8 -10
- package/src/randomization/random.ts +11 -13
- package/src/randomization/rndTypes.ts +16 -12
- package/types/algebra/equation.d.ts +18 -17
- package/types/algebra/equation.d.ts.map +1 -1
- package/types/algebra/equationSolver.d.ts +5 -4
- package/types/algebra/equationSolver.d.ts.map +1 -1
- package/types/algebra/factor.d.ts +1 -1
- package/types/algebra/factor.d.ts.map +1 -1
- package/types/algebra/linearSystem.d.ts +23 -6
- package/types/algebra/linearSystem.d.ts.map +1 -1
- package/types/algebra/logicalset.d.ts +1 -1
- package/types/algebra/logicalset.d.ts.map +1 -1
- package/types/algebra/monom.d.ts +1 -6
- package/types/algebra/monom.d.ts.map +1 -1
- package/types/algebra/operations.d.ts.map +1 -1
- package/types/algebra/polyFactor.d.ts +4 -4
- package/types/algebra/polyFactor.d.ts.map +1 -1
- package/types/algebra/polynom.d.ts +10 -7
- package/types/algebra/polynom.d.ts.map +1 -1
- package/types/analyze/index.d.ts +2 -0
- package/types/analyze/index.d.ts.map +1 -0
- package/types/analyze/solution.d.ts +14 -8
- package/types/analyze/solution.d.ts.map +1 -1
- package/types/coefficients/fraction.d.ts +14 -12
- package/types/coefficients/fraction.d.ts.map +1 -1
- package/types/coefficients/index.d.ts +1 -1
- package/types/coefficients/index.d.ts.map +1 -1
- package/types/coefficients/root.d.ts +3 -0
- package/types/coefficients/root.d.ts.map +1 -1
- package/types/geometry/TupleAbstract.d.ts +22 -0
- package/types/geometry/TupleAbstract.d.ts.map +1 -0
- package/types/geometry/TupleN.d.ts +24 -0
- package/types/geometry/TupleN.d.ts.map +1 -0
- package/types/geometry/circle.d.ts +26 -17
- package/types/geometry/circle.d.ts.map +1 -1
- package/types/geometry/geomMath.d.ts +2 -1
- package/types/geometry/geomMath.d.ts.map +1 -1
- package/types/geometry/index.d.ts.map +1 -1
- package/types/geometry/line.d.ts +21 -30
- package/types/geometry/line.d.ts.map +1 -1
- package/types/geometry/line3.d.ts +19 -19
- package/types/geometry/line3.d.ts.map +1 -1
- package/types/geometry/matrix.d.ts +11 -11
- package/types/geometry/plane3.d.ts +10 -10
- package/types/geometry/plane3.d.ts.map +1 -1
- package/types/geometry/point.d.ts +11 -6
- package/types/geometry/point.d.ts.map +1 -1
- package/types/geometry/triangle.d.ts +68 -23
- package/types/geometry/triangle.d.ts.map +1 -1
- package/types/geometry/vector.d.ts +24 -44
- package/types/geometry/vector.d.ts.map +1 -1
- package/types/index.d.ts +5 -4
- package/types/index.d.ts.map +1 -1
- package/types/numeric.d.ts.map +1 -1
- package/types/pimath.interface.d.ts +18 -24
- package/types/pimath.interface.d.ts.map +1 -1
- package/types/randomization/algebra/rndPolynom.d.ts.map +1 -1
- package/types/randomization/coefficient/rndFraction.d.ts +1 -1
- package/types/randomization/coefficient/rndFraction.d.ts.map +1 -1
- package/types/randomization/geometry/rndLine.d.ts.map +1 -1
- package/types/randomization/random.d.ts +3 -2
- package/types/randomization/random.d.ts.map +1 -1
- package/types/randomization/rndTypes.d.ts +15 -10
- package/types/randomization/rndTypes.d.ts.map +1 -1
- package/src/coefficients/nthRoot.ts +0 -149
package/src/geometry/vector.ts
CHANGED
|
@@ -2,143 +2,43 @@
|
|
|
2
2
|
* Vector2D module contains everything necessary to handle 2d vectors.
|
|
3
3
|
* @module Vector
|
|
4
4
|
*/
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import type {InputValue, IPiMathObject} from "../pimath.interface"
|
|
6
|
+
import {Fraction} from "../coefficients"
|
|
7
|
+
import {Numeric} from "../numeric"
|
|
8
|
+
import {areVectorsColinears, areVectorsEquals, dotProduct} from "./geomMath"
|
|
9
|
+
import {TupleN} from "./TupleN"
|
|
10
|
+
import {type Point} from "./point"
|
|
9
11
|
|
|
10
|
-
export class Vector implements
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
#asPoint = false
|
|
12
|
+
export class Vector extends TupleN implements IPiMathObject<Vector> {
|
|
13
|
+
constructor(...values: (Vector | Point)[] | InputValue<Fraction>[]) {
|
|
14
|
+
super()
|
|
14
15
|
|
|
15
|
-
constructor(...values: Vector[] | InputValue<Fraction>[]) {
|
|
16
16
|
if (values.length > 0) {
|
|
17
17
|
this.parse(...values)
|
|
18
18
|
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// ------------------------------------------
|
|
22
|
-
// Getter and setter
|
|
23
|
-
// ------------------------------------------
|
|
24
|
-
get array(): Fraction[] {
|
|
25
|
-
return this.#array
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
set array(value: Fraction[]) {
|
|
29
|
-
this.#array = value
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get x(): Fraction {
|
|
33
|
-
return this.#array[0]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
set x(value: Fraction | number | string) {
|
|
37
|
-
this.#array[0] = new Fraction(value)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get y(): Fraction {
|
|
41
|
-
return this.#array[1]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
set y(value: Fraction | number | string) {
|
|
45
|
-
this.#array[1] = new Fraction(value)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get z(): Fraction {
|
|
49
|
-
if (this.dimension < 3) { throw new Error('Vector is not 3D') }
|
|
50
|
-
return this.#array[2]
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
set z(value: Fraction | number | string) {
|
|
54
|
-
if (this.dimension < 3) { throw new Error('Vector is not 3D') }
|
|
55
|
-
this.#array[2] = new Fraction(value)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get asPoint(): boolean {
|
|
59
|
-
return this.#asPoint
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
set asPoint(value: boolean) {
|
|
63
|
-
this.#asPoint = value
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
get normSquare(): Fraction {
|
|
68
|
-
// Get the norm square of the vector
|
|
69
|
-
return this.array.reduce((acc, x) => acc.add(x.clone().pow(2)), new Fraction(0))
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get norm(): number {
|
|
73
|
-
return Math.sqrt(this.normSquare.value)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
get tex(): string {
|
|
77
|
-
if (this.#asPoint) {
|
|
78
|
-
return `\\left(${this.array.map(x => x.tex).join(';')}\\right)`
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return `\\begin{pmatrix} ${this.array.map(x => x.tex).join(' \\\\ ')} \\end{pmatrix}`
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
get display(): string {
|
|
85
|
-
if (this.#asPoint) {
|
|
86
|
-
return `(${this.array.map(x => x.display).join(';')})`
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return `((${this.array.map(x => x.display).join(',')}))`
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
setDimension(value = 2): this{
|
|
93
|
-
if (value < 2) {
|
|
94
|
-
throw new Error('Dimension must be at least 2')
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (value < this.dimension) {
|
|
98
|
-
this.#array = this.#array.slice(0, value)
|
|
99
|
-
} else if(value > this.dimension) {
|
|
100
|
-
for(let i = this.dimension; i < value; i++) {
|
|
101
|
-
this.#array.push(new Fraction(0))
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
19
|
|
|
105
20
|
return this
|
|
106
|
-
}
|
|
107
|
-
get dimension(): number {
|
|
108
|
-
return this.array.length
|
|
109
|
-
}
|
|
21
|
+
};
|
|
110
22
|
|
|
111
23
|
// ------------------------------------------
|
|
112
|
-
//
|
|
113
|
-
// ------------------------------------------
|
|
114
|
-
get isNull(): boolean {
|
|
115
|
-
return this.array.every(x => x.isZero())
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
static asTex(...values: string[]): string {
|
|
119
|
-
return `\\begin{pmatrix} ${values.join(' \\\\ ')} \\end{pmatrix}`
|
|
120
|
-
}
|
|
121
|
-
static asDisplay(...values: string[]): string {
|
|
122
|
-
return `((${values.join(',')}))`
|
|
123
|
-
}
|
|
24
|
+
// Getter and setter
|
|
124
25
|
|
|
125
|
-
public
|
|
126
|
-
this.#asPoint = value !== false
|
|
127
|
-
return this
|
|
128
|
-
}
|
|
129
|
-
public parse(...values: Vector[] | InputValue<Fraction>[]): this {
|
|
26
|
+
public parse(...values: (Vector | Point)[] | InputValue<Fraction>[]): this {
|
|
130
27
|
if (values.length === 0) {
|
|
131
28
|
throw new Error(`Invalid value`)
|
|
132
29
|
}
|
|
133
30
|
|
|
134
31
|
if (values.length === 1) {
|
|
135
|
-
if (values[0] instanceof
|
|
136
|
-
|
|
137
|
-
|
|
32
|
+
if (values[0] instanceof TupleN) {
|
|
33
|
+
this.array = values[0].copy()
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (typeof values[0] === 'string') {
|
|
138
38
|
return this.fromString(values[0])
|
|
139
|
-
} else {
|
|
140
|
-
throw new Error(`Invalid value`)
|
|
141
39
|
}
|
|
40
|
+
|
|
41
|
+
throw new Error(`Invalid value`)
|
|
142
42
|
}
|
|
143
43
|
|
|
144
44
|
// Two values are given
|
|
@@ -146,84 +46,56 @@ export class Vector implements
|
|
|
146
46
|
const [A, B] = values
|
|
147
47
|
|
|
148
48
|
// The two values are vectors
|
|
149
|
-
if (A instanceof
|
|
150
|
-
if (A.dimension !== B.dimension) {
|
|
49
|
+
if (A instanceof TupleN && B instanceof TupleN) {
|
|
50
|
+
if (A.dimension !== B.dimension) {
|
|
51
|
+
throw new Error('Vectors must have the same dimension')
|
|
52
|
+
}
|
|
151
53
|
|
|
152
|
-
this
|
|
54
|
+
this.array = B.array.map((x, index) => x.clone().subtract(A.array[index]))
|
|
153
55
|
return this
|
|
154
56
|
}
|
|
155
57
|
}
|
|
156
58
|
|
|
157
59
|
// Two ore more values as number, string, fraction...
|
|
158
|
-
this
|
|
159
|
-
|
|
60
|
+
this.array = values.map(x => new Fraction(x as InputValue<Fraction>))
|
|
160
61
|
return this
|
|
161
62
|
}
|
|
162
63
|
|
|
163
64
|
public clone(): Vector {
|
|
164
|
-
|
|
165
|
-
V.array = this.copy()
|
|
166
|
-
V.asPoint = this.asPoint
|
|
167
|
-
return V
|
|
65
|
+
return new Vector(...this.copy())
|
|
168
66
|
}
|
|
169
67
|
|
|
170
|
-
|
|
171
|
-
return this
|
|
68
|
+
get tex(): string {
|
|
69
|
+
return `\\begin{pmatrix} ${this.array.map(x => x.tex).join(' \\\\ ')} \\end{pmatrix}`
|
|
172
70
|
}
|
|
173
71
|
|
|
174
|
-
|
|
175
|
-
this
|
|
176
|
-
return this
|
|
72
|
+
get display(): string {
|
|
73
|
+
return `((${this.array.map(x => x.display).join(',')}))`
|
|
177
74
|
}
|
|
178
75
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.x.one()
|
|
182
|
-
return this
|
|
76
|
+
static asDisplay(...values: string[]): string {
|
|
77
|
+
return `((${values.join(',')}))`
|
|
183
78
|
}
|
|
184
79
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return this
|
|
80
|
+
static asTex(...values: string[]): string {
|
|
81
|
+
return `\\begin{pmatrix} ${values.join(' \\\\ ')} \\end{pmatrix}`
|
|
188
82
|
}
|
|
189
83
|
|
|
190
84
|
add = (V: Vector): this => {
|
|
191
|
-
this
|
|
85
|
+
this.array.forEach((x, index) => x.add(V.array[index]))
|
|
192
86
|
return this
|
|
193
87
|
}
|
|
194
88
|
|
|
195
|
-
|
|
196
|
-
return this.add(V.clone().opposite())
|
|
197
|
-
}
|
|
89
|
+
angle = (V: Vector, sharp?: boolean, radian?: boolean): number => {
|
|
198
90
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return this
|
|
91
|
+
let scalar = this.dot(V).value
|
|
92
|
+
if (sharp) {
|
|
93
|
+
scalar = Math.abs(scalar)
|
|
203
94
|
}
|
|
204
95
|
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
middleOf(V1: Vector, V2: Vector): this {
|
|
209
|
-
if (V1.dimension !== V2.dimension) { throw new Error('Vectors must be the same dimension') }
|
|
210
|
-
|
|
211
|
-
this.array = []
|
|
212
|
-
V1.array.forEach((x, index) => {
|
|
213
|
-
this.array.push(x.clone().add(V2.array[index]).divide(2))
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
return this
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
translate(...values: Fraction[]): this {
|
|
220
|
-
this.array.forEach((x, index) => x.add(values[index]))
|
|
221
|
-
return this
|
|
222
|
-
}
|
|
223
|
-
|
|
96
|
+
const toDegree = radian ? 1 : 180 / Math.PI
|
|
224
97
|
|
|
225
|
-
|
|
226
|
-
return dotProduct(this, V)
|
|
98
|
+
return toDegree * Math.acos(scalar / (this.norm * V.norm))
|
|
227
99
|
}
|
|
228
100
|
|
|
229
101
|
cross(value: Vector): Vector {
|
|
@@ -238,104 +110,116 @@ export class Vector implements
|
|
|
238
110
|
)
|
|
239
111
|
}
|
|
240
112
|
|
|
241
|
-
|
|
242
|
-
|
|
113
|
+
// ------------------------------------------
|
|
114
|
+
// Creation / parsing functions
|
|
243
115
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
this.#array[0] = y
|
|
247
|
-
this.#array[1] = x
|
|
248
|
-
return this
|
|
116
|
+
divideByScalar = (k: InputValue<Fraction>): this => {
|
|
117
|
+
return this.multiplyByScalar(new Fraction(k).inverse())
|
|
249
118
|
}
|
|
250
119
|
|
|
251
|
-
|
|
252
|
-
return this
|
|
253
|
-
}
|
|
254
|
-
isOne(): boolean {
|
|
255
|
-
return this.array.every((x, index) => index === 0 ? x.isOne() : x.isZero())
|
|
120
|
+
dot = (V: Vector |Point): Fraction => {
|
|
121
|
+
return dotProduct(this, V)
|
|
256
122
|
}
|
|
257
123
|
|
|
258
|
-
|
|
259
|
-
|
|
124
|
+
override fromString(value: string): this {
|
|
125
|
+
if (value.startsWith('((') && value.endsWith('))')) {
|
|
126
|
+
return super.fromString(value.slice(1, -1))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return super.fromString(value)
|
|
260
130
|
}
|
|
261
131
|
|
|
262
132
|
isColinearTo = (v: Vector): boolean => {
|
|
263
133
|
return areVectorsColinears(this, v)
|
|
264
134
|
}
|
|
265
135
|
|
|
136
|
+
isEqual = (v: Vector): boolean => {
|
|
137
|
+
return areVectorsEquals(this, v)
|
|
138
|
+
}
|
|
139
|
+
|
|
266
140
|
isNormalTo = (v: Vector): boolean => {
|
|
267
141
|
return this.dot(v).isZero()
|
|
268
142
|
}
|
|
269
143
|
|
|
144
|
+
// ------------------------------------------
|
|
145
|
+
get isNull(): boolean {
|
|
146
|
+
return this.array.every(x => x.isZero())
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
isOne(): boolean {
|
|
150
|
+
return this.array.every((x, index) => index === 0 ? x.isOne() : x.isZero())
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
isZero(): boolean {
|
|
154
|
+
return this.array.every(x => x.isZero())
|
|
155
|
+
}
|
|
156
|
+
|
|
270
157
|
multiplyByScalar = (k: InputValue<Fraction>): this => {
|
|
271
158
|
const scalar = new Fraction(k)
|
|
272
159
|
this.array.forEach(x => x.multiply(scalar))
|
|
273
160
|
return this
|
|
274
161
|
}
|
|
275
162
|
|
|
276
|
-
|
|
277
|
-
return
|
|
163
|
+
get norm(): number {
|
|
164
|
+
return Math.sqrt(this.normSquare.value)
|
|
278
165
|
}
|
|
279
166
|
|
|
280
|
-
|
|
281
|
-
//
|
|
282
|
-
return this
|
|
283
|
-
.multiplyByScalar(
|
|
284
|
-
Numeric.lcm(...this.array.map(x => x.denominator))
|
|
285
|
-
)
|
|
286
|
-
.divideByScalar(
|
|
287
|
-
Numeric.gcd(...this.array.map(x => x.numerator))
|
|
288
|
-
).
|
|
289
|
-
multiplyByScalar(
|
|
290
|
-
this.x.isNegative() ? -1 : 1
|
|
291
|
-
)
|
|
167
|
+
get normSquare(): Fraction {
|
|
168
|
+
// Get the norm square of the vector
|
|
169
|
+
return this.array.reduce((acc, x) => acc.add(x.clone().pow(2)), new Fraction(0))
|
|
292
170
|
}
|
|
293
171
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (sharp) {
|
|
298
|
-
scalar = Math.abs(scalar)
|
|
172
|
+
normal = (): this => {
|
|
173
|
+
if (this.dimension >= 3) {
|
|
174
|
+
throw new Error('Normal vector can only be determined in 2D')
|
|
299
175
|
}
|
|
300
176
|
|
|
301
|
-
const
|
|
177
|
+
const x = this.x.clone().opposite()
|
|
178
|
+
const y = this.y.clone()
|
|
302
179
|
|
|
303
|
-
|
|
180
|
+
this.array[0] = y
|
|
181
|
+
this.array[1] = x
|
|
182
|
+
return this
|
|
304
183
|
}
|
|
305
184
|
|
|
185
|
+
one = (): this => {
|
|
186
|
+
this.zero()
|
|
187
|
+
this.x.one()
|
|
188
|
+
return this
|
|
189
|
+
}
|
|
306
190
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
191
|
+
opposite = (): this => {
|
|
192
|
+
this.array.forEach(x => x.opposite())
|
|
193
|
+
return this
|
|
194
|
+
}
|
|
312
195
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
196
|
+
simplify = (): this => {
|
|
197
|
+
const lcm = Numeric.lcm(...this.array.map(x => x.denominator))
|
|
198
|
+
const gcd = Numeric.gcd(...this.array.map(x => x.numerator))
|
|
317
199
|
|
|
318
|
-
|
|
319
|
-
const components = value.split(/[,;\s]/g)
|
|
320
|
-
.filter((v) => v.trim() !== '')
|
|
200
|
+
this.multiplyByScalar(new Fraction(lcm, gcd))
|
|
321
201
|
|
|
322
|
-
|
|
323
|
-
if (components.length < 2) {
|
|
324
|
-
return this
|
|
325
|
-
}
|
|
202
|
+
if(this.x.isNegative()) this.opposite()
|
|
326
203
|
|
|
327
|
-
// Validate the fraction values.
|
|
328
|
-
this.#array = components.map(x => new Fraction(x))
|
|
329
204
|
return this
|
|
330
205
|
}
|
|
331
206
|
|
|
332
|
-
|
|
333
|
-
|
|
207
|
+
subtract = (V: Vector): this => {
|
|
208
|
+
return this.add(V.clone().opposite())
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
translate(...values: Fraction[]): this {
|
|
212
|
+
this.array.forEach((x, index) => x.add(values[index]))
|
|
213
|
+
return this
|
|
214
|
+
}
|
|
334
215
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
216
|
+
unit = (): this => {
|
|
217
|
+
const norm = this.norm
|
|
218
|
+
if (norm === 0) {
|
|
219
|
+
return this
|
|
339
220
|
}
|
|
221
|
+
|
|
222
|
+
return this.divideByScalar(norm)
|
|
340
223
|
}
|
|
224
|
+
|
|
341
225
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
// Expose as global
|
|
2
|
-
export * from "./coefficients"
|
|
3
|
-
export * from "./algebra"
|
|
4
|
-
export * from "./geometry"
|
|
5
|
-
|
|
6
|
-
// Import items individually to make a global object
|
|
7
|
-
|
|
8
2
|
// Coefficients
|
|
9
|
-
import {Fraction,
|
|
3
|
+
import {Fraction, Root} from "./coefficients"
|
|
10
4
|
|
|
11
5
|
// Algebra
|
|
12
|
-
import {Equation, Factor, LinearSystem, LogicalSet, Monom, PolyFactor, Polynom
|
|
6
|
+
import {Equation, Factor, LinearSystem, LogicalSet, Matrix, Monom, PolyFactor, Polynom} from "./algebra"
|
|
13
7
|
|
|
14
8
|
// Geometry
|
|
15
|
-
import {Circle, Line, Line3, Plane3, Point, Triangle, Vector
|
|
9
|
+
import {Circle, Line, Line3, Plane3, Point, Sphere3, Triangle, Vector} from "./geometry"
|
|
16
10
|
|
|
17
11
|
// Numeric
|
|
18
12
|
import {Numeric} from "./numeric"
|
|
19
|
-
export {Numeric}
|
|
20
13
|
|
|
21
14
|
// NumExp
|
|
22
15
|
import {NumExp} from "piexpression"
|
|
23
|
-
export {NumExp}
|
|
24
16
|
|
|
25
17
|
// randomization
|
|
26
18
|
import {Random} from "./randomization/random"
|
|
19
|
+
|
|
20
|
+
// export everything to make them available as module
|
|
21
|
+
export * from "./coefficients"
|
|
22
|
+
export * from "./algebra"
|
|
23
|
+
export * from "./geometry"
|
|
24
|
+
export * from "./analyze"
|
|
25
|
+
|
|
26
|
+
export {Numeric}
|
|
27
|
+
export {NumExp}
|
|
27
28
|
export {Random}
|
|
28
29
|
|
|
29
30
|
// Typesetting
|
|
@@ -33,7 +34,7 @@ export type * from "./pimath.interface"
|
|
|
33
34
|
const PiMath = {
|
|
34
35
|
Numeric,
|
|
35
36
|
Fraction,
|
|
36
|
-
Root
|
|
37
|
+
Root,
|
|
37
38
|
Monom,
|
|
38
39
|
Polynom,
|
|
39
40
|
Equation,
|
package/src/numeric.ts
CHANGED
|
@@ -165,19 +165,16 @@ function round(value: number, decimals = 2): number {
|
|
|
165
165
|
function greatestPower(value: number, index: number): number {
|
|
166
166
|
let search_value = Math.floor(Math.pow(value, 1 / index))
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
const radical = value
|
|
169
|
+
const factor = 1
|
|
170
170
|
|
|
171
171
|
while (search_value > 1) {
|
|
172
172
|
const pow = Math.pow(search_value, index)
|
|
173
|
-
if (radical % pow) {
|
|
174
|
-
|
|
175
|
-
radical = radical / pow
|
|
176
|
-
|
|
177
|
-
search_value = Math.floor(Math.pow(radical, 1 / index))
|
|
178
|
-
}else{
|
|
179
|
-
search_value--
|
|
173
|
+
if (radical % pow === 0) {
|
|
174
|
+
return pow
|
|
180
175
|
}
|
|
176
|
+
|
|
177
|
+
search_value--
|
|
181
178
|
}
|
|
182
179
|
|
|
183
180
|
return factor
|
package/src/pimath.interface.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {Fraction
|
|
1
|
+
import type {Fraction} from "./coefficients"
|
|
2
2
|
import type {Equation, Factor, Monom} from "./algebra"
|
|
3
3
|
import type {Line, Point, Vector} from "./geometry"
|
|
4
|
+
import type {Solution} from "./analyze/solution"
|
|
4
5
|
|
|
5
|
-
export type InputValue<T> = T | string | number | Fraction |
|
|
6
|
+
export type InputValue<T> = T | string | number | Fraction // | Root;
|
|
6
7
|
export type InputAlgebra<T> = InputValue<T> | Monom
|
|
7
8
|
export type literalType<T> = Record<string, T>;
|
|
8
9
|
|
|
@@ -26,7 +27,8 @@ export interface IPiMathObject<T> {
|
|
|
26
27
|
|
|
27
28
|
clone(): T;
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
export interface IExpressionBase<T> {
|
|
30
32
|
add(value: InputValue<T>): T;
|
|
31
33
|
|
|
32
34
|
isEqual(value: InputValue<T>): boolean;
|
|
@@ -46,12 +48,13 @@ export interface IExpressionBase<T>{
|
|
|
46
48
|
zero(): T;
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
export interface IExpressionMultiply<T> extends IExpressionBase<T>{
|
|
51
|
+
export interface IExpressionMultiply<T> extends IExpressionBase<T> {
|
|
50
52
|
multiply(value: InputValue<T>): T;
|
|
51
53
|
|
|
52
54
|
pow(value: number): T;
|
|
53
55
|
}
|
|
54
|
-
|
|
56
|
+
|
|
57
|
+
export interface IExpression<T> extends IExpressionMultiply<T> {
|
|
55
58
|
divide(value: InputValue<T>): T | null;
|
|
56
59
|
|
|
57
60
|
inverse(): T | undefined;
|
|
@@ -65,7 +68,7 @@ export interface IEquation<T> {
|
|
|
65
68
|
|
|
66
69
|
reduce(): T;
|
|
67
70
|
|
|
68
|
-
solve():
|
|
71
|
+
solve(): Solution[]
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
export interface IAlgebra<T> {
|
|
@@ -86,18 +89,17 @@ export interface IAnalyse<T> {
|
|
|
86
89
|
primitive(): T;
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
export
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
variable: string,
|
|
92
|
+
export type TABLE_OF_SIGNS_VALUES = '-' | '+' | 'h' | 'z' | 't' | 'd' | 'u' | 'n' | ''
|
|
93
|
+
|
|
94
|
+
export interface TABLE_OF_SIGNS {
|
|
95
|
+
roots: Solution[],
|
|
96
|
+
signs: TABLE_OF_SIGNS_VALUES[]
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
export
|
|
99
|
+
export interface FACTOR_TABLE_OF_SIGNS extends TABLE_OF_SIGNS {
|
|
100
|
+
factor: Factor
|
|
101
|
+
}
|
|
98
102
|
|
|
99
|
-
export interface TABLE_OF_SIGNS {roots: ISolution[], signs: TABLE_OF_SIGNS_VALUES[]}
|
|
100
|
-
export interface FACTOR_TABLE_OF_SIGNS extends TABLE_OF_SIGNS {factor: Factor}
|
|
101
103
|
export interface POLYFACTOR_TABLE_OF_SIGNS extends TABLE_OF_SIGNS {
|
|
102
104
|
factors: FACTOR_TABLE_OF_SIGNS[]
|
|
103
105
|
}
|
|
@@ -131,30 +133,30 @@ export interface remarquableLines {
|
|
|
131
133
|
'A': Line,
|
|
132
134
|
'B': Line,
|
|
133
135
|
'C': Line,
|
|
134
|
-
'intersection':
|
|
135
|
-
},
|
|
136
|
+
'intersection': Point | null
|
|
137
|
+
} | null,
|
|
136
138
|
externalBisectors: {
|
|
137
139
|
'A': Line,
|
|
138
140
|
'B': Line,
|
|
139
141
|
'C': Line,
|
|
140
|
-
'intersection':
|
|
141
|
-
}
|
|
142
|
+
'intersection': Point | null
|
|
143
|
+
} | null,
|
|
142
144
|
'heights': {
|
|
143
145
|
'A': Line,
|
|
144
146
|
'B': Line,
|
|
145
147
|
'C': Line,
|
|
146
|
-
'intersection':
|
|
147
|
-
},
|
|
148
|
+
'intersection': Point | null
|
|
149
|
+
} | null,
|
|
148
150
|
'medians': {
|
|
149
151
|
'A': Line,
|
|
150
152
|
'B': Line,
|
|
151
153
|
'C': Line,
|
|
152
|
-
'intersection':
|
|
153
|
-
},
|
|
154
|
+
'intersection': Point | null
|
|
155
|
+
} | null,
|
|
154
156
|
'mediators': {
|
|
155
|
-
'
|
|
156
|
-
'
|
|
157
|
-
'
|
|
158
|
-
'intersection':
|
|
159
|
-
}
|
|
157
|
+
'a': Line,
|
|
158
|
+
'b': Line,
|
|
159
|
+
'c': Line,
|
|
160
|
+
'intersection': Point | null
|
|
161
|
+
} | null
|
|
160
162
|
}
|