fit-curve icon indicating copy to clipboard operation
fit-curve copied to clipboard

[Feature Request] Option for closed mode

Open mazznoer opened this issue 5 years ago • 4 comments

New option for closed/ loop mode, where start point and end point supposed to be connected.

// Sample points
let points = [[169.08327661184504,100],[164.13682344149368,108.10236504087167],[158.6808325624972,115.06667699209477],[155.08373798899495,121.80919469911817],[150.82185297687838,127.93955010709587],[144.32724655475414,132.20562977140798],[138.11231161900426,135.7898428514393],[133.92334323717515,141.0062778054169],[130.92249863175175,148.72606104386634],[127.38245066461353,158.1906697084441],[121.92416058194807,167.4756280894482],[114.33817063332049,175.16332267719181],[104.99781519950876,179.43799780994365],[95.0246280840088,179.08127203363017],[85.86550319805295,174.09562706246345],[78.92673646229865,164.85683626453897],[73.77562359010429,155.7296366446203],[67.12747390471083,151.7988126464155],[57.86690053241443,150.93016833546463],[50.36693528035536,146.60855012703126],[49.209156638785366,136.9017077351812],[51.92425736063002,126.42986317361597],[52.00199247029985,119.0037555474922],[47.40659458858676,113.50369135277877],[40.46132833731972,107.52148338465331],[33.885621141836396,99.99999999999999],[31.658556367626133,91.36646790381246],[36.81803895223029,83.77762964047915],[46.061053480502366,78.6440603078885],[52.8676595756433,74.08877658297655],[54.93583885835325,67.25897044170699],[54.210729519951535,57.00101292345075],[54.6107491601339,45.1338207939469],[59.2514596766335,35.79057478860891],[68.14451674606336,32.303652177186734],[78.58988363379659,34.106437330729335],[87.69012980479268,35.4694005770497],[95.73740314283884,32.24796310253261],[104.54151772280292,27.81464289570043],[113.92483949803129,27.00343501378434],[122.5496246533553,30.59939143488714],[129.80609096804073,36.65883247394953],[136.7636163108876,42.06981027341028],[143.45036072986937,47.47753632719585],[147.56790731897257,55.33076175655141],[148.5280059052866,64.74233991051405],[149.52511172309568,72.77333942986147],[153.8532232469118,78.67800055251107],[161.17936128863602,84.29180986590764],[168.0284647657436,91.40600632950067]];

Sorry for my broken english.

mazznoer avatar Jan 09 '20 13:01 mazznoer

@mazznoer Hey :) You could prepare your array by duplicating your starting point and append it to the end of the list, before calling the fit function. That should give you a closed polyline.

nylki avatar Jan 09 '20 19:01 nylki

It would be closed, but the curves wouldn't match. Getting the curves to match would be a bit more difficult.

Yay295 avatar Jan 10 '20 04:01 Yay295

@Yay295 Exactly

Here is another sample points and its output.

let points = [[172,100],[166,114],[160,127],[156,141],[149,155],[128,149],[121,164],[107,163],[93,163],[82,154],[65,160],[52,154],[44,141],[35,129],[26,116],[37,100],[44,88],[28,68],[41,57],[48,42],[63,36],[77,28],[92,25],[108,28],[121,37],[130,48],[148,46],[156,59],[161,73],[163,87],[172,100]];

fitCurve(points, 30);

svgx-1578630432

Everything is smooth, except where the start and end point meet (green circle).

mazznoer avatar Jan 10 '20 04:01 mazznoer

I'd love to see this feature implemented.

designspin avatar May 10 '20 22:05 designspin