@motionscript/math 0.1.0-alpha.7 → 0.1.0-alpha.9
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/CHANGELOG.md +4 -0
- package/LICENSE +201 -201
- package/NOTICE +49 -48
- package/README.md +390 -391
- package/dist/annotate/angle-mark.d.ts +6 -6
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +9 -9
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +9 -9
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/{chunk-ABYBW64J.js → chunk-IRZCG6PM.js} +2 -2
- package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
- package/dist/browser/chunks/{chunk-K77KLQX4.js → chunk-WMVW6ZIV.js} +2 -2
- package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
- package/dist/browser/chunks/{mathjax-DNP3YRES.js → mathjax-WV55AC2P.js} +1 -1
- package/dist/browser/chunks/{mathjax-DNP3YRES.js.map → mathjax-WV55AC2P.js.map} +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/tex.js +1 -1
- package/dist/browser/tex.js.map +1 -1
- package/dist/engine.d.ts +1 -1
- package/dist/engine.js +1 -1
- package/dist/engine.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kit/brace.js.map +1 -1
- package/dist/kit/cache.js.map +1 -1
- package/dist/kit/component.d.ts.map +1 -1
- package/dist/kit/component.js.map +1 -1
- package/dist/kit/contour.js.map +1 -1
- package/dist/kit/coords.js.map +1 -1
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/equation.js.map +1 -1
- package/dist/kit/equation3d.js.map +1 -1
- package/dist/kit/expression.js.map +1 -1
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/field.js.map +1 -1
- package/dist/kit/follow.d.ts +2 -2
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.js.map +1 -1
- package/dist/kit/geometry.js.map +1 -1
- package/dist/kit/graph.js.map +1 -1
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/part-fills.js.map +1 -1
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/sampler.js +1 -1
- package/dist/kit/sampler.js.map +1 -1
- package/dist/kit/scale.js.map +1 -1
- package/dist/kit/source.js.map +1 -1
- package/dist/kit/system.js.map +1 -1
- package/dist/kit/ticks.js.map +1 -1
- package/dist/kit/withdrawn.js.map +1 -1
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +6 -6
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +3 -3
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +3 -3
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +6 -6
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +6 -6
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +8 -8
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/graph-layout.js.map +1 -1
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/geometry.js.map +1 -1
- package/dist/tex/index.js.map +1 -1
- package/dist/tex/mathjax.js.map +1 -1
- package/dist/tex/matrix.d.ts +2 -2
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/node.d.ts +2 -2
- package/dist/tex/node.js.map +1 -1
- package/dist/tex/tween.js.map +1 -1
- package/dist/tex/typeset.d.ts +4 -4
- package/dist/tex/typeset.d.ts.map +1 -1
- package/dist/tex/typeset.js.map +1 -1
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +27 -27
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js +3 -2
- package/dist/three/curve-plot3d.js.map +1 -1
- package/dist/three/entries.js.map +1 -1
- package/dist/three/label3d.d.ts.map +1 -1
- package/dist/three/label3d.js +3 -1
- package/dist/three/label3d.js.map +1 -1
- package/dist/three/plot-point3d.d.ts +27 -27
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +36 -36
- package/dist/three/surface-plot3d.js +6 -1
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +27 -27
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +5 -4
- package/registry.json +251 -251
- package/src/annotate/angle-mark.ts +137 -137
- package/src/annotate/curly-brace.ts +148 -148
- package/src/annotate/emphasis-mark.ts +118 -118
- package/src/engine.ts +86 -86
- package/src/index.ts +29 -29
- package/src/kit/brace.ts +37 -37
- package/src/kit/cache.ts +61 -61
- package/src/kit/component.ts +57 -57
- package/src/kit/contour.ts +94 -94
- package/src/kit/coords.ts +278 -278
- package/src/kit/curve.ts +47 -47
- package/src/kit/equation.ts +181 -181
- package/src/kit/equation3d.ts +137 -137
- package/src/kit/expression.ts +159 -159
- package/src/kit/field-mark.ts +171 -171
- package/src/kit/field.ts +50 -50
- package/src/kit/follow.ts +229 -229
- package/src/kit/furniture.ts +113 -113
- package/src/kit/geometry.ts +49 -49
- package/src/kit/graph.ts +116 -116
- package/src/kit/mark.ts +152 -152
- package/src/kit/part-fills.ts +61 -61
- package/src/kit/place.ts +77 -77
- package/src/kit/sampler.ts +281 -281
- package/src/kit/scale.ts +39 -39
- package/src/kit/source.ts +57 -57
- package/src/kit/system.ts +105 -105
- package/src/kit/ticks.ts +85 -85
- package/src/kit/withdrawn.ts +8 -8
- package/src/marks/curve-area.ts +89 -89
- package/src/marks/drop-lines.ts +71 -71
- package/src/marks/plot-point.ts +102 -102
- package/src/marks/riemann-sum.ts +99 -99
- package/src/marks/tangent-line.ts +119 -119
- package/src/marks/vector-arrow.ts +98 -98
- package/src/nodes.ts +99 -99
- package/src/plots/function-plot.ts +220 -220
- package/src/plots/points-plot.ts +103 -103
- package/src/plots/stream-lines.ts +160 -160
- package/src/plots/traced-path.ts +70 -70
- package/src/plots/vector-field.ts +107 -107
- package/src/structures/graph-layout.ts +145 -145
- package/src/structures/network-graph.ts +291 -291
- package/src/structures/sample-space.ts +210 -210
- package/src/systems/axes2d.ts +226 -226
- package/src/systems/number-line.ts +130 -130
- package/src/systems/number-plane.ts +232 -232
- package/src/systems/polar-plane.ts +177 -177
- package/src/tex/geometry.ts +703 -703
- package/src/tex/index.ts +15 -15
- package/src/tex/mathjax.ts +82 -82
- package/src/tex/matrix.ts +97 -97
- package/src/tex/node.ts +74 -74
- package/src/tex/tween.ts +308 -308
- package/src/tex/typeset.ts +461 -461
- package/src/three/axes3d.ts +267 -267
- package/src/three/curve-plot3d.ts +146 -144
- package/src/three/entries.ts +42 -42
- package/src/three/label3d.ts +52 -50
- package/src/three/plot-point3d.ts +63 -63
- package/src/three/space.ts +92 -92
- package/src/three/surface-plot3d.ts +318 -312
- package/src/three/vector-arrow3d.ts +88 -88
- package/dist/browser/chunks/chunk-ABYBW64J.js.map +0 -7
- package/dist/browser/chunks/chunk-K77KLQX4.js.map +0 -7
- package/dist/kit/placement.d.ts +0 -8
- package/dist/kit/placement.d.ts.map +0 -1
- package/dist/kit/placement.js +0 -8
- package/dist/kit/placement.js.map +0 -1
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import {
|
|
2
|
-
component3d,
|
|
3
|
-
Graphics3D,
|
|
4
|
-
lerpVector3,
|
|
5
|
-
Material,
|
|
6
|
-
resolveVector3,
|
|
7
|
-
Types,
|
|
8
|
-
type Mesh3DProps,
|
|
9
|
-
type NodeOf,
|
|
10
|
-
type Values,
|
|
11
|
-
type Vector3,
|
|
12
|
-
type Vector3Input,
|
|
13
|
-
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
14
|
-
type Blend3D as _Blend3D,
|
|
15
|
-
type Color as _Color,
|
|
16
|
-
type Faces3D as _Faces3D,
|
|
17
|
-
type Fill3D as _Fill3D,
|
|
18
|
-
type Geometry3D as _Geometry3D,
|
|
19
|
-
type Material3D as _Material3D,
|
|
20
|
-
type Node3D as _Node3D,
|
|
21
|
-
type Node3DProps as _Node3DProps,
|
|
22
|
-
type NormalizedColor as _NormalizedColor,
|
|
23
|
-
type Shading3D as _Shading3D,
|
|
24
|
-
type Texture3D as _Texture3D,
|
|
25
|
-
} from "@motionscript/sdk";
|
|
26
|
-
import { meshEntries } from "./entries";
|
|
27
|
-
import { aim, graphEntry, graphOf } from "./space";
|
|
28
|
-
|
|
29
|
-
export interface VectorArrow3dProps extends Mesh3DProps {
|
|
30
|
-
tail?: Vector3Input;
|
|
31
|
-
head?: Vector3Input;
|
|
32
|
-
thickness?: number;
|
|
33
|
-
tip?: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function point(initial: Vector3) {
|
|
37
|
-
return Types.custom<Vector3Input, Vector3>(initial, { resolve: resolveVector3, lerp: lerpVector3, kind: "vector3" });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const state = {
|
|
41
|
-
...meshEntries,
|
|
42
|
-
tail: point({ x: 0, y: 0, z: 0 }),
|
|
43
|
-
head: point({ x: 1, y: 1, z: 1 }),
|
|
44
|
-
/** The radius of the shaft, in scene units; the tip is sized from it. */
|
|
45
|
-
thickness: Types.number(0.035, { min: 0.001, step: 0.005 }),
|
|
46
|
-
tip: Types.boolean(true, { animatable: false }),
|
|
47
|
-
graph: graphEntry(),
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/** An arrow between two points of a 3D graph: a vector from the origin by default. */
|
|
51
|
-
export const VectorArrow3d = component3d({
|
|
52
|
-
key: "vectorArrow3d",
|
|
53
|
-
state,
|
|
54
|
-
commands: {
|
|
55
|
-
/** Animate either end, or both. */
|
|
56
|
-
endpointsTo: { args: ["tail", "head"] },
|
|
57
|
-
},
|
|
58
|
-
render: (ctx, s) => ctx.draw(drawArrow(s)),
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
export type VectorArrow3d = NodeOf<typeof VectorArrow3d>;
|
|
62
|
-
|
|
63
|
-
function drawArrow(s: Values<typeof state>): Graphics3D {
|
|
64
|
-
const g3 = new Graphics3D();
|
|
65
|
-
const space = graphOf(s);
|
|
66
|
-
const { tail, head, thickness } = s;
|
|
67
|
-
// Outside a graph an arrow is drawn in the scene's own units.
|
|
68
|
-
const from = space ? space.offset(tail.x, tail.y, tail.z) : tail;
|
|
69
|
-
const to = space ? space.offset(head.x, head.y, head.z) : head;
|
|
70
|
-
const along: Vector3 = { x: to.x - from.x, y: to.y - from.y, z: to.z - from.z };
|
|
71
|
-
const length = Math.hypot(along.x, along.y, along.z);
|
|
72
|
-
if (!(length > 0)) return g3;
|
|
73
|
-
|
|
74
|
-
const paint = Material.shorthand(s);
|
|
75
|
-
const quaternion = aim(along);
|
|
76
|
-
const tipLength = s.tip ? Math.min(thickness * 8, length) : 0;
|
|
77
|
-
const shaft = length - tipLength;
|
|
78
|
-
const at = (distance: number): Vector3 => ({
|
|
79
|
-
x: from.x + (along.x * distance) / length,
|
|
80
|
-
y: from.y + (along.y * distance) / length,
|
|
81
|
-
z: from.z + (along.z * distance) / length,
|
|
82
|
-
});
|
|
83
|
-
if (shaft > 0) g3.cylinder({ ...paint, radius: thickness, height: shaft, segments: [12, 1], position: at(shaft / 2), quaternion });
|
|
84
|
-
if (tipLength > 0) {
|
|
85
|
-
g3.cone({ ...paint, radius: thickness * 2.8, height: tipLength, segments: [20, 1], position: at(shaft + tipLength / 2), quaternion });
|
|
86
|
-
}
|
|
87
|
-
return g3;
|
|
88
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
component3d,
|
|
3
|
+
Graphics3D,
|
|
4
|
+
lerpVector3,
|
|
5
|
+
Material,
|
|
6
|
+
resolveVector3,
|
|
7
|
+
Types,
|
|
8
|
+
type Mesh3DProps,
|
|
9
|
+
type NodeOf,
|
|
10
|
+
type Values,
|
|
11
|
+
type Vector3,
|
|
12
|
+
type Vector3Input,
|
|
13
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
14
|
+
type Blend3D as _Blend3D,
|
|
15
|
+
type Color as _Color,
|
|
16
|
+
type Faces3D as _Faces3D,
|
|
17
|
+
type Fill3D as _Fill3D,
|
|
18
|
+
type Geometry3D as _Geometry3D,
|
|
19
|
+
type Material3D as _Material3D,
|
|
20
|
+
type Node3D as _Node3D,
|
|
21
|
+
type Node3DProps as _Node3DProps,
|
|
22
|
+
type NormalizedColor as _NormalizedColor,
|
|
23
|
+
type Shading3D as _Shading3D,
|
|
24
|
+
type Texture3D as _Texture3D,
|
|
25
|
+
} from "@motionscript/sdk";
|
|
26
|
+
import { meshEntries } from "./entries";
|
|
27
|
+
import { aim, graphEntry, graphOf } from "./space";
|
|
28
|
+
|
|
29
|
+
export interface VectorArrow3dProps extends Mesh3DProps {
|
|
30
|
+
tail?: Vector3Input;
|
|
31
|
+
head?: Vector3Input;
|
|
32
|
+
thickness?: number;
|
|
33
|
+
tip?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function point(initial: Vector3) {
|
|
37
|
+
return Types.custom<Vector3Input, Vector3>(initial, { resolve: resolveVector3, lerp: lerpVector3, kind: "vector3" });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const state = {
|
|
41
|
+
...meshEntries,
|
|
42
|
+
tail: point({ x: 0, y: 0, z: 0 }),
|
|
43
|
+
head: point({ x: 1, y: 1, z: 1 }),
|
|
44
|
+
/** The radius of the shaft, in scene units; the tip is sized from it. */
|
|
45
|
+
thickness: Types.number(0.035, { min: 0.001, step: 0.005 }),
|
|
46
|
+
tip: Types.boolean(true, { animatable: false }),
|
|
47
|
+
graph: graphEntry(),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** An arrow between two points of a 3D graph: a vector from the origin by default. */
|
|
51
|
+
export const VectorArrow3d = component3d({
|
|
52
|
+
key: "vectorArrow3d",
|
|
53
|
+
state,
|
|
54
|
+
commands: {
|
|
55
|
+
/** Animate either end, or both. */
|
|
56
|
+
endpointsTo: { args: ["tail", "head"] },
|
|
57
|
+
},
|
|
58
|
+
render: (ctx, s) => ctx.draw(drawArrow(s)),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export type VectorArrow3d = NodeOf<typeof VectorArrow3d>;
|
|
62
|
+
|
|
63
|
+
function drawArrow(s: Values<typeof state>): Graphics3D {
|
|
64
|
+
const g3 = new Graphics3D();
|
|
65
|
+
const space = graphOf(s);
|
|
66
|
+
const { tail, head, thickness } = s;
|
|
67
|
+
// Outside a graph an arrow is drawn in the scene's own units.
|
|
68
|
+
const from = space ? space.offset(tail.x, tail.y, tail.z) : tail;
|
|
69
|
+
const to = space ? space.offset(head.x, head.y, head.z) : head;
|
|
70
|
+
const along: Vector3 = { x: to.x - from.x, y: to.y - from.y, z: to.z - from.z };
|
|
71
|
+
const length = Math.hypot(along.x, along.y, along.z);
|
|
72
|
+
if (!(length > 0)) return g3;
|
|
73
|
+
|
|
74
|
+
const paint = Material.shorthand(s);
|
|
75
|
+
const quaternion = aim(along);
|
|
76
|
+
const tipLength = s.tip ? Math.min(thickness * 8, length) : 0;
|
|
77
|
+
const shaft = length - tipLength;
|
|
78
|
+
const at = (distance: number): Vector3 => ({
|
|
79
|
+
x: from.x + (along.x * distance) / length,
|
|
80
|
+
y: from.y + (along.y * distance) / length,
|
|
81
|
+
z: from.z + (along.z * distance) / length,
|
|
82
|
+
});
|
|
83
|
+
if (shaft > 0) g3.cylinder({ ...paint, radius: thickness, height: shaft, segments: [12, 1], position: at(shaft / 2), quaternion });
|
|
84
|
+
if (tipLength > 0) {
|
|
85
|
+
g3.cone({ ...paint, radius: thickness * 2.8, height: tipLength, segments: [20, 1], position: at(shaft + tipLength / 2), quaternion });
|
|
86
|
+
}
|
|
87
|
+
return g3;
|
|
88
|
+
}
|