Updates getPointsBetween
This commit is contained in:
parent
062dbafc36
commit
cbc26f2e06
3 changed files with 43 additions and 10 deletions
|
@ -970,9 +970,12 @@ interface ShapeUtility<K extends Shape> {
|
|||
* ## Utils
|
||||
*/
|
||||
class Utils {
|
||||
static pointsBetween(a: number[], b: number[], steps = 6): number[][] {
|
||||
static getPointsBetween(a: number[], b: number[], steps = 6): number[][] {
|
||||
return Array.from(Array(steps))
|
||||
.map((_, i) => ease(i / steps))
|
||||
.map((_, i) => {
|
||||
const t = i / steps
|
||||
return t * t * t
|
||||
})
|
||||
.map((t) => [...vec.lrp(a, b, t), (1 - t) / 2])
|
||||
}
|
||||
|
||||
|
@ -1605,7 +1608,7 @@ interface ShapeUtility<K extends Shape> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get a vector d distance from A towards B.
|
||||
* Push a point A towards point B by a given distance.
|
||||
* @param A
|
||||
* @param B
|
||||
* @param d
|
||||
|
@ -1615,6 +1618,16 @@ interface ShapeUtility<K extends Shape> {
|
|||
return Vec.add(A, Vec.mul(Vec.uni(Vec.vec(A, B)), d))
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a point in a given angle by a given distance.
|
||||
* @param A
|
||||
* @param B
|
||||
* @param d
|
||||
*/
|
||||
static nudgeAtAngle = (A: number[], a: number, d: number): number[] => {
|
||||
return [Math.cos(a) * d + A[0], Math.sin(a) * d + A[1]]
|
||||
}
|
||||
|
||||
/**
|
||||
* Round a vector to a precision length.
|
||||
* @param a
|
||||
|
@ -1623,6 +1636,21 @@ interface ShapeUtility<K extends Shape> {
|
|||
static toPrecision = (a: number[], n = 4): number[] => {
|
||||
return [+a[0].toPrecision(n), +a[1].toPrecision(n)]
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a number of points between two points.
|
||||
* @param a
|
||||
* @param b
|
||||
* @param steps
|
||||
*/
|
||||
static pointsBetween = (a: number[], b: number[], steps = 6): number[][] => {
|
||||
return Array.from(Array(steps))
|
||||
.map((_, i) => {
|
||||
const t = i / steps
|
||||
return t * t * t
|
||||
})
|
||||
.map((t) => [...Vec.lrp(a, b, t), (1 - t) / 2])
|
||||
}
|
||||
}
|
||||
|
||||
`,
|
||||
|
|
|
@ -5,6 +5,15 @@ import vec from 'utils/vec'
|
|||
* ## Utils
|
||||
*/
|
||||
export default class Utils {
|
||||
static getPointsBetween(a: number[], b: number[], steps = 6): number[][] {
|
||||
return Array.from(Array(steps))
|
||||
.map((_, i) => {
|
||||
const t = i / steps
|
||||
return t * t * t
|
||||
})
|
||||
.map((t) => [...vec.lrp(a, b, t), (1 - t) / 2])
|
||||
}
|
||||
|
||||
static getRayRayIntersection(
|
||||
p0: number[],
|
||||
n0: number[],
|
||||
|
|
|
@ -96,13 +96,9 @@ const initialData: Data = {
|
|||
code: `
|
||||
const draw = new Draw({
|
||||
points: [
|
||||
[0, 0],
|
||||
[0, 50],
|
||||
[20, 80],
|
||||
[56, 56],
|
||||
[52, 52],
|
||||
[80, 20],
|
||||
[90, 90],
|
||||
...Utils.getPointsBetween([0, 0], [20, 50]),
|
||||
...Utils.getPointsBetween([20, 50], [100, 20], 3),
|
||||
...Utils.getPointsBetween([100, 20], [100, 100], 10),
|
||||
[100, 100],
|
||||
],
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue