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.
Files changed (99) hide show
  1. package/dist/pimath.js +3106 -2873
  2. package/dist/pimath.js.map +1 -1
  3. package/package.json +13 -11
  4. package/src/algebra/equation.ts +113 -111
  5. package/src/algebra/equationSolver.ts +69 -120
  6. package/src/algebra/factor.ts +6 -7
  7. package/src/algebra/linearSystem.ts +97 -46
  8. package/src/algebra/logicalset.ts +51 -52
  9. package/src/algebra/monom.ts +23 -61
  10. package/src/algebra/operations.ts +0 -1
  11. package/src/algebra/polyFactor.ts +5 -5
  12. package/src/algebra/polynom.ts +69 -216
  13. package/src/analyze/index.ts +4 -0
  14. package/src/analyze/solution.ts +92 -29
  15. package/src/analyze/tableOfSigns.ts +1 -1
  16. package/src/coefficients/fraction.ts +189 -149
  17. package/src/coefficients/index.ts +1 -1
  18. package/src/coefficients/root.ts +66 -19
  19. package/src/geometry/TupleN.ts +128 -0
  20. package/src/geometry/circle.ts +308 -238
  21. package/src/geometry/geomMath.ts +4 -3
  22. package/src/geometry/index.ts +1 -0
  23. package/src/geometry/line.ts +221 -245
  24. package/src/geometry/line3.ts +78 -73
  25. package/src/geometry/plane3.ts +64 -55
  26. package/src/geometry/point.ts +57 -19
  27. package/src/geometry/triangle.ts +376 -248
  28. package/src/geometry/vector.ts +113 -229
  29. package/src/index.ts +13 -12
  30. package/src/numeric.ts +6 -9
  31. package/src/pimath.interface.ts +30 -28
  32. package/src/randomization/algebra/rndPolynom.ts +29 -15
  33. package/src/randomization/coefficient/rndFraction.ts +3 -3
  34. package/src/randomization/geometry/rndLine.ts +8 -10
  35. package/src/randomization/random.ts +11 -13
  36. package/src/randomization/rndTypes.ts +16 -12
  37. package/types/algebra/equation.d.ts +18 -17
  38. package/types/algebra/equation.d.ts.map +1 -1
  39. package/types/algebra/equationSolver.d.ts +5 -4
  40. package/types/algebra/equationSolver.d.ts.map +1 -1
  41. package/types/algebra/factor.d.ts +1 -1
  42. package/types/algebra/factor.d.ts.map +1 -1
  43. package/types/algebra/linearSystem.d.ts +23 -6
  44. package/types/algebra/linearSystem.d.ts.map +1 -1
  45. package/types/algebra/logicalset.d.ts +1 -1
  46. package/types/algebra/logicalset.d.ts.map +1 -1
  47. package/types/algebra/monom.d.ts +1 -6
  48. package/types/algebra/monom.d.ts.map +1 -1
  49. package/types/algebra/operations.d.ts.map +1 -1
  50. package/types/algebra/polyFactor.d.ts +4 -4
  51. package/types/algebra/polyFactor.d.ts.map +1 -1
  52. package/types/algebra/polynom.d.ts +10 -7
  53. package/types/algebra/polynom.d.ts.map +1 -1
  54. package/types/analyze/index.d.ts +2 -0
  55. package/types/analyze/index.d.ts.map +1 -0
  56. package/types/analyze/solution.d.ts +14 -8
  57. package/types/analyze/solution.d.ts.map +1 -1
  58. package/types/coefficients/fraction.d.ts +14 -12
  59. package/types/coefficients/fraction.d.ts.map +1 -1
  60. package/types/coefficients/index.d.ts +1 -1
  61. package/types/coefficients/index.d.ts.map +1 -1
  62. package/types/coefficients/root.d.ts +3 -0
  63. package/types/coefficients/root.d.ts.map +1 -1
  64. package/types/geometry/TupleAbstract.d.ts +22 -0
  65. package/types/geometry/TupleAbstract.d.ts.map +1 -0
  66. package/types/geometry/TupleN.d.ts +24 -0
  67. package/types/geometry/TupleN.d.ts.map +1 -0
  68. package/types/geometry/circle.d.ts +26 -17
  69. package/types/geometry/circle.d.ts.map +1 -1
  70. package/types/geometry/geomMath.d.ts +2 -1
  71. package/types/geometry/geomMath.d.ts.map +1 -1
  72. package/types/geometry/index.d.ts.map +1 -1
  73. package/types/geometry/line.d.ts +21 -30
  74. package/types/geometry/line.d.ts.map +1 -1
  75. package/types/geometry/line3.d.ts +19 -19
  76. package/types/geometry/line3.d.ts.map +1 -1
  77. package/types/geometry/matrix.d.ts +11 -11
  78. package/types/geometry/plane3.d.ts +10 -10
  79. package/types/geometry/plane3.d.ts.map +1 -1
  80. package/types/geometry/point.d.ts +11 -6
  81. package/types/geometry/point.d.ts.map +1 -1
  82. package/types/geometry/triangle.d.ts +68 -23
  83. package/types/geometry/triangle.d.ts.map +1 -1
  84. package/types/geometry/vector.d.ts +24 -44
  85. package/types/geometry/vector.d.ts.map +1 -1
  86. package/types/index.d.ts +5 -4
  87. package/types/index.d.ts.map +1 -1
  88. package/types/numeric.d.ts.map +1 -1
  89. package/types/pimath.interface.d.ts +18 -24
  90. package/types/pimath.interface.d.ts.map +1 -1
  91. package/types/randomization/algebra/rndPolynom.d.ts.map +1 -1
  92. package/types/randomization/coefficient/rndFraction.d.ts +1 -1
  93. package/types/randomization/coefficient/rndFraction.d.ts.map +1 -1
  94. package/types/randomization/geometry/rndLine.d.ts.map +1 -1
  95. package/types/randomization/random.d.ts +3 -2
  96. package/types/randomization/random.d.ts.map +1 -1
  97. package/types/randomization/rndTypes.d.ts +15 -10
  98. package/types/randomization/rndTypes.d.ts.map +1 -1
  99. package/src/coefficients/nthRoot.ts +0 -149
@@ -2,19 +2,19 @@
2
2
  * This class works for 2d line in a plane.
3
3
  */
4
4
 
5
- import { Fraction } from "../coefficients/fraction"
6
- import { Polynom } from "../algebra/polynom"
7
- import { Monom } from "../algebra/monom"
8
- import { randomIntSym } from "../randomization/rndHelpers"
9
- import { Vector } from "./vector"
10
- import { Point } from "./point"
5
+ import {Fraction} from "../coefficients/fraction"
6
+ import {Polynom} from "../algebra/polynom"
7
+ import {Monom} from "../algebra/monom"
8
+ import {randomIntSym} from "../randomization/rndHelpers"
9
+ import {Vector} from "./vector"
10
+ import {Point} from "./point"
11
11
  import {Line3Propriety} from "../pimath.interface"
12
12
 
13
13
 
14
14
  export class Line3 {
15
+ static PARALLEL = Line3Propriety.Parallel
15
16
  // A line is defined as the canonical form
16
17
  static PERPENDICULAR = Line3Propriety.Perpendicular
17
- static PARALLEL = Line3Propriety.Parallel
18
18
  // ax + by + c = 0
19
19
  #OA: Point = new Point()
20
20
  #d: Vector = new Vector()
@@ -28,27 +28,15 @@ export class Line3 {
28
28
  constructor(A: Point, d: Vector)
29
29
  constructor(A: Point, d: Vector | Point) {
30
30
  this.#OA = A.clone()
31
- this.#d = d.asPoint ? new Vector(A, d) : d.clone()
31
+ this.#d = (d instanceof Point) ? new Vector(A, d) : d.clone()
32
32
  return this
33
33
  }
34
34
 
35
- get OA(): Point {
36
- return this.#OA
37
- }
38
-
39
- set OA(value: Point) {
40
- this.#OA = value
41
- }
42
- get point(): Point {
43
- return this.#OA.clone()
44
- }
45
-
46
- get d(): Vector {
47
- return this.#d
48
- }
35
+ clone = (): this => {
36
+ this.#d = this.#d.clone()
37
+ this.#OA = this.#OA.clone()
49
38
 
50
- set d(value: Vector) {
51
- this.#d = value
39
+ return this
52
40
  }
53
41
 
54
42
  get tex(): { parametric: string, system: string, cartesian: string } {
@@ -88,53 +76,24 @@ export class Line3 {
88
76
  }
89
77
  }
90
78
 
91
- get direction(): Vector {
92
- return this.#d.clone()
79
+ get OA(): Point {
80
+ return this.#OA
93
81
  }
94
82
 
95
- clone = (): this => {
96
- this.#d = this.#d.clone()
97
- this.#OA = this.#OA.clone()
98
-
99
- return this
100
- }
101
- // ------------------------------------------
102
- // Mathematical operations
103
- // ------------------------------------------
104
- isOnLine = (pt: Point): boolean => {
105
- return false
83
+ set OA(value: Point) {
84
+ this.#OA = value
106
85
  }
107
86
 
108
- isParallelTo = (line: Line3): boolean => {
109
- // Do they have the isSame direction ?
110
- throw new Error('Method not implemented.')
111
- }
112
- isSameAs = (line: Line3): boolean => {
113
- throw new Error('Method not implemented.')
114
- }
115
- isPerpendicularTo = (line: Line3): boolean => {
116
- throw new Error('Method not implemented.')
117
- }
118
- isVertical = (): boolean => {
119
- throw new Error('Method not implemented.')
87
+ get d(): Vector {
88
+ return this.#d
120
89
  }
121
- simplify = (): this => {
122
- throw new Error('Method not implemented.')
123
- // const lcm = Numeric.lcm(this.#a.denominator, this.#b.denominator, this.#c.denominator),
124
- // gcd = Numeric.gcd(this.#a.numerator, this.#b.numerator, this.#c.numerator)
125
-
126
- // this.fromCoefficient(
127
- // this.#a.clone().multiply(lcm).divide(gcd),
128
- // this.#b.clone().multiply(lcm).divide(gcd),
129
- // this.#c.clone().multiply(lcm).divide(gcd),
130
- // )
131
90
 
132
- // return this
91
+ set d(value: Vector) {
92
+ this.#d = value
133
93
  }
134
94
 
135
- intersection = (line: Line3): { point: Vector, hasIntersection: boolean, isParallel: boolean, isSame: boolean } => {
136
-
137
- throw new Error('Method not implemented.')
95
+ get direction(): Vector {
96
+ return this.#d.clone()
138
97
  }
139
98
 
140
99
  distanceTo(pt: Point): { value: number, fraction: Fraction, tex: string } {
@@ -147,13 +106,14 @@ export class Line3 {
147
106
  num2d2 = num2.clone().divide(d2),
148
107
  dnum = num2d2.clone().sqrt()
149
108
 
150
- console.log('CROSS', AP.cross(d).display)
151
109
  return {
152
110
  value: Math.sqrt(num2d2.value),
153
111
  fraction: num2d2.clone().sqrt(),
154
- tex: dnum.isExact() ? dnum.tex : `\\sqrt{${num2d2.tex}}`
112
+ tex: dnum.exact ? dnum.tex : `\\sqrt{${num2d2.tex}}`
155
113
  }
156
114
  }
115
+ // ------------------------------------------
116
+ // Mathematical operations
157
117
 
158
118
  hitSegment(A: Point, B: Point): boolean {
159
119
  const iPt = this.intersection(
@@ -172,6 +132,48 @@ export class Line3 {
172
132
  return false
173
133
  }
174
134
 
135
+ intersection = (line: Line3): { point: Vector, hasIntersection: boolean, isParallel: boolean, isSame: boolean } => {
136
+
137
+ throw new Error('Method not implemented.')
138
+ }
139
+
140
+ // ------------------------------------------
141
+ isOnLine = (pt: Point): boolean => {
142
+ return false
143
+ }
144
+
145
+ isParallelTo = (line: Line3): boolean => {
146
+ // Do they have the isSame direction ?
147
+ throw new Error('Method not implemented.')
148
+ }
149
+
150
+ isPerpendicularTo = (line: Line3): boolean => {
151
+ throw new Error('Method not implemented.')
152
+ }
153
+
154
+ isSameAs = (line: Line3): boolean => {
155
+ throw new Error('Method not implemented.')
156
+ }
157
+
158
+ isVertical = (): boolean => {
159
+ throw new Error('Method not implemented.')
160
+ }
161
+
162
+ get point(): Point {
163
+ return this.#OA.clone()
164
+ }
165
+
166
+ randomPoint = (max = 5): Point => {
167
+ const A = this.#OA.clone(),
168
+ k = new Fraction(randomIntSym(max, false))
169
+
170
+ return new Point(
171
+ A.x.clone().add(this.#d.x.clone().multiply(k)),
172
+ A.y.clone().add(this.#d.y.clone().multiply(k)),
173
+ A.z.clone().add(this.#d.z.clone().multiply(k))
174
+ )
175
+ }
176
+
175
177
  // getValueAtX = (value: Fraction | number): Fraction => {
176
178
  // const equ = this.equation.clone().isolate('y'),
177
179
  // F = new Fraction(value)
@@ -193,14 +195,17 @@ export class Line3 {
193
195
  // return new Fraction().invalid()
194
196
  // }
195
197
 
196
- randomPoint = (max = 5): Point => {
197
- const A = this.#OA.clone(),
198
- k = new Fraction(randomIntSym(max, false))
198
+ simplify = (): this => {
199
+ throw new Error('Method not implemented.')
200
+ // const lcm = Numeric.lcm(this.#a.denominator, this.#b.denominator, this.#c.denominator),
201
+ // gcd = Numeric.gcd(this.#a.numerator, this.#b.numerator, this.#c.numerator)
199
202
 
200
- return new Point(
201
- A.x.clone().add(this.#d.x.clone().multiply(k)),
202
- A.y.clone().add(this.#d.y.clone().multiply(k)),
203
- A.z.clone().add(this.#d.z.clone().multiply(k))
204
- )
203
+ // this.fromCoefficient(
204
+ // this.#a.clone().multiply(lcm).divide(gcd),
205
+ // this.#b.clone().multiply(lcm).divide(gcd),
206
+ // this.#c.clone().multiply(lcm).divide(gcd),
207
+ // )
208
+
209
+ // return this
205
210
  }
206
211
  }
@@ -1,13 +1,12 @@
1
- import { Equation } from "../algebra/equation"
2
- import { Polynom } from "../algebra/polynom"
3
- import { Fraction } from "../coefficients/fraction"
4
- import { Line3 } from "./line3"
5
- import { Point } from "./point"
6
- import { Vector } from "./vector"
1
+ import {Equation} from "../algebra/equation"
2
+ import {Polynom} from "../algebra/polynom"
3
+ import {Fraction} from "../coefficients/fraction"
4
+ import {Line3} from "./line3"
5
+ import {Point} from "./point"
6
+ import {Vector} from "./vector"
7
7
  import type {Plane3Config} from "../pimath.interface"
8
8
 
9
9
 
10
-
11
10
  export class Plane3 {
12
11
  #normal: Vector = new Vector(0, 0, 1)
13
12
  #point: Point = new Point(0, 0, 0)
@@ -20,50 +19,6 @@ export class Plane3 {
20
19
  return this
21
20
  }
22
21
 
23
- get normal(): Vector {
24
- return this.#normal
25
- }
26
- set normal(value: Vector) {
27
- this.#normal = value
28
- this.#normal.asPoint = false
29
- }
30
- get point(): Point {
31
- return this.#point
32
- }
33
- set point(value: Point) {
34
- this.#point = value
35
- this.#point.asPoint = true
36
- }
37
-
38
- get a(): Fraction {
39
- return this.#normal.x
40
- }
41
- get b(): Fraction {
42
- return this.#normal.y
43
- }
44
- get c(): Fraction {
45
- return this.#normal.z
46
- }
47
- get d(): Fraction {
48
- return this.#normal.dot(this.#point).opposite()
49
- }
50
-
51
- get tex(): string {
52
- // return the cartesian equation of the plane
53
- return new Equation(
54
- new Polynom('xyz', this.a, this.b, this.c, this.d),
55
- new Polynom(0)
56
- ).reduce().tex
57
- }
58
-
59
- get display(): string {
60
- // return the cartesian equation of the plane
61
- return new Equation(
62
- new Polynom('xyz', this.a, this.b, this.c, this.d),
63
- new Polynom(0)
64
- ).reduce().display
65
- }
66
-
67
22
  parse(config: Plane3Config) {
68
23
  if (config.point && config.normal) {
69
24
  this.point = config.point
@@ -121,9 +76,32 @@ export class Plane3 {
121
76
  }
122
77
  }
123
78
 
79
+ get tex(): string {
80
+ // return the cartesian equation of the plane
81
+ return new Equation(
82
+ new Polynom('xyz', this.a, this.b, this.c, this.d),
83
+ new Polynom(0)
84
+ ).reduce().tex
85
+ }
86
+
87
+ get display(): string {
88
+ // return the cartesian equation of the plane
89
+ return new Equation(
90
+ new Polynom('xyz', this.a, this.b, this.c, this.d),
91
+ new Polynom(0)
92
+ ).reduce().display
93
+ }
94
+
95
+ get a(): Fraction {
96
+ return this.#normal.x
97
+ }
98
+
124
99
  angle(vector: Vector, sharp?: boolean, radian?: boolean): number
100
+
125
101
  angle(line: Line3, sharp?: boolean, radian?: boolean): number
102
+
126
103
  angle(plane: Plane3, sharp?: boolean, radian?: boolean): number
104
+
127
105
  angle(value: Plane3 | Line3 | Vector, sharp?: boolean, radian?: boolean): number {
128
106
  if (value instanceof Plane3) {
129
107
  return this.normal.angle(value.normal, sharp, radian)
@@ -144,20 +122,35 @@ export class Plane3 {
144
122
  return a90 - this.normal.angle(direction, true, radian)
145
123
  }
146
124
 
147
- distanceTo(point: Vector): number {
125
+ get b(): Fraction {
126
+ return this.#normal.y
127
+ }
128
+
129
+ get c(): Fraction {
130
+ return this.#normal.z
131
+ }
132
+
133
+ get d(): Fraction {
134
+ return this.#normal.dot(this.#point).opposite()
135
+ }
136
+
137
+ distanceTo(point: Point): number {
148
138
  return this.normal.dot(point).add(this.d).abs().value / this.normal.norm
149
139
  }
150
140
 
151
141
  intersectWithLine(line: Line3): Point {
152
- const { point, direction } = line
142
+ const {point, direction} = line
153
143
  const t = this.normal.dot(point).add(this.d).divide(this.normal.dot(direction).opposite())
154
- return point.clone().add(direction.clone().multiplyByScalar(t))
144
+ return new Point(
145
+ new Vector(point)
146
+ .add(direction.clone().multiplyByScalar(t))
147
+ )
155
148
  }
156
149
 
157
150
  intersectWithPlane(plane: Plane3): Line3 {
158
151
  const direction = this.normal.cross(plane.normal)
159
152
 
160
- // Solve the system:
153
+ // Solve the asSystem:
161
154
  // p1 // p2 // z=0
162
155
  const pt = new Point(0, 0, 0)
163
156
  throw new Error('Intersection with plane not yet implemented !')
@@ -167,4 +160,20 @@ export class Plane3 {
167
160
  isPointOnPlane(pt: Point): boolean {
168
161
  return this.normal.dot(pt).add(this.d).isZero()
169
162
  }
163
+
164
+ get normal(): Vector {
165
+ return this.#normal
166
+ }
167
+
168
+ set normal(value: Vector | Point) {
169
+ this.#normal = new Vector(value)
170
+ }
171
+
172
+ get point(): Point {
173
+ return this.#point
174
+ }
175
+
176
+ set point(value: Point | Vector) {
177
+ this.#point = new Point(value)
178
+ }
170
179
  }
@@ -1,32 +1,29 @@
1
1
  /**
2
- * Vector2D module contains everything necessary to handle 2d vectors.
2
+ * POint module contains everything necessary to handle 2d Points
3
+ * It's a "wrapper" of the Vector class.
3
4
  * @module Point
4
5
  */
5
6
 
6
7
  import {Fraction} from "../coefficients"
7
8
  import type {InputValue} from "../pimath.interface"
8
- import {Vector} from "./vector"
9
+ import {Root} from "../coefficients/root"
10
+ import {TupleN} from "./TupleN"
11
+ import type {Vector} from "./vector"
9
12
 
10
- export class Point extends Vector {
11
13
 
12
- constructor()
13
- constructor(value: Vector)
14
- constructor(start: Vector, end: Vector)
15
- constructor(...values: InputValue<Fraction>[])
16
- constructor(...values: Vector[] | InputValue<Fraction>[]) {
14
+ export class Point extends TupleN {
15
+ constructor(...values: (Point|Vector)[] | InputValue<Fraction>[]) {
17
16
  super()
18
17
 
19
- this.asPoint = true
20
-
21
18
  // Initialize the vector
22
19
  if (values.length > 0) {
23
20
  this.parse(...values)
24
21
  }
25
22
  };
26
23
 
27
- public override parse(...values: Vector[] | InputValue<Fraction>[]): this {
24
+ public parse(...values: (Point|Vector)[] | InputValue<Fraction>[]): this {
28
25
  if (values.length === 1) {
29
- if (values[0] instanceof Vector) {
26
+ if (values[0] instanceof TupleN) {
30
27
  this.array = values[0].copy()
31
28
  return this
32
29
  }
@@ -39,14 +36,14 @@ export class Point extends Vector {
39
36
 
40
37
 
41
38
  if (values.length > 1) {
42
- if (values.some(x => x instanceof Vector)) {
39
+ if (values.some(x => x instanceof Point)) {
43
40
  throw new Error('Creating a point with multiple argument requires an input fraction')
44
41
  }
45
42
 
46
43
  const nbs: Fraction[] = values.map(x => new Fraction(x as InputValue<Fraction>))
47
44
 
48
45
  if (nbs.some(x => x.isNaN())) {
49
- throw new Error('The value is not a valid point sting (a,b): ' + values.join(','))
46
+ throw new Error('The given values are not a valid point string (a,b): ')
50
47
  }
51
48
 
52
49
  this.array = nbs
@@ -55,12 +52,53 @@ export class Point extends Vector {
55
52
  return this
56
53
  }
57
54
 
55
+ public clone(): Point {
56
+ return new Point(...this.copy())
57
+ }
58
+
59
+ get tex(): string {
60
+ return `\\left(${this.array.map(x => x.tex).join(';')}\\right)`
61
+ }
62
+
63
+ get display(): string {
64
+ return `(${this.array.map(x => x.display).join(';')})`
65
+ }
66
+
67
+ distanceTo(B: Point): Root {
68
+ if (this.dimension !== B.dimension) {
69
+ throw new Error('The two points must have the same dimensions.')
70
+ }
71
+
72
+ const AB = this.array
73
+ .map((x, index) => B.array[index].clone().subtract(x))
74
+
75
+ const distance2 = AB
76
+ .reduce(
77
+ (acc, x) =>
78
+ acc.add(x.clone().pow(2)), new Fraction(0)
79
+ )
58
80
 
59
- public override clone(): Point {
60
- const V = new Point()
61
- V.array = this.copy()
62
- V.asPoint = true
63
- return V
81
+ return new Root().from(2, distance2).reduce()
64
82
  }
65
83
 
84
+ public isEqual(pt: Point): boolean {
85
+ return this.x.value===pt.x.value && this.y.value===pt.y.value
86
+ }
87
+
88
+ public isEqualXY(x: InputValue<Fraction>, y: InputValue<Fraction>): boolean {
89
+ return this.isEqual(new Point(x, y))
90
+ }
91
+
92
+ middleOf(V1: Point, V2: Point): this {
93
+ if (V1.dimension !== V2.dimension) {
94
+ throw new Error('Vectors must be the same dimension')
95
+ }
96
+
97
+ this.array = []
98
+ V1.array.forEach((x, index) => {
99
+ this.array.push(x.clone().add(V2.array[index]).divide(2))
100
+ })
101
+
102
+ return this
103
+ }
66
104
  }