Pomax / bezierjs

A nodejs and client-side library for (cubic) Bezier curve work
MIT License
1.75k stars 234 forks source link

getLUT function not generating z values for large inputs #116

Closed SahilRS200 closed 5 years ago

SahilRS200 commented 5 years ago

Hi,

I have a large input file, something like

[{"x":-2857420.9140500156,"y":4641993.331296496,"z":3300644.3972672834},{"x":-2876470.528692387,"y":4624771.111628751,"z":3308214.3370198156},{"x":-2895469.5899375114,"y":4607467.215074685,"z":3315726.0164609975},{"x":-2914417.76070472,"y":4590081.9454655005,"z":3323179.3013677783},{"x":-2933314.7047949964,"y":4572615.608104647,"z":3330574.0585474847},{"x":-2952160.0868972973,"y":4555068.509762563,"z":3337910.1558404807},{"x":-2970953.572594882,"y":4537440.958671404,"z":3345187.462122812},{"x":-2989694.828371595,"y":4519733.264519734,"z":3352405.847308815},{"x":-3008383.5216181683,"y":4501945.738447175,"z":3359565.1823537266},{"x":-3027019.320638483,"y":4484078.693039038,"z":3366665.3392562657},{"x":-3045601.8946558386,"y":4466132.442320918,"z":3373706.191061187},{"x":-3064130.9138191915,"y":4448107.301753244,"z":3380687.6118618376},{"x":-3082606.049209391,"y":4430003.588225827,"z":3387609.4768026713},{"x":-3101026.972845395,"y":4411821.6200523395,"z":3394471.6620817618},{"x":-3119393.357690465,"y":4393561.716964796,"z":3401274.044953284},{"x":-3137704.8776583616,"y":4375224.200107985,"z":3408016.503729982},{"x":-3155961.207619505,"y":4356809.3920338685,"z":3414698.9177856217},{"x":-3174162.0234071454,"y":4338317.616695956,"z":3421321.1675574076},{"x":-3192307.0018234877,"y":4319749.199443657,"z":3427883.134548401},{"x":-3210395.8206458273,"y":4301104.467016575,"z":3434384.701329906},{"x":-3228428.158632655,"y":4282383.7475387985,"z":3440825.75154383},{"x":-3246403.6955297505,"y":4263587.370513144,"z":3447206.169905048},{"x":-3264322.1120762555,"y":4244715.66681538,"z":3453525.842203711},{"x":-3282183.0900107436,"y":4225768.968688408,"z":3459784.655307574},{"x":-3299986.312077252,"y":4206747.609736426,"z":3465982.497164267},{"x":-3317731.462031313,"y":4187651.9249190455,"z":3472119.2568035764},{"x":-3335418.2246459695,"y":4168482.250545399,"z":3478194.82433968},{"x":-3353046.2857177597,"y":4149238.924268196,"z":3484209.090973384},{"x":-3370615.3320727022,"y":4129922.2850777637,"z":3490161.9489943255},{"x":-3388125.0515722353,"y":4110532.673296051,"z":3496053.2917831563},{"x":-3405575.133119186,"y":4091070.430570604,"z":3501883.0138137056},{"x":-3422965.2666636677,"y":4071535.8998685107,"z":3507651.010655132},{"x":-3440295.1432089987,"y":4051929.4254703172,"z":3513357.1789740417},{"x":-3457564.4548175796,"y":4032251.3529639235,"z":3519001.4165365845},{"x":-3474772.8946167747,"y":4012502.029238419,"z":3524583.6222105455},{"x":-3491920.156804744,"y":3992681.802477932,"z":3530103.6959674014},{"x":-3509005.9366562916,"y":3972791.0221554185,"z":3535561.538884353},{"x":-3526029.930528669,"y":3952830.0390264275,"z":3540957.0531463483},{"x":-3542991.835867367,"y":3932799.205122848,"z":3546290.142048081},{"x":-3559891.3512118924,"y":3912698.8737466186,"z":3551560.7099959534},{"x":-3576728.176201529,"y":3892529.3994634054,"z":3556768.6625100444},{"x":-3593502.01158106,"y":3872291.1380962646,"z":3561913.9062260212},{"x":-3610212.5592064913,"y":3851984.4467192553,"z":3566996.3488970743},{"x":-3626859.5220507463,"y":3831609.6836510547,"z":3572015.8993957797},{"x":-3643442.6042093416,"y":3811167.208448506,"z":3576972.467715981},{"x":-3659961.510906043,"y":3790657.38190017,"z":3581865.964974623},{"x":-3676415.9484984945,"y":3770080.566019841,"z":3586696.3034135844},{"x":-3692805.6244838363,"y":3749437.1240400253,"z":3591463.396401467},{"x":-3709130.2475043,"y":3728727.4204054037,"z":3596167.158435374},{"x":-3725389.5273527885,"y":3707951.820766242,"z":3600807.5051426776},{"x":-3741583.174978409,"y":3687110.691971827,"z":3605384.353282734}]

