[geom-splines] expose cubic conversion for polylines
See original GitHub issueI’m trying to create smooth curve from a polyline and hit a roadblock when realized that cubic-from-controlpoints assumes that curve is closed. Turns of that buildNonUniform
is all I needed. Is there an official way to convert list of points to list of Cubics? Currently i’m doing:
let path = [[0, 0, 0], [0.5, 1, 0], [1, 0.25, 0]]
let segments = convertToSegments(path)
let cubics = buildNonUniform(segments, 1, false)
let resampledPath = cubics.reduce((resampledPath, c) => {
// resample each segment individually, is there better way?
var curve = sampleCubic(c, 6)
return resampledPath.concat(curve)
}, [])
// remove overlapping start/end points for each cubic
let smoothPath = simplify(resampledPath, 0, false)
assuming following buildNonUniform from cubic-from-controlpoints
const buildNonUniform = (segments, t = 1) => {
const res = []
for (let i = 0, n = segments.length - 2; i < n; i += 2) {
const a = segments[i]
const b = segments[i + 1]
const c = segments[i + 2]
res.push([a, vec3.lerp([...a], b, t), vec3.lerp([...c], b, t), c])
}
return res
}
and modified segment generation
function convertToSegments(path) {
const segments = [path[0], path[0]]
for (let i = 0, num = path.length - 1; i < num; i++) {
const q = path[i + 1];
segments.push(vec3.lerp([...path[i]], q, 0.5), [...q]);
}
segments.push(path[path.length-1])
return segments
}
Note: vec3.lerp
comes from pex-math/vec3.js#L150 and is similar to mixN
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How to convert splines to polylines in AutoCAD
To convert multiple splines at the same time, use the PEDIT command: At the command line in AutoCAD, type PEDIT. Type M for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Works great! My strange attractors thank you…
@vorg -
openCubicFromBreakPoints()
is now available too…