@eturnity/eturnity_maths 6.37.0 → 6.38.0
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/package.json +1 -1
- package/src/geometry.js +8 -0
- package/src/matrix.js +1 -1
- package/src/objects/Circle.js +15 -3
- package/src/objects/Line.js +3 -2
- package/src/objects/Polygon.js +1 -0
package/package.json
CHANGED
package/src/geometry.js
CHANGED
|
@@ -104,6 +104,14 @@ export function getDistanceBetweenPoints(firstPoint, secondPoint) {
|
|
|
104
104
|
)
|
|
105
105
|
return distance
|
|
106
106
|
}
|
|
107
|
+
export function get3DDistanceBetweenPoints(firstPoint, secondPoint) {
|
|
108
|
+
const distance = Math.hypot(
|
|
109
|
+
firstPoint.x - secondPoint.x,
|
|
110
|
+
firstPoint.y - secondPoint.y,
|
|
111
|
+
firstPoint.z - secondPoint.z
|
|
112
|
+
)
|
|
113
|
+
return distance
|
|
114
|
+
}
|
|
107
115
|
|
|
108
116
|
export function getDegree(H, I, J) {
|
|
109
117
|
const a = getDistanceBetweenPoints(H, I)
|
package/src/matrix.js
CHANGED
|
@@ -52,7 +52,7 @@ export function inverse3x3matrix(m) {
|
|
|
52
52
|
}
|
|
53
53
|
return product
|
|
54
54
|
}
|
|
55
|
-
export function rotateTransformation(point,angle,center){
|
|
55
|
+
export function rotateTransformation(point,angle,center = {x:0,y:0}){
|
|
56
56
|
let rotationMatrix=[[Math.cos(angle),Math.sin(angle)],[-Math.sin(angle),Math.cos(angle)]]
|
|
57
57
|
let k=multiplyMatrices(rotationMatrix,[[point.x-center.x],[point.y-center.y]])
|
|
58
58
|
return {x:k[0][0]+center.x,y:k[1][0]+center.y}
|
package/src/objects/Circle.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import {
|
|
3
3
|
getDistanceBetweenPoints,
|
|
4
4
|
translate2D,
|
|
5
|
+
verticalProjectionOnPlane,
|
|
6
|
+
get3DDistanceBetweenPoints
|
|
5
7
|
} from '../geometry'
|
|
6
8
|
import { v4 as uuidv4 } from 'uuid'
|
|
7
9
|
import {Point} from './Point'
|
|
@@ -32,11 +34,21 @@ export class Circle {
|
|
|
32
34
|
const toCanvasRef = canvasContext.toCanvasRef
|
|
33
35
|
let pxCenter = toCanvasRef(this.center)
|
|
34
36
|
let pxRadius = this.radius / canvasContext.mmPerPx
|
|
35
|
-
|
|
37
|
+
if(this.normalVector){
|
|
38
|
+
point.z=verticalProjectionOnPlane(point,this.normalVector,this.center).z
|
|
39
|
+
}else{
|
|
40
|
+
point.z=this.center.z
|
|
41
|
+
}
|
|
42
|
+
return Math.abs(get3DDistanceBetweenPoints(point, pxCenter) - pxRadius)
|
|
36
43
|
}
|
|
37
44
|
getProjectedPoint(point) {
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
if(this.normalVector){
|
|
46
|
+
point.z=verticalProjectionOnPlane(point,this.normalVector,this.center).z
|
|
47
|
+
}else{
|
|
48
|
+
point.z=this.center.z
|
|
49
|
+
}
|
|
50
|
+
let distance = get3DDistanceBetweenPoints(point, this.center)
|
|
51
|
+
if (distance == 0) {
|
|
40
52
|
console.error("can't project center to cercle", this)
|
|
41
53
|
return null
|
|
42
54
|
}
|
package/src/objects/Line.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import {
|
|
3
3
|
getDistanceBetweenPoints,
|
|
4
|
+
get3DDistanceBetweenPoints,
|
|
4
5
|
getPointOnLine,
|
|
5
6
|
isSamePoint3D,
|
|
6
7
|
translate2D,
|
|
@@ -40,8 +41,8 @@ export class Line {
|
|
|
40
41
|
canvasContext.mmPerPx
|
|
41
42
|
)
|
|
42
43
|
}
|
|
43
|
-
mmLength(
|
|
44
|
-
return
|
|
44
|
+
mmLength() {
|
|
45
|
+
return get3DDistanceBetweenPoints(this.outline[0], this.outline[1])
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
getMidPoint() {
|