function createPolylinePath (options={}) {
    // construct a PolylinePathway given the number of points (vertices),
    // an array of points, and a path radius.
    let { points, pointCount, radius, cyclic } = options

    if (cyclic)
        pointCount++

    const normals = [ ]
    const lengths = [ ]
    let totalPathLength = 0

    // loop over all points
    for (let i = 0; i < pointCount; i++) {
        // copy in point locations, closing cycle when appropriate
        const closeCycle = cyclic && (i == pointCount-1)
        const j = closeCycle ? 0 : i
        points[i] = points[j]

        // for the end of each segment
        if (i > 0) {
            // compute the segment length
            normals[i] = vec2.subtract(vec2.create(), points[i], points[i-1])
            lengths[i] = vec2.length(normals[i])

            // find the normalized vector parallel to the segment
            vec2.normalize(normals[i], normals[i])

            // keep running total of segment lengths
            totalPathLength += lengths[i]
        }
    }

    return {
        pointCount,
        points,
        radius,
        cyclic,

        // lengths of each line segment between the points
        lengths,

        // unit vectors of each line segment between the points
        normals,

        totalPathLength
    }
}
// of a sphere at each point and a cylinder along each segment.
of a sphere at each point and a cylinder along each segment.
of a sphere at each point and a cylinder along each segment .
function createPolylinePath (options={}) {
    let { points, pointCount, radius, cyclic } = options
    if (cyclic)
        pointCount++
    const normals = [ ]
    const lengths = [ ]
    let totalPathLength = 0
    for (let i = 0; i < pointCount; i++) {
        const closeCycle = cyclic && (i == pointCount-1)
        const j = closeCycle ? 0 : i
        points[i] = points[j]
        if (i > 0) {
            normals[i] = vec2.subtract(vec2.create(), points[i], points[i-1])
            lengths[i] = vec2.length(normals[i])
            vec2.normalize(normals[i], normals[i])
            totalPathLength += lengths[i]
        }
    }
    return {
        pointCount,
        points,
        radius,
        cyclic,
        lengths,
        normals,
        totalPathLength
    }
}
function createPolylinePath ( options = { } ) { let { points , pointCount , radius , cyclic } = options if ( cyclic ) pointCount ++ const normals = [ ] const lengths = [ ] let totalPathLength = 0 for ( let i = 0 ; i < pointCount ; i ++ ) { const closeCycle = cyclic && ( i == pointCount - 1 ) const j = closeCycle ? 0 : i points [ i ] = points [ j ] if ( i > 0 ) { normals [ i ] = vec2 . subtract ( vec2 . create ( ) , points [ i ] , points [ i - 1 ] ) lengths [ i ] = vec2 . length ( normals [ i ] ) vec2 . normalize ( normals [ i ] , normals [ i ] ) totalPathLength += lengths [ i ] } } return { pointCount , points , radius , cyclic , lengths , normals , totalPathLength } }
of a sphere at each point and a cylinder along each segment.
of a sphere at each point and a cylinder along each segment .
// construct a PolylinePathway given the number of points (vertices), // an array of points, and a path radius. // loop over all points // copy in point locations, closing cycle when appropriate // for the end of each segment // compute the segment length // find the normalized vector parallel to the segment // keep running total of segment lengths // lengths of each line segment between the points // unit vectors of each line segment between the points