mirror of
https://github.com/xibyte/jsketcher
synced 2026-02-13 19:02:53 +01:00
move out legacy bezier luts
This commit is contained in:
parent
eecb903a1c
commit
24acddcc5a
3 changed files with 36 additions and 39 deletions
|
|
@ -1,11 +1,9 @@
|
|||
import verb from 'verb-nurbs'
|
||||
import BrepCurve from '../../brep/geom/curves/brepCurve';
|
||||
import NurbsCurve from '../../brep/geom/curves/nurbsCurve';
|
||||
import {Point} from '../../brep/geom/point'
|
||||
import {LUT} from '../../math/bezier-cubic'
|
||||
import {makeAngle0_360} from '../../../../modules/math/commons'
|
||||
import {normalizeCurveEnds} from '../../brep/geom/impl/nurbs-ext';
|
||||
import Vector, {AXIS, ORIGIN} from '../../../../modules/math/vector';
|
||||
import Vector from '../../../../modules/math/vector';
|
||||
import CSys from "../../../../modules/math/csys";
|
||||
import {distanceAB} from "../../../../modules/math/distance";
|
||||
import {isCCW} from "../../../../modules/math/euclidean";
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
import Vector from 'math/vector';
|
||||
|
||||
export function LUT(a, b, cp1, cp2, scale) {
|
||||
scale = 1 / scale;
|
||||
const lut = [];
|
||||
for (let t = 0; t < 1; t += 0.1 * scale) {
|
||||
const p = compute(t, a, b, cp1, cp2);
|
||||
lut.push(p);
|
||||
}
|
||||
lut[0] = a;
|
||||
lut[lut.length - 1] = b;
|
||||
return lut;
|
||||
}
|
||||
|
||||
export function compute(t, from, to, controlPoint1, controlPoint2) {
|
||||
const mt = 1 - t;
|
||||
const mt2 = mt * mt;
|
||||
const t2 = t * t;
|
||||
|
||||
const a = mt2 * mt;
|
||||
const b = mt2 * t * 3;
|
||||
const c = mt * t2 * 3;
|
||||
const d = t * t2;
|
||||
const p0 = from;
|
||||
const p3 = to;
|
||||
const p1 = controlPoint1;
|
||||
const p2 = controlPoint2;
|
||||
return new Vector(
|
||||
a * p0.x + b * p1.x + c * p2.x + d * p3.x,
|
||||
a * p0.y + b * p1.y + c * p2.y + d * p3.y,
|
||||
a * p0.z + b * p1.z + c * p2.z + d * p3.z
|
||||
);
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
import {SketchObject} from './sketch-object'
|
||||
import {Segment} from './segment'
|
||||
import {LUT} from '../../math/bezier-cubic'
|
||||
import {ConvexHull2D} from '../../math/convex-hull'
|
||||
|
||||
import * as draw_utils from '../shapes/draw-utils'
|
||||
import {isPointInsidePolygon, polygonOffset} from "../../../../modules/math/euclidean";
|
||||
import {isPointInsidePolygon, polygonOffset} from "math/euclidean";
|
||||
import Vector from "math/vector";
|
||||
|
||||
|
||||
export class BezierCurve extends SketchObject {
|
||||
|
|
@ -123,4 +123,36 @@ BezierCurve.prototype.TYPE = 'BezierCurve';
|
|||
|
||||
BezierCurve.prototype._class = 'TCAD.TWO.BezierCurve';
|
||||
|
||||
const RECOVER_LENGTH = 100;
|
||||
const RECOVER_LENGTH = 100;
|
||||
|
||||
export function LUT(a, b, cp1, cp2, scale) {
|
||||
scale = 1 / scale;
|
||||
const lut = [];
|
||||
for (let t = 0; t < 1; t += 0.1 * scale) {
|
||||
const p = compute(t, a, b, cp1, cp2);
|
||||
lut.push(p);
|
||||
}
|
||||
lut[0] = a;
|
||||
lut[lut.length - 1] = b;
|
||||
return lut;
|
||||
}
|
||||
|
||||
export function compute(t, from, to, controlPoint1, controlPoint2) {
|
||||
const mt = 1 - t;
|
||||
const mt2 = mt * mt;
|
||||
const t2 = t * t;
|
||||
|
||||
const a = mt2 * mt;
|
||||
const b = mt2 * t * 3;
|
||||
const c = mt * t2 * 3;
|
||||
const d = t * t2;
|
||||
const p0 = from;
|
||||
const p3 = to;
|
||||
const p1 = controlPoint1;
|
||||
const p2 = controlPoint2;
|
||||
return new Vector(
|
||||
a * p0.x + b * p1.x + c * p2.x + d * p3.x,
|
||||
a * p0.y + b * p1.y + c * p2.y + d * p3.y,
|
||||
a * p0.z + b * p1.z + c * p2.z + d * p3.z
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue