question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[geom-splines] expose cubic conversion for polylines

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
vorgcommented, Mar 3, 2020

Works great! My strange attractors thank you…

Screenshot 2020-03-03 at 10 12 15
1reaction
postspectacularcommented, Feb 25, 2020

@vorg - openCubicFromBreakPoints() is now available too…

open-brk

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found