@xort/cga 0.0.92 → 0.1.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/THIRD_PARTY_NOTICES.md +47 -0
- package/build/@xort_cga.js +14209 -14318
- package/build/cga.d.ts +2284 -1958
- package/build/cga.esm.js +14179 -0
- package/dist/THIRD_PARTY_NOTICES.md +47 -0
- package/dist/index.cjs +14320 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2358 -0
- package/dist/index.d.ts +2358 -38
- package/dist/index.js +14181 -56
- package/dist/index.js.map +1 -0
- package/package.json +59 -47
- package/readme.md +162 -247
- package/.github/FUNDING.yml +0 -12
- package/cga/1./347/202/271/344/270/216/347/272/277/346/200/247/345/205/203/347/264/240/347/232/204/350/267/235/347/246/273.html +0 -601
- package/cga/1./347/202/271/344/270/216/347/272/277/346/200/247/345/205/203/347/264/240/347/232/204/350/267/235/347/246/273.md +0 -111
- package/cga/2./347/202/271/344/270/216/351/235/242/346/200/247/345/205/203/347/264/240.md +0 -4
- package/cga/img//347/202/271/344/270/216/345/260/204/347/272/277.png +0 -0
- package/cga/img//347/202/271/344/270/216/347/233/264/347/272/277.png +0 -0
- package/cga/img//347/202/271/344/270/216/347/272/277/346/256/265.png +0 -0
- package/cga/img//347/233/264/347/272/277/347/232/204/350/241/250/350/276/276/345/274/217.png +0 -0
- package/deploy.sh +0 -39
- package/dist/IKanimation/Bone.d.ts +0 -7
- package/dist/IKanimation/Bone.js +0 -20
- package/dist/IKanimation/CCDSolver.d.ts +0 -37
- package/dist/IKanimation/CCDSolver.js +0 -93
- package/dist/IKanimation/Joint.d.ts +0 -3
- package/dist/IKanimation/Joint.js +0 -17
- package/dist/IKanimation/constaint/constraint.d.ts +0 -10
- package/dist/IKanimation/constaint/constraint.js +0 -25
- package/dist/IKanimation/constaint/hinge.d.ts +0 -12
- package/dist/IKanimation/constaint/hinge.js +0 -46
- package/dist/IKanimation/constaint/slider.d.ts +0 -12
- package/dist/IKanimation/constaint/slider.js +0 -44
- package/dist/IKanimation/index.d.ts +0 -0
- package/dist/IKanimation/index.js +0 -9
- package/dist/IKanimation/isolver.d.ts +0 -4
- package/dist/IKanimation/isolver.js +0 -10
- package/dist/IKanimation/skeleton.d.ts +0 -13
- package/dist/IKanimation/skeleton.js +0 -31
- package/dist/alg/common.d.ts +0 -114
- package/dist/alg/common.js +0 -302
- package/dist/alg/curve.d.ts +0 -4
- package/dist/alg/curve.js +0 -11
- package/dist/alg/delaunator.d.ts +0 -29
- package/dist/alg/delaunator.js +0 -442
- package/dist/alg/delaunay.d.ts +0 -20
- package/dist/alg/delaunay.js +0 -199
- package/dist/alg/delaunayslow.d.ts +0 -18
- package/dist/alg/delaunayslow.js +0 -140
- package/dist/alg/extrude/extrude.d.ts +0 -3
- package/dist/alg/extrude/extrude.js +0 -17
- package/dist/alg/extrude.d.ts +0 -199
- package/dist/alg/extrude.js +0 -728
- package/dist/alg/offset/index.d.ts +0 -0
- package/dist/alg/offset/index.js +0 -9
- package/dist/alg/offset.d.ts +0 -0
- package/dist/alg/offset.js +0 -472
- package/dist/alg/pointset.d.ts +0 -94
- package/dist/alg/pointset.js +0 -223
- package/dist/alg/recognition.d.ts +0 -14
- package/dist/alg/recognition.js +0 -37
- package/dist/alg/result.d.ts +0 -22
- package/dist/alg/result.js +0 -2
- package/dist/alg/segmentset.d.ts +0 -11
- package/dist/alg/segmentset.js +0 -45
- package/dist/alg/sort.d.ts +0 -2
- package/dist/alg/sort.js +0 -14
- package/dist/alg/split.d.ts +0 -8
- package/dist/alg/split.js +0 -10
- package/dist/alg/trianglution.d.ts +0 -15
- package/dist/alg/trianglution.js +0 -70
- package/dist/alg/vol.d.ts +0 -6
- package/dist/alg/vol.js +0 -18
- package/dist/alg/voronoi.d.ts +0 -31
- package/dist/alg/voronoi.js +0 -418
- package/dist/app.d.ts +0 -1
- package/dist/app.js +0 -248
- package/dist/basic/distance.d.ts +0 -12
- package/dist/basic/distance.js +0 -39
- package/dist/csg/bsp.d.ts +0 -9
- package/dist/csg/bsp.js +0 -22
- package/dist/csg/node.d.ts +0 -12
- package/dist/csg/node.js +0 -75
- package/dist/csg/polygon.d.ts +0 -43
- package/dist/csg/polygon.js +0 -161
- package/dist/diamondMaterialShader.d.ts +0 -92
- package/dist/diamondMaterialShader.js +0 -118
- package/dist/effect/breath-light.d.ts +0 -4
- package/dist/effect/breath-light.js +0 -39
- package/dist/extends/geometryaid.d.ts +0 -28
- package/dist/extends/geometryaid.js +0 -71
- package/dist/extends/split.d.ts +0 -3
- package/dist/extends/split.js +0 -13
- package/dist/glview.d.ts +0 -112
- package/dist/glview.js +0 -564
- package/dist/math/Color.d.ts +0 -33
- package/dist/math/Color.js +0 -235
- package/dist/math/Euler.d.ts +0 -46
- package/dist/math/Euler.js +0 -225
- package/dist/math/HVec3.d.ts +0 -43
- package/dist/math/HVec3.js +0 -176
- package/dist/math/Mat3.d.ts +0 -29
- package/dist/math/Mat3.js +0 -244
- package/dist/math/Mat4.d.ts +0 -85
- package/dist/math/Mat4.js +0 -791
- package/dist/math/Math.d.ts +0 -130
- package/dist/math/Math.js +0 -198
- package/dist/math/Quat.d.ts +0 -82
- package/dist/math/Quat.js +0 -418
- package/dist/math/Vec2.d.ts +0 -68
- package/dist/math/Vec2.js +0 -328
- package/dist/math/Vec3.d.ts +0 -240
- package/dist/math/Vec3.js +0 -1082
- package/dist/math/Vec4.d.ts +0 -81
- package/dist/math/Vec4.js +0 -475
- package/dist/math/vecs.d.ts +0 -134
- package/dist/math/vecs.js +0 -464
- package/dist/render/bufferAttribute.d.ts +0 -104
- package/dist/render/bufferAttribute.js +0 -344
- package/dist/render/geometry.d.ts +0 -87
- package/dist/render/geometry.js +0 -769
- package/dist/render/mesh.d.ts +0 -30
- package/dist/render/mesh.js +0 -87
- package/dist/render/types.d.ts +0 -3
- package/dist/render/types.js +0 -8
- package/dist/robust/plane.d.ts +0 -7
- package/dist/robust/plane.js +0 -17
- package/dist/robust/vec.d.ts +0 -15
- package/dist/robust/vec.js +0 -71
- package/dist/struct/3d/Box.d.ts +0 -23
- package/dist/struct/3d/Box.js +0 -109
- package/dist/struct/3d/Capsule.d.ts +0 -12
- package/dist/struct/3d/Capsule.js +0 -36
- package/dist/struct/3d/Circle.d.ts +0 -52
- package/dist/struct/3d/Circle.js +0 -138
- package/dist/struct/3d/Disk.d.ts +0 -10
- package/dist/struct/3d/Disk.js +0 -22
- package/dist/struct/3d/Frustum.d.ts +0 -35
- package/dist/struct/3d/Frustum.js +0 -159
- package/dist/struct/3d/Line.d.ts +0 -40
- package/dist/struct/3d/Line.js +0 -340
- package/dist/struct/3d/Path.d.ts +0 -75
- package/dist/struct/3d/Path.js +0 -308
- package/dist/struct/3d/Plane.d.ts +0 -74
- package/dist/struct/3d/Plane.js +0 -298
- package/dist/struct/3d/Point.d.ts +0 -4
- package/dist/struct/3d/Point.js +0 -30
- package/dist/struct/3d/Polygon.d.ts +0 -8
- package/dist/struct/3d/Polygon.js +0 -55
- package/dist/struct/3d/Polyline.d.ts +0 -34
- package/dist/struct/3d/Polyline.js +0 -130
- package/dist/struct/3d/Ray.d.ts +0 -21
- package/dist/struct/3d/Ray.js +0 -262
- package/dist/struct/3d/Rectangle.d.ts +0 -7
- package/dist/struct/3d/Rectangle.js +0 -35
- package/dist/struct/3d/Segment.d.ts +0 -32
- package/dist/struct/3d/Segment.js +0 -334
- package/dist/struct/3d/Shape.d.ts +0 -4
- package/dist/struct/3d/Shape.js +0 -27
- package/dist/struct/3d/Sphere.d.ts +0 -11
- package/dist/struct/3d/Sphere.js +0 -30
- package/dist/struct/3d/Triangle.d.ts +0 -8
- package/dist/struct/3d/Triangle.js +0 -53
- package/dist/struct/bsp.d.ts +0 -9
- package/dist/struct/bsp.js +0 -44
- package/dist/struct/btree.d.ts +0 -0
- package/dist/struct/btree.js +0 -1
- package/dist/struct/data/ArrayList.d.ts +0 -42
- package/dist/struct/data/ArrayList.js +0 -172
- package/dist/struct/data/ArrayObject.d.ts +0 -30
- package/dist/struct/data/ArrayObject.js +0 -131
- package/dist/struct/data/type.d.ts +0 -13
- package/dist/struct/data/type.js +0 -18
- package/dist/struct/kdtree.d.ts +0 -0
- package/dist/struct/kdtree.js +0 -1
- package/dist/struct/polyTree.d.ts +0 -4
- package/dist/struct/polyTree.js +0 -27
- package/dist/struct/quatTree.d.ts +0 -0
- package/dist/struct/quatTree.js +0 -1
- package/dist/struct/tree.d.ts +0 -11
- package/dist/struct/tree.js +0 -26
- package/dist/utils/array.d.ts +0 -24
- package/dist/utils/array.js +0 -89
- package/dist/utils/types.d.ts +0 -24
- package/dist/utils/types.js +0 -20
- package/docs/.vuepress/components/distance.vue +0 -125
- package/docs/.vuepress/components/intersect.vue +0 -0
- package/docs/.vuepress/components/trianglution.vue +0 -121
- package/docs/.vuepress/components/utils.js +0 -314
- package/docs/.vuepress/config.js +0 -99
- package/docs/.vuepress/enhanceApp.js +0 -13
- package/docs/.vuepress/public/delaunay.png +0 -0
- package/docs/.vuepress/public/logo.png +0 -0
- package/docs/.vuepress/public/plane-set-convex.png +0 -0
- package/docs/.vuepress/public/sponsor/alipay.jpg +0 -0
- package/docs/.vuepress/public/sponsor/wechat.png +0 -0
- package/docs/README.md +0 -14
- package/docs/demo/README.md +0 -9
- package/docs/guide/README.md +0 -94
- package/docs/guide/array.md +0 -10
- package/docs/guide/cy/trianglution.html +0 -2
- package/docs/guide/distLineAll.md +0 -85
- package/docs/guide/distPointAll.md +0 -137
- package/docs/guide/distRayAll.md +0 -69
- package/docs/guide/distSegmentAll.md +0 -19
- package/docs/guide/point.vue +0 -12
- package/docs/guide/vector.md +0 -10
- package/docs/guide//345/270/270/347/224/250.md +0 -156
- package/docs/sponsor/README.md +0 -15
- package/docs//345/274/200/345/217/221/346/227/245/345/277/227/2020/345/271/2643/346/234/21013/346/227/245.md +0 -6
- package/effect/common.glsl +0 -34
- package/effect/drawing.glsl +0 -36
- package/effect/shape.arc.glsl +0 -13
- package/effect/shape.circle.glsl +0 -13
- package/effect/shape.grid.glsl +0 -42
- package/effect/shape.line.glsl +0 -18
- package/effect/shape.pie.glsl +0 -18
- package/effect/shape.plot.glsl +0 -10
- package/effect/shape.poly.glsl +0 -15
- package/effect/shape.rect.glsl +0 -14
- package/effect/shape.rectround.glsl +0 -15
- package/effect/shape.segment.glsl +0 -10
- package/effect/shape.spiral.glsl +0 -12
- package/effect/shape.star.glsl +0 -16
- package/examples/index.html +0 -31
- package/git.sh +0 -12
- package/gitproxy.sh +0 -6
- package/image/readme/1640758500266.png +0 -0
- package/image/readme/1640758513361.png +0 -0
- package/index.html +0 -14
- package/linear algorithm//346/225/260/345/255/246/350/241/250/350/276/276/345/274/217.md" +0 -122
- package/linear algorithm//347/237/251/351/230/265.md" +0 -91
- package/rollup.config.js +0 -79
- package/scripttest.html +0 -23
- package/src/IKanimation/Bone.ts +0 -20
- package/src/IKanimation/CCDSolver.ts +0 -114
- package/src/IKanimation/Joint.ts +0 -13
- package/src/IKanimation/constaint/constraint.ts +0 -23
- package/src/IKanimation/constaint/hinge.ts +0 -29
- package/src/IKanimation/constaint/slider.ts +0 -25
- package/src/IKanimation/index.ts +0 -8
- package/src/IKanimation/isolver.ts +0 -13
- package/src/IKanimation/skeleton.ts +0 -30
- package/src/alg/common.ts +0 -304
- package/src/alg/curve.ts +0 -9
- package/src/alg/delaunator.ts +0 -519
- package/src/alg/delaunay.ts +0 -163
- package/src/alg/delaunayslow.ts +0 -183
- package/src/alg/extrude/extrude.ts +0 -19
- package/src/alg/extrude.ts +0 -941
- package/src/alg/offset/index.ts +0 -8
- package/src/alg/offset.ts +0 -501
- package/src/alg/pointset.ts +0 -219
- package/src/alg/recognition.ts +0 -43
- package/src/alg/result.ts +0 -24
- package/src/alg/segmentset.ts +0 -44
- package/src/alg/sort.ts +0 -11
- package/src/alg/split.ts +0 -15
- package/src/alg/trianglution.ts +0 -53
- package/src/alg/vol.ts +0 -18
- package/src/alg/voronoi.ts +0 -303
- package/src/app.css +0 -12
- package/src/app.ts +0 -285
- package/src/assets/color.jpg +0 -0
- package/src/basic/distance.ts +0 -40
- package/src/clipper/clipper.d.ts +0 -323
- package/src/clipper/clipper.js +0 -7626
- package/src/clipper/clipper_float.js +0 -185
- package/src/clipper/clipper_float_unminified.js +0 -5639
- package/src/clipper/clipperint.js +0 -7626
- package/src/csg/bsp.ts +0 -24
- package/src/csg/csg.js +0 -583
- package/src/csg/node.ts +0 -91
- package/src/csg/polygon.ts +0 -177
- package/src/diamondMaterialShader.ts +0 -93
- package/src/effect/breath-light.ts +0 -24
- package/src/extends/geometryaid.ts +0 -86
- package/src/extends/split.ts +0 -15
- package/src/glview.ts +0 -570
- package/src/index.ts +0 -47
- package/src/math/Color.ts +0 -225
- package/src/math/Euler.ts +0 -238
- package/src/math/HVec3.ts +0 -1144
- package/src/math/Mat3.ts +0 -365
- package/src/math/Mat4.ts +0 -1134
- package/src/math/Math.ts +0 -213
- package/src/math/Quat.ts +0 -536
- package/src/math/Vec2.ts +0 -408
- package/src/math/Vec3.ts +0 -1307
- package/src/math/Vec4.ts +0 -587
- package/src/math/vecs.ts +0 -486
- package/src/render/bufferAttribute.ts +0 -491
- package/src/render/geometry.ts +0 -1329
- package/src/render/mesh.ts +0 -82
- package/src/render/types.ts +0 -17
- package/src/robust/plane.ts +0 -12
- package/src/robust/readme.md +0 -1
- package/src/robust/vec.ts +0 -61
- package/src/shader/cga.glsl +0 -202
- package/src/shader/common.glsl +0 -87
- package/src/shader/noise/GLSL-Noise.md +0 -1108
- package/src/shader/noise/cellular2D.glsl +0 -69
- package/src/shader/noise/cellular2x2.glsl +0 -64
- package/src/shader/noise/cellular2x2x2.glsl +0 -88
- package/src/shader/noise/cellular3D.glsl +0 -187
- package/src/shader/noise/classicnoise2D.glsl +0 -113
- package/src/shader/noise/classicnoise3D.glsl +0 -177
- package/src/shader/noise/classicnoise4D.glsl +0 -302
- package/src/shader/noise/noise2D.glsl +0 -71
- package/src/shader/noise/noise3D.glsl +0 -103
- package/src/shader/noise/noise3Dgrad.glsl +0 -111
- package/src/shader/noise/noise4D.glsl +0 -129
- package/src/shader/noise/psrdnoise2D.glsl +0 -462
- package/src/struct/3d/Box.ts +0 -124
- package/src/struct/3d/Capsule.ts +0 -18
- package/src/struct/3d/Circle.ts +0 -149
- package/src/struct/3d/Disk.ts +0 -22
- package/src/struct/3d/Frustum.ts +0 -189
- package/src/struct/3d/Line.ts +0 -378
- package/src/struct/3d/Path.ts +0 -314
- package/src/struct/3d/Plane.ts +0 -341
- package/src/struct/3d/Point.ts +0 -7
- package/src/struct/3d/PolyLine.ts +0 -115
- package/src/struct/3d/Polygon.ts +0 -46
- package/src/struct/3d/Ray.ts +0 -285
- package/src/struct/3d/Rectangle.ts +0 -18
- package/src/struct/3d/Segment.ts +0 -330
- package/src/struct/3d/Shape.ts +0 -7
- package/src/struct/3d/Sphere.ts +0 -31
- package/src/struct/3d/Triangle.ts +0 -28
- package/src/struct/bsp.ts +0 -18
- package/src/struct/btree.ts +0 -0
- package/src/struct/data/ArrayList.ts +0 -144
- package/src/struct/data/ArrayObject.ts +0 -105
- package/src/struct/data/type.ts +0 -14
- package/src/struct/kdtree.ts +0 -0
- package/src/struct/polyTree.ts +0 -8
- package/src/struct/quatTree.ts +0 -0
- package/src/struct/tree.ts +0 -30
- package/src/utils/array.ts +0 -106
- package/src/utils/types.ts +0 -42
- package/src-gis/app.ts +0 -7
- package/src-gis/core/Cartographic.ts +0 -48
- package/src-gis/core/EllipsoidGeodesic.ts +0 -56
- package/src-gis/core/EllipsoidTerrainProvider.ts +0 -35
- package/src-gis/core/HeightmapTerrainData.ts +0 -5
- package/src-gis/core/Rectangle.ts +0 -112
- package/src-gis/core/TaskProcessor.ts +0 -222
- package/src-gis/gis.ts +0 -25
- package/src-gis/globe.ts +0 -54
- package/src-gis/math/Cartographic.ts +0 -24
- package/src-gis/math/GVec3.ts +0 -55
- package/src-gis/math/ellipsoid.ts +0 -13
- package/src-gis/provider/DcTerrainProvider.ts +0 -36
- package/src-gis/provider/TerrainProvider.ts +0 -12
- package/src-gis/scene/DcImageryProvider.ts +0 -36
- package/src-gis/scene/GeographicTilingScheme.ts +0 -65
- package/src-gis/scene/Globe.ts +0 -76
- package/src-gis/scene/GlobeSurfaceShaderSet.ts +0 -9
- package/src-gis/scene/GlobeSurfaceTileProvider.ts +0 -25
- package/src-gis/scene/ImageryLayerCollection.ts +0 -75
- package/src-gis/scene/ImageryProvider.ts +0 -28
- package/src-gis/scene/QuadtreeTile.ts +0 -162
- package/src-gis/scene/UrlTemplateImageryProvider.ts +0 -32
- package/src-gis/scene/quadtree_primitive.ts +0 -58
- package/tsconfig.json +0 -77
- package/webpack.config.js +0 -112
- package//350/256/241/347/256/227/345/207/240/344/275/225/351/227/256/351/242/230.md +0 -26
package/src/math/HVec3.ts
DELETED
|
@@ -1,1144 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Description : arbitrary-precision 任意精度的向量
|
|
3
|
-
* @Author : 赵耀圣
|
|
4
|
-
* @QQ : 549184003
|
|
5
|
-
* @Date : 2021-08-02 16:24:03
|
|
6
|
-
* @LastEditTime : 2021-08-03 11:32:10
|
|
7
|
-
* @FilePath : \cga.js\src\math\HVec3.ts
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import Decimal from 'decimal.js';
|
|
11
|
-
// import { wgs84RadiiSquared } from '../gis/gis';
|
|
12
|
-
export interface IHVec2 {
|
|
13
|
-
x: Decimal;
|
|
14
|
-
y: Decimal;
|
|
15
|
-
}
|
|
16
|
-
export interface IHVec3 extends IHVec2 {
|
|
17
|
-
z: Decimal;
|
|
18
|
-
}
|
|
19
|
-
export interface IHVec4 extends IHVec3 {
|
|
20
|
-
w: Decimal;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class HVec3 implements IHVec3 {
|
|
24
|
-
x: Decimal;
|
|
25
|
-
y: Decimal;
|
|
26
|
-
z: Decimal;
|
|
27
|
-
constructor(private _x: any = 0, private _y: any = 0, private _z: any = 0) {
|
|
28
|
-
this.x = new Decimal(_x);
|
|
29
|
-
this.y = new Decimal(_x);
|
|
30
|
-
this.z = new Decimal(_x);
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
static isVec3(v: any) {
|
|
36
|
-
return !isNaN(v.x) && !isNaN(v.y) && !isNaN(v.z) && isNaN(v.w);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
get isVec3() { return true; }
|
|
41
|
-
|
|
42
|
-
static get Up() {
|
|
43
|
-
return new HVec3(0, 1, 0);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static get Down() {
|
|
47
|
-
return new HVec3(0, 1, 0);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static get UnitX() {
|
|
51
|
-
return new HVec3(1, 0, 0);
|
|
52
|
-
}
|
|
53
|
-
static get UnitY() {
|
|
54
|
-
return new HVec3(0, 1, 0);
|
|
55
|
-
}
|
|
56
|
-
static get UnitZ() {
|
|
57
|
-
return new HVec3(0, 0, 1);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
set(x: Decimal, y: Decimal, z: Decimal) {
|
|
62
|
-
this.x = x;
|
|
63
|
-
this.y = y;
|
|
64
|
-
this.z = z;
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
setScalar(scalar: Decimal) {
|
|
69
|
-
this.x = scalar;
|
|
70
|
-
this.y = scalar;
|
|
71
|
-
this.z = scalar;
|
|
72
|
-
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
setComponent(index: number, value: Decimal) {
|
|
77
|
-
switch (index) {
|
|
78
|
-
case 0:
|
|
79
|
-
this.x = value;
|
|
80
|
-
break;
|
|
81
|
-
case 1:
|
|
82
|
-
this.y = value;
|
|
83
|
-
break;
|
|
84
|
-
case 2:
|
|
85
|
-
this.z = value;
|
|
86
|
-
break;
|
|
87
|
-
default:
|
|
88
|
-
throw new Error("index is out of range: " + index);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
add(v: HVec3, w?: HVec3) {
|
|
95
|
-
if (w !== undefined) {
|
|
96
|
-
console.warn(
|
|
97
|
-
"Vec3: .add() now only accepts one argument. Use .addVecs( a, b ) instead."
|
|
98
|
-
);
|
|
99
|
-
return this.addVecs(v, w);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
this.x.add(v.x);
|
|
103
|
-
this.y.add(v.y);
|
|
104
|
-
this.z.add(v.z);
|
|
105
|
-
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
addVecs(a: HVec3, b: HVec3) {
|
|
111
|
-
this.x = new Decimal(a.x).add(b.x);
|
|
112
|
-
this.y = new Decimal(a.y).add(b.y);
|
|
113
|
-
this.z = new Decimal(a.z).add(b.z);
|
|
114
|
-
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
sub(v: HVec3, w?: HVec3) {
|
|
120
|
-
if (w !== undefined) {
|
|
121
|
-
console.warn(
|
|
122
|
-
"Vec3: .sub() now only accepts one argument. Use .subVecs( a, b ) instead."
|
|
123
|
-
);
|
|
124
|
-
return this.subVecs(v, w);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
this.x.sub(v.x);
|
|
128
|
-
this.y.sub(v.y);
|
|
129
|
-
this.z.sub(v.z);
|
|
130
|
-
|
|
131
|
-
return this;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
subVecs(a: HVec3, b: HVec3) {
|
|
136
|
-
this.x = new Decimal(a.x).sub(b.x);
|
|
137
|
-
this.y = new Decimal(a.y).sub(b.y);
|
|
138
|
-
this.z = new Decimal(a.z).sub(b.z);
|
|
139
|
-
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
multiplyScalar(scalar: Decimal | number) {
|
|
145
|
-
scalar = new Decimal(scalar);
|
|
146
|
-
this.x.mul(scalar);
|
|
147
|
-
this.y.mul(scalar);
|
|
148
|
-
this.z.mul(scalar);
|
|
149
|
-
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
cross(v: HVec3, w?: HVec3) {
|
|
155
|
-
if (w !== undefined) {
|
|
156
|
-
console.warn(
|
|
157
|
-
"Vec3: .cross() now only accepts one argument. Use .crossVecs( a, b ) instead."
|
|
158
|
-
);
|
|
159
|
-
return this.crossVecs(v, w);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return this.crossVecs(this, v);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
crossVecs(a: HVec3, b: HVec3) {
|
|
166
|
-
var ax = a.x,
|
|
167
|
-
ay = a.y,
|
|
168
|
-
az = a.z;
|
|
169
|
-
var bx = b.x,
|
|
170
|
-
by = b.y,
|
|
171
|
-
bz = b.z;
|
|
172
|
-
|
|
173
|
-
this.x = ay.mul(bz).sub(az.mul(by));
|
|
174
|
-
this.y = az.mul(bx).sub(ax.mul(bz));
|
|
175
|
-
this.z = ax.mul(by).sub(ay.mul(bx));
|
|
176
|
-
|
|
177
|
-
return this;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
dot(v: HVec3) {
|
|
181
|
-
return this.x.mul(v.x).add(this.y.mul(v.y)).add(this.z.mul(v.z));
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
lerp(v: HVec3, alpha: number | Decimal) {
|
|
185
|
-
this.x.add(v.x.sub(this.x).mul(alpha));
|
|
186
|
-
this.y.add(v.y.sub(this.y).mul(alpha));
|
|
187
|
-
this.z.add(v.z.sub(this.z).mul(alpha));
|
|
188
|
-
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
clone(): HVec3 {
|
|
194
|
-
return new HVec3(this.x, this.y, this.z);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
length() {
|
|
198
|
-
return this.x.mul(this.x).add(this.y.mul(this.y)).add(this.z.mul(this.z)).sqrt();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
normalize() {
|
|
202
|
-
return this.divideScalar(this.length() || new Decimal(1));
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
divideScalar(scalar: number | Decimal) {
|
|
207
|
-
return this.multiplyScalar(new Decimal(1).mul(new Decimal(scalar)));
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
// getComponent(index: number) {
|
|
212
|
-
// switch (index) {
|
|
213
|
-
// case 0:
|
|
214
|
-
// return this.x;
|
|
215
|
-
// case 1:
|
|
216
|
-
// return this.y;
|
|
217
|
-
// case 2:
|
|
218
|
-
// return this.z;
|
|
219
|
-
// default:
|
|
220
|
-
// throw new Error("index is out of range: " + index);
|
|
221
|
-
// }
|
|
222
|
-
// }
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
// copy(v: Vec3) {
|
|
226
|
-
// this.x = v.x;
|
|
227
|
-
// this.y = v.y;
|
|
228
|
-
// this.z = v.z;
|
|
229
|
-
|
|
230
|
-
// return this;
|
|
231
|
-
// }
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
// addScalar(s: number) {
|
|
236
|
-
// this.x.add(s);
|
|
237
|
-
// this.y.add(s);
|
|
238
|
-
// this.z.add(s);
|
|
239
|
-
|
|
240
|
-
// return this;
|
|
241
|
-
// }
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
// addScaledVec(v: Vec3, s: number) {
|
|
245
|
-
// this.x.add(v.x.mul(s));
|
|
246
|
-
// this.y.add(v.y.mul(s));
|
|
247
|
-
// this.z.add(v.z.mul(s));
|
|
248
|
-
|
|
249
|
-
// return this;
|
|
250
|
-
// }
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
// multiply(v: Vec3, w?: Vec3) {
|
|
254
|
-
// if (w !== undefined) {
|
|
255
|
-
// return this.multiplyVecs(v, w);
|
|
256
|
-
// }
|
|
257
|
-
|
|
258
|
-
// this.x *= v.x;
|
|
259
|
-
// this.y *= v.y;
|
|
260
|
-
// this.z *= v.z;
|
|
261
|
-
|
|
262
|
-
// return this;
|
|
263
|
-
// }
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
// multiplyVecs(a: Vec3, b: Vec3) {
|
|
267
|
-
// this.x = a.x * b.x;
|
|
268
|
-
// this.y = a.y * b.y;
|
|
269
|
-
// this.z = a.z * b.z;
|
|
270
|
-
|
|
271
|
-
// return this;
|
|
272
|
-
// }
|
|
273
|
-
|
|
274
|
-
// applyEuler(euler: Euler) {
|
|
275
|
-
// if (!(euler && euler.isEuler)) {
|
|
276
|
-
// console.error(
|
|
277
|
-
// "Vec3: .applyEuler() now expects an Euler rotation rather than a Vec3 and order."
|
|
278
|
-
// );
|
|
279
|
-
// }
|
|
280
|
-
|
|
281
|
-
// return this.applyQuat(_quat.setFromEuler(euler));
|
|
282
|
-
// }
|
|
283
|
-
|
|
284
|
-
// applyAxisAngle(axis: any, angle: any) {
|
|
285
|
-
// return this.applyQuat(_quat.setFromAxisAngle(axis, angle));
|
|
286
|
-
// }
|
|
287
|
-
|
|
288
|
-
// applyNormalMat(m: Mat3) {
|
|
289
|
-
// return this.applyMat3(m).normalize();
|
|
290
|
-
// }
|
|
291
|
-
|
|
292
|
-
// applyMat3(m: Mat3) {
|
|
293
|
-
// var x = this.x,
|
|
294
|
-
// y = this.y,
|
|
295
|
-
// z = this.z;
|
|
296
|
-
// var e = m.elements;
|
|
297
|
-
|
|
298
|
-
// this.x = e[0] * x + e[3] * y + e[6] * z;
|
|
299
|
-
// this.y = e[1] * x + e[4] * y + e[7] * z;
|
|
300
|
-
// this.z = e[2] * x + e[5] * y + e[8] * z;
|
|
301
|
-
|
|
302
|
-
// return this;
|
|
303
|
-
// }
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
// applyQuat(q: { x: any; y: any; z: any; w: any; }) {
|
|
307
|
-
// var x = this.x,
|
|
308
|
-
// y = this.y,
|
|
309
|
-
// z = this.z;
|
|
310
|
-
// var qx = q.x,
|
|
311
|
-
// qy = q.y,
|
|
312
|
-
// qz = q.z,
|
|
313
|
-
// qw = q.w;
|
|
314
|
-
|
|
315
|
-
// // calculate Quat * Vec
|
|
316
|
-
|
|
317
|
-
// var ix = qw * x + qy * z - qz * y;
|
|
318
|
-
// var iy = qw * y + qz * x - qx * z;
|
|
319
|
-
// var iz = qw * z + qx * y - qy * x;
|
|
320
|
-
// var iw = -qx * x - qy * y - qz * z;
|
|
321
|
-
|
|
322
|
-
// // calculate result * inverse Quat
|
|
323
|
-
|
|
324
|
-
// this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
|
325
|
-
// this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
|
326
|
-
// this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
|
327
|
-
|
|
328
|
-
// return this;
|
|
329
|
-
// }
|
|
330
|
-
|
|
331
|
-
// project(camera: { matrixWorldInverse: any; projectionMat: any; }) {
|
|
332
|
-
// return this.applyMat4(camera.matrixWorldInverse).applyMat4(
|
|
333
|
-
// camera.projectionMat
|
|
334
|
-
// );
|
|
335
|
-
// }
|
|
336
|
-
|
|
337
|
-
// unproject(camera: { projectionMatInverse: any; matrixWorld: any; }) {
|
|
338
|
-
// return this.applyMat4(camera.projectionMatInverse).applyMat4(
|
|
339
|
-
// camera.matrixWorld
|
|
340
|
-
// );
|
|
341
|
-
// }
|
|
342
|
-
|
|
343
|
-
// transformDirection(m: Mat4) {
|
|
344
|
-
// // input: Mat4 affine matrix
|
|
345
|
-
// // Vec interpreted as a direction
|
|
346
|
-
|
|
347
|
-
// var x = this.x,
|
|
348
|
-
// y = this.y,
|
|
349
|
-
// z = this.z;
|
|
350
|
-
// var e = m.elements;
|
|
351
|
-
|
|
352
|
-
// this.x = e[0] * x + e[4] * y + e[8] * z;
|
|
353
|
-
// this.y = e[1] * x + e[5] * y + e[9] * z;
|
|
354
|
-
// this.z = e[2] * x + e[6] * y + e[10] * z;
|
|
355
|
-
|
|
356
|
-
// return this.normalize();
|
|
357
|
-
// }
|
|
358
|
-
|
|
359
|
-
// divide(v: Vec3) {
|
|
360
|
-
// this.x /= v.x;
|
|
361
|
-
// this.y /= v.y;
|
|
362
|
-
// this.z /= v.z;
|
|
363
|
-
|
|
364
|
-
// return this;
|
|
365
|
-
// }
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
// min(v: Vec3) {
|
|
369
|
-
// this.x = Math.min(this.x, v.x);
|
|
370
|
-
// this.y = Math.min(this.y, v.y);
|
|
371
|
-
// this.z = Math.min(this.z, v.z);
|
|
372
|
-
|
|
373
|
-
// return this;
|
|
374
|
-
// }
|
|
375
|
-
|
|
376
|
-
// max(v: Vec3) {
|
|
377
|
-
// this.x = Math.max(this.x, v.x);
|
|
378
|
-
// this.y = Math.max(this.y, v.y);
|
|
379
|
-
// this.z = Math.max(this.z, v.z);
|
|
380
|
-
|
|
381
|
-
// return this;
|
|
382
|
-
// }
|
|
383
|
-
|
|
384
|
-
// clamp(min: Vec3, max: Vec3) {
|
|
385
|
-
// // assumes min < max, componentwise
|
|
386
|
-
|
|
387
|
-
// this.x = Math.max(min.x, Math.min(max.x, this.x));
|
|
388
|
-
// this.y = Math.max(min.y, Math.min(max.y, this.y));
|
|
389
|
-
// this.z = Math.max(min.z, Math.min(max.z, this.z));
|
|
390
|
-
|
|
391
|
-
// return this;
|
|
392
|
-
// }
|
|
393
|
-
|
|
394
|
-
// clampScalar(minVal: number, maxVal: number) {
|
|
395
|
-
// this.x = Math.max(minVal, Math.min(maxVal, this.x));
|
|
396
|
-
// this.y = Math.max(minVal, Math.min(maxVal, this.y));
|
|
397
|
-
// this.z = Math.max(minVal, Math.min(maxVal, this.z));
|
|
398
|
-
|
|
399
|
-
// return this;
|
|
400
|
-
// }
|
|
401
|
-
|
|
402
|
-
// clampLength(min: number, max: number) {
|
|
403
|
-
// var length = this.length();
|
|
404
|
-
|
|
405
|
-
// return this.divideScalar(length || 1).multiplyScalar(
|
|
406
|
-
// Math.max(min, Math.min(max, length))
|
|
407
|
-
// );
|
|
408
|
-
// }
|
|
409
|
-
|
|
410
|
-
// floor() {
|
|
411
|
-
// this.x = Math.floor(this.x);
|
|
412
|
-
// this.y = Math.floor(this.y);
|
|
413
|
-
// this.z = Math.floor(this.z);
|
|
414
|
-
|
|
415
|
-
// return this;
|
|
416
|
-
// }
|
|
417
|
-
|
|
418
|
-
// ceil() {
|
|
419
|
-
// this.x = Math.ceil(this.x);
|
|
420
|
-
// this.y = Math.ceil(this.y);
|
|
421
|
-
// this.z = Math.ceil(this.z);
|
|
422
|
-
|
|
423
|
-
// return this;
|
|
424
|
-
// }
|
|
425
|
-
|
|
426
|
-
// round() {
|
|
427
|
-
// this.x = Math.round(this.x);
|
|
428
|
-
// this.y = Math.round(this.y);
|
|
429
|
-
// this.z = Math.round(this.z);
|
|
430
|
-
|
|
431
|
-
// return this;
|
|
432
|
-
// }
|
|
433
|
-
|
|
434
|
-
// roundToZero() {
|
|
435
|
-
// this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
|
|
436
|
-
// this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
|
|
437
|
-
// this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
|
|
438
|
-
|
|
439
|
-
// return this;
|
|
440
|
-
// }
|
|
441
|
-
|
|
442
|
-
// negate() {
|
|
443
|
-
// this.x = -this.x;
|
|
444
|
-
// this.y = -this.y;
|
|
445
|
-
// this.z = -this.z;
|
|
446
|
-
|
|
447
|
-
// return this;
|
|
448
|
-
// }
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
// // TODO lengthSquared?
|
|
452
|
-
|
|
453
|
-
// lengthSq() {
|
|
454
|
-
// return this.x * this.x + this.y * this.y + this.z * this.z;
|
|
455
|
-
// }
|
|
456
|
-
|
|
457
|
-
// length() {
|
|
458
|
-
// return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
459
|
-
// }
|
|
460
|
-
|
|
461
|
-
// manhattanLength() {
|
|
462
|
-
// return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
|
|
463
|
-
// }
|
|
464
|
-
// setLength(length: any) {
|
|
465
|
-
// return this.normalize().multiplyScalar(length);
|
|
466
|
-
// }
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
// lerpVecs(v1: Vec3, v2: any, alpha: any) {
|
|
470
|
-
// return this.subVecs(v2, v1)
|
|
471
|
-
// .multiplyScalar(alpha)
|
|
472
|
-
// .add(v1);
|
|
473
|
-
// }
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
// projectOnVec(vec: Vec3) {
|
|
477
|
-
// var scalar = vec.dot(this) / vec.lengthSq();
|
|
478
|
-
|
|
479
|
-
// return this.copy(vec).multiplyScalar(scalar);
|
|
480
|
-
// }
|
|
481
|
-
|
|
482
|
-
// projectOnPlaneNormal(planeNormal: any) {
|
|
483
|
-
// _vec.copy(this).projectOnVec(planeNormal);
|
|
484
|
-
|
|
485
|
-
// return this.sub(_vec);
|
|
486
|
-
// }
|
|
487
|
-
|
|
488
|
-
// /**
|
|
489
|
-
// * 投影到平面
|
|
490
|
-
// * @param plane
|
|
491
|
-
// */
|
|
492
|
-
// projectOnPlane(plane: Plane) {
|
|
493
|
-
// var scalar = plane.normal.dot(this) - plane.w;
|
|
494
|
-
|
|
495
|
-
// _vec.copy(plane.normal).multiplyScalar(scalar);
|
|
496
|
-
|
|
497
|
-
// return this.sub(_vec);
|
|
498
|
-
// }
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
// /**
|
|
502
|
-
// * 从指定方向线(斜线,也可能是法线)上投影到平面
|
|
503
|
-
// * @param planeNormal
|
|
504
|
-
// * @param dir
|
|
505
|
-
// */
|
|
506
|
-
// projectDirectionOnPlane(plane: Plane, dir: Vec3) {
|
|
507
|
-
// var scalar = plane.normal.dot(this) - plane.w;
|
|
508
|
-
|
|
509
|
-
// _vec.copy(plane.normal).multiplyScalar(scalar);
|
|
510
|
-
|
|
511
|
-
// _vec.negate().add(this);
|
|
512
|
-
// var len = this.distanceTo(_vec);
|
|
513
|
-
|
|
514
|
-
// var nlen = len / plane.normal.dot(dir)
|
|
515
|
-
|
|
516
|
-
// this.add(_vec.copy(dir).negate().multiplyScalar(nlen));
|
|
517
|
-
|
|
518
|
-
// return this;
|
|
519
|
-
// }
|
|
520
|
-
|
|
521
|
-
// reflect(normal: any) {
|
|
522
|
-
// // reflect incident Vec off plane orthogonal to normal
|
|
523
|
-
// // normal is assumed to have unit length
|
|
524
|
-
|
|
525
|
-
// return this.sub(_vec.copy(normal).multiplyScalar(2 * this.dot(normal)));
|
|
526
|
-
// }
|
|
527
|
-
|
|
528
|
-
// angleTo(v: Vec3, normal?: Vec3 | any) {
|
|
529
|
-
// if (normal)
|
|
530
|
-
// return this.angleToEx(v, normal)
|
|
531
|
-
|
|
532
|
-
// var theta = this.dot(v) / Math.sqrt(this.lengthSq() * v.lengthSq());
|
|
533
|
-
// return Math.acos(clamp(theta, -1, 1));
|
|
534
|
-
// }
|
|
535
|
-
|
|
536
|
-
// angleToEx(v: Vec3, normal: Vec3) {
|
|
537
|
-
// var theta = this.dot(v) / Math.sqrt(this.lengthSq() * v.lengthSq());
|
|
538
|
-
|
|
539
|
-
// if (this.clone().cross(v).dot(normal) > 0)
|
|
540
|
-
// return Math.acos(clamp(theta, -1, 1));
|
|
541
|
-
// else
|
|
542
|
-
// return Math.PI * 2 - Math.acos(clamp(theta, -1, 1));
|
|
543
|
-
// }
|
|
544
|
-
|
|
545
|
-
// distanceTo(v: any) {
|
|
546
|
-
// return Math.sqrt(this.distanceToSquared(v));
|
|
547
|
-
// }
|
|
548
|
-
|
|
549
|
-
// distanceToSquared(v: Vec3) {
|
|
550
|
-
// var dx = this.x - v.x,
|
|
551
|
-
// dy = this.y - v.y,
|
|
552
|
-
// dz = this.z - v.z;
|
|
553
|
-
|
|
554
|
-
// return dx * dx + dy * dy + dz * dz;
|
|
555
|
-
// }
|
|
556
|
-
|
|
557
|
-
// manhattanDistanceTo(v: Vec3) {
|
|
558
|
-
// return (
|
|
559
|
-
// Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z)
|
|
560
|
-
// );
|
|
561
|
-
// }
|
|
562
|
-
|
|
563
|
-
// setFromSpherical(s: { radius: number; phi: number; theta: number; }) {
|
|
564
|
-
// return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
|
|
565
|
-
// }
|
|
566
|
-
|
|
567
|
-
// setFromSphericalCoords(radius: number, phi: number, theta: number) {
|
|
568
|
-
// var sinPhiRadius = Math.sin(phi) * radius;
|
|
569
|
-
|
|
570
|
-
// this.x = sinPhiRadius * Math.sin(theta);
|
|
571
|
-
// this.y = Math.cos(phi) * radius;
|
|
572
|
-
// this.z = sinPhiRadius * Math.cos(theta);
|
|
573
|
-
|
|
574
|
-
// return this;
|
|
575
|
-
// }
|
|
576
|
-
|
|
577
|
-
// setFromCylindrical(c: { radius: any; theta: any; y: any; }) {
|
|
578
|
-
// return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
|
|
579
|
-
// }
|
|
580
|
-
|
|
581
|
-
// setFromCylindricalCoords(radius: number, theta: number, y: number) {
|
|
582
|
-
// this.x = radius * Math.sin(theta);
|
|
583
|
-
// this.y = y;
|
|
584
|
-
// this.z = radius * Math.cos(theta);
|
|
585
|
-
|
|
586
|
-
// return this;
|
|
587
|
-
// }
|
|
588
|
-
|
|
589
|
-
// setFromMatPosition(m: { elements: any; }) {
|
|
590
|
-
// var e = m.elements;
|
|
591
|
-
|
|
592
|
-
// this.x = e[12];
|
|
593
|
-
// this.y = e[13];
|
|
594
|
-
// this.z = e[14];
|
|
595
|
-
|
|
596
|
-
// return this;
|
|
597
|
-
// }
|
|
598
|
-
|
|
599
|
-
// setFromMatScale(m: any) {
|
|
600
|
-
// var sx = this.setFromMatColumn(m, 0).length();
|
|
601
|
-
// var sy = this.setFromMatColumn(m, 1).length();
|
|
602
|
-
// var sz = this.setFromMatColumn(m, 2).length();
|
|
603
|
-
|
|
604
|
-
// this.x = sx;
|
|
605
|
-
// this.y = sy;
|
|
606
|
-
// this.z = sz;
|
|
607
|
-
|
|
608
|
-
// return this;
|
|
609
|
-
// }
|
|
610
|
-
|
|
611
|
-
// setFromMatColumn(m: { elements: any; }, index: number) {
|
|
612
|
-
// return this.fromArray(m.elements, index * 4);
|
|
613
|
-
// }
|
|
614
|
-
|
|
615
|
-
// equals(v: Vec3) {
|
|
616
|
-
// return v.x === this.x && v.y === this.y && v.z === this.z;
|
|
617
|
-
// }
|
|
618
|
-
|
|
619
|
-
// fromArray(array: ArrayLike<number>, offset?: number) {
|
|
620
|
-
// if (offset === undefined) offset = 0;
|
|
621
|
-
|
|
622
|
-
// this.x = array[offset];
|
|
623
|
-
// this.y = array[offset + 1];
|
|
624
|
-
// this.z = array[offset + 2];
|
|
625
|
-
|
|
626
|
-
// return this;
|
|
627
|
-
// }
|
|
628
|
-
|
|
629
|
-
// toArray(array: number[] = [], offset: number = 0) {
|
|
630
|
-
|
|
631
|
-
// array[offset] = this.x;
|
|
632
|
-
// array[offset + 1] = this.y;
|
|
633
|
-
// array[offset + 2] = this.z;
|
|
634
|
-
|
|
635
|
-
// return array;
|
|
636
|
-
// }
|
|
637
|
-
|
|
638
|
-
// fromBufferAttribute(attribute: { getX: (arg0: any) => number; getY: (arg0: any) => number; getZ: (arg0: any) => number; }, index: any, offset?: number) {
|
|
639
|
-
// if (offset !== undefined) {
|
|
640
|
-
// console.warn(
|
|
641
|
-
// "Vec3: offset has been removed from .fromBufferAttribute()."
|
|
642
|
-
// );
|
|
643
|
-
// }
|
|
644
|
-
|
|
645
|
-
// this.x = attribute.getX(index);
|
|
646
|
-
// this.y = attribute.getY(index);
|
|
647
|
-
// this.z = attribute.getZ(index);
|
|
648
|
-
|
|
649
|
-
// return this;
|
|
650
|
-
// }
|
|
651
|
-
|
|
652
|
-
// toFixed(fractionDigits: number | undefined) {
|
|
653
|
-
// if (fractionDigits !== undefined) {
|
|
654
|
-
// this.x = parseFloat(this.x.toFixed(fractionDigits))
|
|
655
|
-
// this.y = parseFloat(this.y.toFixed(fractionDigits))
|
|
656
|
-
// this.z = parseFloat(this.z.toFixed(fractionDigits))
|
|
657
|
-
// }
|
|
658
|
-
// return this;
|
|
659
|
-
// }
|
|
660
|
-
|
|
661
|
-
// //---Distance-------------------------------------------------------------------------------
|
|
662
|
-
// distancePoint(point: Vec3): DistanceResult {
|
|
663
|
-
// const result: DistanceResult = {};
|
|
664
|
-
// result.distanceSqr = this.distanceToSquared(point);
|
|
665
|
-
// result.distance = Math.sqrt(result.distanceSqr);
|
|
666
|
-
// return result;
|
|
667
|
-
// }
|
|
668
|
-
|
|
669
|
-
// distanceVec3(point: Vec3): DistanceResult {
|
|
670
|
-
// return this.distancePoint(point);
|
|
671
|
-
// }
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
// /**
|
|
675
|
-
// * 点到直线的距离 point distance to Line
|
|
676
|
-
// * @param line
|
|
677
|
-
// */
|
|
678
|
-
// distanceLine(line: Line): DistanceResult {
|
|
679
|
-
// const result: DistanceResult = { parameters: [], closests: [] };
|
|
680
|
-
// var diff = this.clone().sub(line.origin);
|
|
681
|
-
// var lineParameter = line.direction.dot(diff);
|
|
682
|
-
// var lineClosest = line.direction
|
|
683
|
-
// .clone()
|
|
684
|
-
// .multiplyScalar(lineParameter)
|
|
685
|
-
// .add(line.origin);
|
|
686
|
-
|
|
687
|
-
// result.parameters!.push(0, lineParameter);
|
|
688
|
-
// result.closests!.push(this, lineClosest);
|
|
689
|
-
|
|
690
|
-
// diff = result.closests![0].clone().sub(result.closests![1]);
|
|
691
|
-
// result.distanceSqr = diff.dot(diff);
|
|
692
|
-
// result.distance = Math.sqrt(result.distanceSqr);
|
|
693
|
-
// return result;
|
|
694
|
-
// }
|
|
695
|
-
|
|
696
|
-
// /**
|
|
697
|
-
// * Test success
|
|
698
|
-
// * 到射线的距离
|
|
699
|
-
// * @param {Line} line
|
|
700
|
-
// * @returns {Object} lineParameter 最近点的参数 lineClosest 最近点 distanceSqr 到最近点距离的平方 distance 到最近点距离
|
|
701
|
-
// */
|
|
702
|
-
// distanceRay(ray: Ray) {
|
|
703
|
-
// var result: DistanceResult = {
|
|
704
|
-
// parameters: [0],
|
|
705
|
-
// closests: [this]
|
|
706
|
-
// };
|
|
707
|
-
// var diff = this.clone().sub(ray.origin);
|
|
708
|
-
// result.parameters![1] = ray.direction.dot(diff);
|
|
709
|
-
|
|
710
|
-
// if (result.parameters![1] > 0) {
|
|
711
|
-
// result.closests![1] = ray.direction
|
|
712
|
-
// .clone()
|
|
713
|
-
// .multiplyScalar(result.parameters![1])
|
|
714
|
-
// .add(ray.origin);
|
|
715
|
-
// } else {
|
|
716
|
-
// result.closests![1] = ray.origin.clone();
|
|
717
|
-
// }
|
|
718
|
-
// diff = this.clone().sub(result.closests![1]);
|
|
719
|
-
// result.distanceSqr = diff.dot(diff);
|
|
720
|
-
// result.distance = Math.sqrt(result.distanceSqr);
|
|
721
|
-
|
|
722
|
-
// return result;
|
|
723
|
-
// }
|
|
724
|
-
|
|
725
|
-
// /**
|
|
726
|
-
// * Test success
|
|
727
|
-
// * 到线段的距离
|
|
728
|
-
// * @param {Line} line
|
|
729
|
-
// * @returns {Object} lineParameter 最近点的参数 lineClosest 最近点 distanceSqr 到最近点距离的平方 distance 到最近点距离
|
|
730
|
-
// */
|
|
731
|
-
// distanceSegment(segment: Segment) {
|
|
732
|
-
// const result: DistanceResult = {
|
|
733
|
-
// parameters: [],
|
|
734
|
-
// closests: []
|
|
735
|
-
// };
|
|
736
|
-
|
|
737
|
-
// var diff = this.clone().sub(segment.p1);
|
|
738
|
-
// var t = segment.extentDirection.dot(diff);
|
|
739
|
-
|
|
740
|
-
// if (t >= 0) {
|
|
741
|
-
// result.parameters![1] = 1;
|
|
742
|
-
// result.closests![1] = segment.p1;
|
|
743
|
-
// } else {
|
|
744
|
-
// diff = this.clone().sub(segment.p0);
|
|
745
|
-
// t = segment.extentDirection.dot(diff);
|
|
746
|
-
// if (t <= 0) {
|
|
747
|
-
// result.parameters![1] = 0;
|
|
748
|
-
// result.closests![1] = segment.p0;
|
|
749
|
-
// }
|
|
750
|
-
// else {
|
|
751
|
-
// var sqrLength = segment.extentSqr;
|
|
752
|
-
// if (sqrLength <= 0)
|
|
753
|
-
// sqrLength = 0;
|
|
754
|
-
|
|
755
|
-
// t /= sqrLength;
|
|
756
|
-
// result.parameters![1] = t;
|
|
757
|
-
// result.closests![1] = segment.extentDirection
|
|
758
|
-
// .clone()
|
|
759
|
-
// .multiplyScalar(t)
|
|
760
|
-
// .add(segment.p0);
|
|
761
|
-
// }
|
|
762
|
-
// }
|
|
763
|
-
|
|
764
|
-
// result.closests![0] = this;
|
|
765
|
-
// diff = this.clone().sub(result.closests![1]);
|
|
766
|
-
// result.distanceSqr = diff.dot(diff);
|
|
767
|
-
// result.distance = Math.sqrt(result.distanceSqr);
|
|
768
|
-
|
|
769
|
-
// return result;
|
|
770
|
-
// }
|
|
771
|
-
|
|
772
|
-
// /**
|
|
773
|
-
// * 点与线段的距离
|
|
774
|
-
// * @param plane
|
|
775
|
-
// */
|
|
776
|
-
// distancePlane(plane: Plane) {
|
|
777
|
-
// // this.clone().sub(plane.origin).dot(plane.normal);
|
|
778
|
-
// const result: DistanceResult = {
|
|
779
|
-
// parameters: [],
|
|
780
|
-
// closests: [],
|
|
781
|
-
// signedDistance: 0,
|
|
782
|
-
// distance: 0
|
|
783
|
-
// };
|
|
784
|
-
// result.signedDistance = this.clone().dot(plane.normal) - plane.w;
|
|
785
|
-
// result.distance = Math.abs(result.signedDistance);
|
|
786
|
-
// result.closests![1] = this.clone().sub(plane.normal.clone().multiplyScalar(result.signedDistance));
|
|
787
|
-
// return result;
|
|
788
|
-
// }
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
// /**
|
|
792
|
-
// * 点与圆圈的距离
|
|
793
|
-
// * @param {*} circle
|
|
794
|
-
// * @param {*} disk
|
|
795
|
-
// * @returns {} result
|
|
796
|
-
// */
|
|
797
|
-
// distanceCircle(circle: Circle) {
|
|
798
|
-
// var result: DistanceResult = {
|
|
799
|
-
// parameters: [],
|
|
800
|
-
// closests: [],
|
|
801
|
-
// equidistant: false//是否等距
|
|
802
|
-
// };
|
|
803
|
-
|
|
804
|
-
// // Projection of P-C onto plane is Q-C = P-C - Dot(N,P-C)*N.
|
|
805
|
-
|
|
806
|
-
// var PmC = this.clone().sub(circle.center);
|
|
807
|
-
// var QmC = PmC.clone().sub(circle.normal.clone().multiplyScalar(circle.normal.dot(PmC)));
|
|
808
|
-
// var lengthQmC = QmC.length();
|
|
809
|
-
// if (lengthQmC > gPrecision) {
|
|
810
|
-
// result.circleClosest = QmC.clone().multiplyScalar(circle.radius / lengthQmC).add(circle.center);
|
|
811
|
-
// result.equidistant = false;
|
|
812
|
-
// }
|
|
813
|
-
// else {
|
|
814
|
-
// var offsetPoint = circle.center.clone().add(v3(10, 10, 10));
|
|
815
|
-
// var CP = offsetPoint.sub(circle.center);
|
|
816
|
-
// var CQ = CP.clone().sub(circle.normal.clone().multiplyScalar(circle.normal.dot(CP))).normalize()
|
|
817
|
-
// //在圆圈圆心的法线上,到圆圈上的没一点都相同
|
|
818
|
-
// result.circleClosest = CQ.clone().multiplyScalar(circle.radius).add(circle.center)
|
|
819
|
-
// result.equidistant = true;
|
|
820
|
-
// }
|
|
821
|
-
// result.closests!.push(this, result.circleClosest);
|
|
822
|
-
// var diff = this.clone().sub(result.circleClosest);
|
|
823
|
-
// result.distanceSqr = diff.dot(diff);
|
|
824
|
-
// result.distance = Math.sqrt(result.distanceSqr);
|
|
825
|
-
|
|
826
|
-
// return result;
|
|
827
|
-
// }
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
// /**
|
|
831
|
-
// * 点与圆盘的距离
|
|
832
|
-
// * @param {*} Disk
|
|
833
|
-
// * @returns {} result
|
|
834
|
-
// */
|
|
835
|
-
// distanceDisk(disk: Disk): DistanceResult {
|
|
836
|
-
// var result: DistanceResult = {
|
|
837
|
-
// parameters: [],
|
|
838
|
-
// closests: [],
|
|
839
|
-
// signedDistance: 1,
|
|
840
|
-
// distanceSqr: 0,
|
|
841
|
-
// distance: 0,
|
|
842
|
-
// };
|
|
843
|
-
|
|
844
|
-
// var PmC = this.clone().sub(disk.center);
|
|
845
|
-
// var QmC = PmC.clone().sub(disk.normal.clone().multiplyScalar(disk.normal.dot(PmC)));
|
|
846
|
-
// var lengthQmC = QmC.length();
|
|
847
|
-
|
|
848
|
-
// result.signedDistance = this.clone().dot(disk.normal) - disk.w;
|
|
849
|
-
|
|
850
|
-
// if (lengthQmC > disk.radius) {
|
|
851
|
-
// result.diskClosest = QmC.clone().multiplyScalar(disk.radius / lengthQmC).add(disk.center);
|
|
852
|
-
// }
|
|
853
|
-
// else {
|
|
854
|
-
// var signedDistance = this.clone().dot(disk.normal) - disk.w;
|
|
855
|
-
// result.diskClosest = this.clone().sub(disk.normal.clone().multiplyScalar(signedDistance));
|
|
856
|
-
// }
|
|
857
|
-
// result.closests!.push(this, result.diskClosest);
|
|
858
|
-
// var diff = this.clone().sub(result.diskClosest);
|
|
859
|
-
// result.distanceSqr = diff.dot(diff);
|
|
860
|
-
// result.distance = Math.sqrt(result.distanceSqr);
|
|
861
|
-
// return result;
|
|
862
|
-
// }
|
|
863
|
-
// /**
|
|
864
|
-
// * 点与线段的距离
|
|
865
|
-
// * 点与折线的距离 测试排除法,平均比线性检索(暴力法)要快两倍以上
|
|
866
|
-
// * @param { Polyline | Vec3[]} polyline
|
|
867
|
-
// */
|
|
868
|
-
// distancePolyline(polyline: Polyline | Vec3[]) {
|
|
869
|
-
// let u = +Infinity;
|
|
870
|
-
// let ipos: number = -1;
|
|
871
|
-
// let tempResult: DistanceResult;
|
|
872
|
-
// let result = null;
|
|
873
|
-
// for (let i = 0; i < polyline.length - 1; i++) {
|
|
874
|
-
// const pti = polyline[i];
|
|
875
|
-
// const ptj = polyline[i + 1];
|
|
876
|
-
// if (Math.abs(pti.x - this.x) > u && Math.abs(ptj.x - this.x) > u && (pti.x - this.x) * (ptj.x - this.x) > 0)
|
|
877
|
-
// continue;
|
|
878
|
-
// if (Math.abs(pti.y - this.y) > u && Math.abs(ptj.y - this.y) > u && (pti.y - this.y) * (ptj.y - this.y) > 0)
|
|
879
|
-
// continue;
|
|
880
|
-
// if (Math.abs(pti.z - this.z) > u && Math.abs(ptj.z - this.z) > u && (pti.z - this.z) * (ptj.z - this.z) > 0)
|
|
881
|
-
// continue;
|
|
882
|
-
// tempResult = this.distanceSegment(new Segment(pti, ptj));
|
|
883
|
-
// if (tempResult.distance! < u) {
|
|
884
|
-
// u = tempResult.distance!;
|
|
885
|
-
// result = tempResult;
|
|
886
|
-
// ipos = i;
|
|
887
|
-
// }
|
|
888
|
-
// }
|
|
889
|
-
|
|
890
|
-
// result!.segmentIndex = ipos;
|
|
891
|
-
// return result;
|
|
892
|
-
// }
|
|
893
|
-
|
|
894
|
-
// /**
|
|
895
|
-
// * 点到三角形的距离
|
|
896
|
-
// * @param {Triangle} triangle
|
|
897
|
-
// */
|
|
898
|
-
// distanceTriangle(triangle: Triangle): DistanceResult {
|
|
899
|
-
|
|
900
|
-
// function GetMinEdge02(a11: any, b1: any, p: any) {
|
|
901
|
-
// p[0] = 0;
|
|
902
|
-
// if (b1 >= 0) {
|
|
903
|
-
// p[1] = 0;
|
|
904
|
-
// }
|
|
905
|
-
// else if (a11 + b1 <= 0) {
|
|
906
|
-
// p[1] = 1;
|
|
907
|
-
// }
|
|
908
|
-
// else {
|
|
909
|
-
// p[1] = -b1 / a11;
|
|
910
|
-
// }
|
|
911
|
-
// }
|
|
912
|
-
|
|
913
|
-
// function GetMinEdge12(a01: number, a11: number, b1: number, f10: number, f01: number, p: any) {
|
|
914
|
-
// var h0 = a01 + b1 - f10;
|
|
915
|
-
// if (h0 >= 0) {
|
|
916
|
-
// p[1] = 0;
|
|
917
|
-
// }
|
|
918
|
-
// else {
|
|
919
|
-
// var h1 = a11 + b1 - f01;
|
|
920
|
-
// if (h1 <= 0) {
|
|
921
|
-
// p[1] = 1;
|
|
922
|
-
// }
|
|
923
|
-
// else {
|
|
924
|
-
// p[1] = h0 / (h0 - h1);
|
|
925
|
-
// }
|
|
926
|
-
// }
|
|
927
|
-
// p[0] = 1 - p[1];
|
|
928
|
-
// }
|
|
929
|
-
|
|
930
|
-
// function GetMinInterior(p0: any, h0: number, p1: any, h1: number, p: any) {
|
|
931
|
-
// var z = h0 / (h0 - h1);
|
|
932
|
-
// p[0] = (1 - z) * p0[0] + z * p1[0];
|
|
933
|
-
// p[1] = (1 - z) * p0[1] + z * p1[1];
|
|
934
|
-
// }
|
|
935
|
-
|
|
936
|
-
// var diff = this.clone().sub(triangle.p0);
|
|
937
|
-
// var edge0 = triangle.p1.clone().sub(triangle.p0);
|
|
938
|
-
// var edge1 = triangle.p2.clone().sub(triangle.p0);
|
|
939
|
-
// var a00 = edge0.dot(edge0);
|
|
940
|
-
// var a01 = edge0.dot(edge1);
|
|
941
|
-
// var a11 = edge1.dot(edge1);
|
|
942
|
-
// var b0 = -diff.dot(edge0);
|
|
943
|
-
// var b1 = -diff.dot(edge1);
|
|
944
|
-
|
|
945
|
-
// var f00 = b0;
|
|
946
|
-
// var f10 = b0 + a00;
|
|
947
|
-
// var f01 = b0 + a01;
|
|
948
|
-
|
|
949
|
-
// var p0 = [0, 0], p1 = [0, 0], p = [0, 0];
|
|
950
|
-
// var dt1, h0, h1;
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
// if (f00 >= 0) {
|
|
954
|
-
// if (f01 >= 0) {
|
|
955
|
-
// // (1) p0 = (0,0), p1 = (0,1), H(z) = G(L(z))
|
|
956
|
-
// GetMinEdge02(a11, b1, p);
|
|
957
|
-
// }
|
|
958
|
-
// else {
|
|
959
|
-
// // (2) p0 = (0,t10), p1 = (t01,1-t01),
|
|
960
|
-
// // H(z) = (t11 - t10)*G(L(z))
|
|
961
|
-
// p0[0] = 0;
|
|
962
|
-
// p0[1] = f00 / (f00 - f01);
|
|
963
|
-
// p1[0] = f01 / (f01 - f10);
|
|
964
|
-
// p1[1] = 1 - p1[0];
|
|
965
|
-
// dt1 = p1[1] - p0[1];
|
|
966
|
-
// h0 = dt1 * (a11 * p0[1] + b1);
|
|
967
|
-
// if (h0 >= 0) {
|
|
968
|
-
// GetMinEdge02(a11, b1, p);
|
|
969
|
-
// }
|
|
970
|
-
// else {
|
|
971
|
-
// h1 = dt1 * (a01 * p1[0] + a11 * p1[1] + b1);
|
|
972
|
-
// if (h1 <= 0) {
|
|
973
|
-
// GetMinEdge12(a01, a11, b1, f10, f01, p);
|
|
974
|
-
// }
|
|
975
|
-
// else {
|
|
976
|
-
// GetMinInterior(p0, h0, p1, h1, p);
|
|
977
|
-
// }
|
|
978
|
-
// }
|
|
979
|
-
// }
|
|
980
|
-
// }
|
|
981
|
-
// else if (f01 <= 0) {
|
|
982
|
-
// if (f10 <= 0) {
|
|
983
|
-
// // (3) p0 = (1,0), p1 = (0,1),
|
|
984
|
-
// // H(z) = G(L(z)) - F(L(z))
|
|
985
|
-
// GetMinEdge12(a01, a11, b1, f10, f01, p);
|
|
986
|
-
// }
|
|
987
|
-
// else {
|
|
988
|
-
// // (4) p0 = (t00,0), p1 = (t01,1-t01), H(z) = t11*G(L(z))
|
|
989
|
-
// p0[0] = f00 / (f00 - f10);
|
|
990
|
-
// p0[1] = 0;
|
|
991
|
-
// p1[0] = f01 / (f01 - f10);
|
|
992
|
-
// p1[1] = 1 - p1[0];
|
|
993
|
-
// h0 = p1[1] * (a01 * p0[0] + b1);
|
|
994
|
-
// if (h0 >= 0) {
|
|
995
|
-
// p = p0; // GetMinEdge01
|
|
996
|
-
// }
|
|
997
|
-
// else {
|
|
998
|
-
// h1 = p1[1] * (a01 * p1[0] + a11 * p1[1] + b1);
|
|
999
|
-
// if (h1 <= 0) {
|
|
1000
|
-
// GetMinEdge12(a01, a11, b1, f10, f01, p);
|
|
1001
|
-
// }
|
|
1002
|
-
// else {
|
|
1003
|
-
// GetMinInterior(p0, h0, p1, h1, p);
|
|
1004
|
-
// }
|
|
1005
|
-
// }
|
|
1006
|
-
// }
|
|
1007
|
-
// }
|
|
1008
|
-
// else if (f10 <= 0) {
|
|
1009
|
-
// // (5) p0 = (0,t10), p1 = (t01,1-t01),
|
|
1010
|
-
// // H(z) = (t11 - t10)*G(L(z))
|
|
1011
|
-
// p0[0] = 0;
|
|
1012
|
-
// p0[1] = f00 / (f00 - f01);
|
|
1013
|
-
// p1[0] = f01 / (f01 - f10);
|
|
1014
|
-
// p1[1] = 1 - p1[0];
|
|
1015
|
-
// dt1 = p1[1] - p0[1];
|
|
1016
|
-
// h0 = dt1 * (a11 * p0[1] + b1);
|
|
1017
|
-
// if (h0 >= 0) {
|
|
1018
|
-
// GetMinEdge02(a11, b1, p);
|
|
1019
|
-
// }
|
|
1020
|
-
// else {
|
|
1021
|
-
// h1 = dt1 * (a01 * p1[0] + a11 * p1[1] + b1);
|
|
1022
|
-
// if (h1 <= 0) {
|
|
1023
|
-
// GetMinEdge12(a01, a11, b1, f10, f01, p);
|
|
1024
|
-
// }
|
|
1025
|
-
// else {
|
|
1026
|
-
// GetMinInterior(p0, h0, p1, h1, p);
|
|
1027
|
-
// }
|
|
1028
|
-
// }
|
|
1029
|
-
// }
|
|
1030
|
-
// else {
|
|
1031
|
-
// // (6) p0 = (t00,0), p1 = (0,t11), H(z) = t11*G(L(z))
|
|
1032
|
-
// p0[0] = f00 / (f00 - f10);
|
|
1033
|
-
// p0[1] = 0;
|
|
1034
|
-
// p1[0] = 0;
|
|
1035
|
-
// p1[1] = f00 / (f00 - f01);
|
|
1036
|
-
// h0 = p1[1] * (a01 * p0[0] + b1);
|
|
1037
|
-
// if (h0 >= 0) {
|
|
1038
|
-
// p = p0; // GetMinEdge01
|
|
1039
|
-
// }
|
|
1040
|
-
// else {
|
|
1041
|
-
// h1 = p1[1] * (a11 * p1[1] + b1);
|
|
1042
|
-
// if (h1 <= 0) {
|
|
1043
|
-
// GetMinEdge02(a11, b1, p);
|
|
1044
|
-
// }
|
|
1045
|
-
// else {
|
|
1046
|
-
// GetMinInterior(p0, h0, p1, h1, p);
|
|
1047
|
-
// }
|
|
1048
|
-
// }
|
|
1049
|
-
// }
|
|
1050
|
-
|
|
1051
|
-
// var result: DistanceResult = {
|
|
1052
|
-
// closests: [],
|
|
1053
|
-
// parameters: [],
|
|
1054
|
-
// triangleParameters: []
|
|
1055
|
-
// };
|
|
1056
|
-
// result.triangleParameters![0] = 1 - p[0] - p[1];
|
|
1057
|
-
// result.triangleParameters![1] = p[0];
|
|
1058
|
-
// result.triangleParameters![2] = p[1];
|
|
1059
|
-
// var closest = triangle.p0.clone().add(edge0.multiplyScalar(p[0])).add(edge1.multiplyScalar(p[1]));
|
|
1060
|
-
// result.parameters!.push(0, result.triangleParameters);
|
|
1061
|
-
// result.closests!.push(this, closest);
|
|
1062
|
-
// diff = this.clone().sub(closest);
|
|
1063
|
-
// result.distanceSqr = diff.dot(diff);
|
|
1064
|
-
// result.distance = Math.sqrt(result.distanceSqr);
|
|
1065
|
-
// return result;
|
|
1066
|
-
// }
|
|
1067
|
-
|
|
1068
|
-
// /**
|
|
1069
|
-
// * 点到矩形的距离
|
|
1070
|
-
// * @param {Rectangle} rectangle
|
|
1071
|
-
// */
|
|
1072
|
-
// distanceRectangle(rectangle: Rectangle): DistanceResult {
|
|
1073
|
-
// var result: DistanceResult = {
|
|
1074
|
-
// rectangleParameters: [],
|
|
1075
|
-
// parameters: [],
|
|
1076
|
-
// closests: [],
|
|
1077
|
-
// };
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
// var diff = rectangle.center.clone().sub(this);
|
|
1081
|
-
// var b0 = diff.dot(rectangle.axis[0]);
|
|
1082
|
-
// var b1 = diff.dot(rectangle.axis[1]);
|
|
1083
|
-
// var s0 = -b0, s1 = -b1;
|
|
1084
|
-
// result.distanceSqr = diff.dot(diff);
|
|
1085
|
-
|
|
1086
|
-
// if (s0 < -rectangle.extent[0]) {
|
|
1087
|
-
// s0 = -rectangle.extent[0];
|
|
1088
|
-
// }
|
|
1089
|
-
// else if (s0 > rectangle.extent[0]) {
|
|
1090
|
-
// s0 = rectangle.extent[0];
|
|
1091
|
-
// }
|
|
1092
|
-
// result.distanceSqr += s0 * (s0 + 2 * b0);
|
|
1093
|
-
|
|
1094
|
-
// if (s1 < -rectangle.extent[1]) {
|
|
1095
|
-
// s1 = -rectangle.extent[1];
|
|
1096
|
-
// }
|
|
1097
|
-
// else if (s1 > rectangle.extent[1]) {
|
|
1098
|
-
// s1 = rectangle.extent[1];
|
|
1099
|
-
// }
|
|
1100
|
-
// result.distanceSqr += s1 * (s1 + 2 * b1);
|
|
1101
|
-
|
|
1102
|
-
// // Account for numerical round-off error.
|
|
1103
|
-
// if (result.distanceSqr < 0) {
|
|
1104
|
-
// result.distanceSqr = 0;
|
|
1105
|
-
// }
|
|
1106
|
-
|
|
1107
|
-
// result.distance = Math.sqrt(result.distanceSqr);
|
|
1108
|
-
// result.rectangleParameters![0] = s0;
|
|
1109
|
-
// result.rectangleParameters![1] = s1;
|
|
1110
|
-
// var rectangleClosestPoint = rectangle.center.clone();
|
|
1111
|
-
// for (var i = 0; i < 2; ++i) {
|
|
1112
|
-
// rectangleClosestPoint.add(rectangle.axis[i].multiplyScalar(result.rectangleParameters![i]));
|
|
1113
|
-
// }
|
|
1114
|
-
// result.closests![0] = this;
|
|
1115
|
-
// result.closests![1] = rectangleClosestPoint;
|
|
1116
|
-
// return result;
|
|
1117
|
-
// }
|
|
1118
|
-
|
|
1119
|
-
// /**
|
|
1120
|
-
// * 点到胶囊的距离
|
|
1121
|
-
// * @param {Capsule} capsule
|
|
1122
|
-
// */
|
|
1123
|
-
// distanceCapsule(capsule: Capsule): DistanceResult {
|
|
1124
|
-
// var result = this.distanceSegment(capsule);
|
|
1125
|
-
// result.distance = result.distance! - capsule.radius;
|
|
1126
|
-
// var closest = this.clone().sub(result.closests![1]).normalize().multiplyScalar(capsule.radius);
|
|
1127
|
-
// result.interior = result.distance < 0;
|
|
1128
|
-
|
|
1129
|
-
// result.closests = [this, closest];
|
|
1130
|
-
// return result;
|
|
1131
|
-
// }
|
|
1132
|
-
|
|
1133
|
-
// //---Intersection-------------------------------------------------------------------------------
|
|
1134
|
-
// }
|
|
1135
|
-
|
|
1136
|
-
// const _vec = v3();
|
|
1137
|
-
// const _quat: Quat = quat();
|
|
1138
|
-
// const scratchN = new Vec3();
|
|
1139
|
-
// const scratchK = new Vec3();
|
|
1140
|
-
|
|
1141
|
-
// export function v3(x?: number, y?: number, z?: number) {
|
|
1142
|
-
// return new Vec3(x, y, z);
|
|
1143
|
-
}
|
|
1144
|
-
|