when i create a new Bezier([...coords]) and then do a getLUT(count), only first and last values get the z number and the intermediate points return with only x and y

[{"x":-2857420.9140500156,"y":4641993.331296496,"z":3300644.3972672834},{"x":-2867035.6062093554,"y":4633285.038127019},{"x":-2876637.620484418,"y":4624556.364692988},{"x":-2886226.9160974165,"y":4615807.347945566},{"x":-2895803.452321632,"y":4607038.024920339},{"x":-2905367.1884815777,"y":4598248.432737188},{"x":-2914918.0839531748,"y":4589438.608600141},{"x":-2924456.098163916,"y":4580608.589797225},{"x":-2933981.1905930387,"y":4571758.413700336},{"x":-2943493.320771686,"y":4562888.117765089},{"x":-2952992.448283081,"y":4553997.739530674},{"x":-2962478.5327626937,"y":4545087.31661972},{"x":-2971951.533898403,"y":4536156.886738136},{"x":-2981411.4114306723,"y":4527206.487674987},{"x":-2990858.125152711,"y":4518236.157302328},{"x":-3000291.634910642,"y":4509245.933575077},{"x":-3009711.900603673,"y":4500235.854530857},{"x":-3019118.8821842563,"y":4491205.958289858},{"x":-3028512.5396582624,"y":4482156.283054688},{"x":-3037892.833085141,"y":4473086.86711022},{"x":-3047259.722578093,"y":4463997.748823459},{"x":-3056613.168304226,"y":4454888.966643379},{"x":-3065953.130484734,"y":4445760.559100789},{"x":-3075279.5693950527,"y":4436612.564808174},{"x":-3084592.4453650285,"y":4427445.022459555},{"x":-3093891.718779084,"y":4418257.970830332},{"x":-3103177.350076383,"y":4409051.4487771345},{"x":-3112449.299750994,"y":4399825.495237689},{"x":-3121707.5283520566,"y":4390580.149230644},{"x":-3130951.996483947,"y":4381315.449855436},{"x":-3140182.6648064377,"y":4372031.436292134},{"x":-3149399.4940348677,"y":4362728.147801288},{"x":-3158602.4449403025,"y":4353405.623723777},{"x":-3167791.4783496982,"y":4344063.9034806555},{"x":-3176966.5551460665,"y":4334703.026573009},{"x":-3186127.636268639,"y":4325323.03258179},{"x":-3195274.6827130252,"y":4315923.961167674},{"x":-3204407.655531383,"y":4306505.852070897},{"x":-3213526.5158325764,"y":4297068.745111115},{"x":-3222631.224782336,"y":4287612.680187237},{"x":-3231721.7436034307,"y":4278137.697277279},{"x":-3240798.0335758193,"y":4268643.836438195},{"x":-3249860.056036821,"y":4259131.137805748},{"x":-3258907.772381268,"y":4249599.641594325},{"x":-3267941.1440616786,"y":4240049.388096798},{"x":-3276960.1325884094,"y":4230480.417684367},{"x":-3285964.69952982,"y":4220892.770806396},{"x":-3294954.806512434,"y":4211286.48799026},{"x":-3303930.4152210993,"y":4201661.609841189},{"x":-3312891.4873991483,"y":4192018.1770421094},{"x":-3321837.9848485603,"y":4182356.230353476},{"x":-3330769.8694301196,"y":4172675.810613131},{"x":-3339687.1030635755,"y":4162976.9587361338},{"x":-3348589.647727801,"y":4153259.715714598},{"x":-3357477.46546096,"y":4143524.122617545},{"x":-3366350.5183606544,"y":4133770.2205907297},{"x":-3375208.768584091,"y":4123998.050856488},{"x":-3384052.178348241,"y":4114207.6547135753},{"x":-3392880.7099299952,"y":4104399.0735370046},{"x":-3401694.3256663214,"y":4094572.3487778823},{"x":-3410492.9879544303,"y":4084727.521963248},{"x":-3419276.6592519246,"y":4074864.634695916},{"x":-3428045.302076959,"y":4064983.7286543064},{"x":-3436798.879008404,"y":4055084.8455922855},{"x":-3445537.3526859954,"y":4045168.0273390017},{"x":-3454260.685810495,"y":4035233.315798723},{"x":-3462968.8411438484,"y":4025280.752950669},{"x":-3471661.7815093393,"y":4015310.380848852},{"x":-3480339.4697917486,"y":4005322.241621907},{"x":-3489001.8689375063,"y":3995316.3774729297},{"x":-3497648.9419548544,"y":3985292.8306793123},{"x":-3506280.651913995,"y":3975251.6435925714},{"x":-3514896.9619472534,"y":3965192.8586381874},{"x":-3523497.8352492265,"y":3955116.5183154363},{"x":-3532083.235076942,"y":3945022.665197223},{"x":-3540653.1247500135,"y":3934911.3419299144},{"x":-3549207.4676507944,"y":3924782.5912331683},{"x":-3557746.22722453,"y":3914636.4558997694},{"x":-3566269.3669795142,"y":3904472.978795462},{"x":-3574776.850487244,"y":3894292.2028587726},{"x":-3583268.641382572,"y":3884094.1711008567},{"x":-3591744.7033638596,"y":3873878.9266053094},{"x":-3600205.00019313,"y":3863646.512528013},{"x":-3608649.495696223,"y":3853396.9720969587},{"x":-3617078.153762946,"y":3843130.3486120743},{"x":-3625490.9383472283,"y":3832846.68544506},{"x":-3633887.813467271,"y":3822546.026039213},{"x":-3642268.743205699,"y":3812228.413909256},{"x":-3650633.6917097187,"y":3801893.892641165},{"x":-3658982.623191259,"y":3791542.5058919997},{"x":-3667315.501927133,"y":3781174.297389732},{"x":-3675632.2922591837,"y":3770789.3109330665},{"x":-3683932.958594434,"y":3760387.590391271},{"x":-3692217.4654052407,"y":3749969.179704009},{"x":-3700485.777229444,"y":3739534.1228811536},{"x":-3708737.8586705127,"y":3729082.4640026265},{"x":-3716973.6743977023,"y":3718614.247218209},{"x":-3725193.1891461983,"y":3708129.5167473843},{"x":-3733396.3677172684,"y":3697628.3168791435},{"x":-3741583.174978409,"y":3687110.691971827,"z":3605384.353282734}]

I need all three points as i am calculating the bezier projection for geo coordinates which are converted to ecef(cartesian) coords and it needs all three axes for each points to convert back to geo cords

Pomax commented 5 years ago

On a sensibility note: you really don't want to do this, because that's not what Bezier curves are even remotely for. If you need a "higher than cubic" Bezier curve, you're almost certainly using the wrong curve type. Form a polybezier/catmull-rom curve through these points instead, or a B-spline (not supported by this library), and compute your full-curve LUT by aggregating the LUTs for each segment.

Pomax commented 5 years ago

v2.4.1 published