how to handle unclamped BSplineSurface

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: how to handle unclamped BSplineSurface

Post by microelly2 »

The problem is an inner multiplicity 4 of your data
when I change the knots a little bit I get a solution
try a mult 3 - in this case your curve goes through the pole.


Python 3.7.3 | packaged by conda-forge | (default, Dec 6 2019, 08:58:45)
[GCC 7.3.0] on linux
Type 'help', 'copyright', 'credits' or 'license' for more information.
>>> import numpy as np
>>> import random
>>>
>>> control_pts=[[[9.068757563189992, -2.6944957245128247, 17.490567855962535, 1], [8.93826943501047, -1.4555105066569196, 16.551231793471505, 1], [8.903305891202592, -0.5990170393119777, 15.735865559207014, 1], [8.893076120383126, -0.08738668080722323, 15.110594625103968, 1], [8.85917492092599, 1.6081432717300113, 13.038462704861793, 1], [9.088668280701501, 2.9624500761025057, 8.05556849032455, 1], [13.395147585080677, 7.041202828732808, 2.064628861818192, 1], [18.42599564039713, 13.725410449092601, -0.10904875905113254, 1], [19.80591507076088, 19.342946012850597, -0.3576913996663066, 1], [20.021262750768603, 22.341471235911392, -0.389206865375026, 1], [20.081573452138517, 23.181244198739183, -0.3980331496462297, 1], [20.112056326905346, 24.44282131479675, -0.399619215788922, 1], [20.027070707421146, 26.114396156084428, -0.36238554956480096, 1]], [[9.554691634598832, -2.883381617409447, 17.3081651437757, 1], [9.434026645353617, -1.5891038136867082, 16.452021580661345, 1], [9.401307711001477, -0.6796829894101543, 15.674941127178476, 1], [9.389237047388155, -0.123379394701022, 15.060969486660772, 1], [9.349235176187234, 1.7201965226664746, 13.026283137030267, 1], [9.504326776874015, 3.180809940544943, 8.154850422854125, 1], [13.71112712680983, 7.071922891237927, 2.224182645847926, 1], [18.613472088365718, 13.66942234334463, 0.013057202491092545, 1], [19.92605666030484, 19.278812349589483, -0.2161272050641137, 1], [20.10677254361049, 22.264739818843516, -0.21445408774461852, 1], [20.157384194827053, 23.100984629579102, -0.21398551116645761, 1], [20.173466566117312, 24.35662543608946, -0.19897775781156268, 1], [20.070028284901166, 26.01702757227097, -0.13535157389624994, 1]], [[9.915803489549713, -2.98161008654386, 17.192682830104943, 1], [9.801534219074009, -1.6614856607494113, 16.38365688587836, 1], [9.77022720171123, -0.723856652140193, 15.629637445130513, 1], [9.757106825341074, -0.1419635570768772, 15.024179687567434, 1], [9.71362623285009, 1.7864153114833141, 13.017708128795224, 1], [9.825125640152711, 3.325971314102241, 8.228791575296022, 1], [13.943695900826066, 7.107574438840525, 2.3454389429665734, 1], [18.747825938644773, 13.647313761392988, 0.11678709750972752, 1], [20.013152453330665, 19.236166662682955, -0.09988417233606635, 1], [20.169780368039692, 22.207705340083916, -0.08462890648598906, 1], [20.213645894660967, 23.039920397034848, -0.08035648626316771, 1], [20.219709308030573, 24.288863688144346, -0.058837896649712285, 1], [20.1036098131345, 25.938206146503383, 0.014898390964687595, 1]], [[10.153846461257803, -3.0118182457126306, 17.133245317109715, 1], [10.043085205164441, -1.6849290140708024, 16.34298706267264, 1], [10.012513604330385, -0.7376654127188789, 15.599719162147556, 1], [9.99893597014986, -0.14587482594081236, 15, 1], [9.953940036943408, 1.8153040776024303, 13.012546, 1], [10.044422647886826, 3.4122296492883084, 8.277596, 1], [14.094563022808646, 7.143717404548399, 2.427847737174211, 1], [18.8318309328357, 13.650531895743912, 0.19690755308181007, 1], [20.06874512515554, 19.212290323710793, -0.01399697076283558, 1], [20.211240533548427, 22.169929095399674, 0, 1], [20.251148082224407, 22.998251316995052, 0.0039200195875364096, 1], [20.251354511988726, 24.240791304478428, 0.02440605087850957, 1], [20.128029755740208, 25.880511180480603, 0.09618623196298172, 1]], [[10.715069278161772, -3.0821803821633993, 16.995559656802264, 1], [10.61263290970905, -1.7400721735949443, 16.247802866381882, 1], [10.583810875217662, -0.770225668464383, 15.529173587847769, 1], [10.569155053667432, -0.15509737084435324, 14.942985700522797, 1], [10.520586035030464, 1.883422110908222, 13.000374, 1], [10.561512260336833, 3.615621795733029, 8.392674, 1], [14.45029893750934, 7.228940419325408, 2.62216288948566, 1], [19.02990983203672, 13.658120069707275, 0.38582693574532617, 1], [20.19982941775947, 19.15599130260965, 0.1885200641698277, 1], [20.30900119675373, 22.080854903620118, 0.1995500481701333, 1], [20.339576063224126, 22.89999804545452, 0.20263912751908894, 1], [20.325993984876188, 24.127421543130247, 0.22069237948900883, 1], [20.18570711656094, 25.744419119294065, 0.2878667707053176, 1]], [[12.137154710171684, -2.8143721913698805, 16.831586168852205, 1], [12.090508906180155, -1.5495205542278456, 16.046425658220272, 1], [12.086800293252542, -0.6377511592161078, 15.340438023110964, 1], [12.080056354192225, -0.059755657538711586, 14.791989015651577, 1], [12.057707112235063, 1.8557066859975366, 12.974443, 1], [11.933305185359648, 3.975281724048325, 8.673814, 1], [15.3082064772923, 7.624687379600255, 3.1455850617688315, 1], [19.37431472068055, 13.929706757034074, 0.9457335577523813, 1], [20.431969920642167, 19.10595922283073, 0.7207913919251576, 1], [20.573544225237903, 21.83626427349529, 0.7280384452196381, 1], [20.61319380774476, 22.60091895913431, 0.7300680694395952, 1], [20.624200178736114, 23.75031968010881, 0.7478143075850376, 1], [20.536714542662523, 25.2735670207947, 0.8155451853330927, 1]], [[14.479222674173496, -2.827309167410598, 16.33325117681234, 1], [14.476892784638942, -1.582246465633871, 15.662451251326782, 1], [14.489333219125799, -0.6635688402946606, 15.04217399113688, 1], [14.487275165337845, -0.06385715804113179, 14.551254306807028, 1], [14.480454827601031, 1.9235720537809313, 12.924359, 1], [14.248213828067437, 4.244200425861611, 9.129797, 1], [16.75096586934408, 8.051448354581666, 3.9610032761021405, 1], [20.057965361625392, 14.161066473792669, 1.7871886138158974, 1], [20.845385690978247, 18.985794576116085, 1.5706914182832277, 1], [20.932354294073644, 21.492222377420617, 1.570609926175237, 1], [20.956710894756117, 22.19417755346109, 1.5705871033327117, 1], [20.955239386721868, 23.25192434095696, 1.5838725706653396, 1], [20.871353386535286, 24.65906203502376, 1.643575006303928, 1]], [[17.093541464703122, -2.5089608137300483, 16.006337529670837, 1], [17.181239781869987, -1.4016018210875516, 15.28819153496406, 1], [17.234262778848375, -0.5932309155181043, 14.699728109619276, 1], [17.247647703039462, -0.0689260552184985, 14.275224250518303, 1], [17.2920050002584, 1.6686068728447736, 12.868429293751374, 1], [16.898035656679237, 4.482854588794428, 9.640086429627052, 1], [18.341594352637085, 8.691156664361761, 4.9373963105824465, 1], [20.75679229218072, 14.531684628370385, 2.7923453226395663, 1], [21.227643362854163, 18.939505311892784, 2.5458793816560132, 1], [21.24543888701271, 21.18225739950589, 2.536715123186111, 1], [21.25042273705098, 21.81036702853898, 2.5341485626555533, 1], [21.231126001147373, 22.760592922003234, 2.544331518689196, 1], [21.145543460982985, 24.031916263603634, 2.600090342310477, 1]], [[18.920392954152447, -2.702406015180803, 15.59430621275493, 1], [19.04243399382607, -1.5289747324705094, 14.986962154566099, 1], [19.105162694236178, -0.6516131873322063, 14.46971763628216, 1], [19.11780615945611, -0.06851640703589716, 14.088205813300071, 1], [19.15970628056484, 1.86385144367135, 12.823885367180173, 1], [18.59844405447844, 4.9697369859564775, 9.974781370512387, 1], [19.342350578774802, 9.221773507445143, 5.5913265392967695, 1], [21.148714998747696, 14.862250240082751, 3.458637780205138, 1], [21.435120022950155, 18.953404465956762, 3.2074948626717026, 1], [21.443996875199762, 20.980352702732763, 3.1912796534496644, 1], [21.44648294417024, 21.548023874282368, 3.1867383895688275, 1], [21.433741819959476, 22.413304146124826, 3.1932638675619693, 1], [21.375969784981002, 23.582827864330998, 3.2429152362895586, 1]], [[19.801195425276696, -2.7735224347570058, 15.405544885135802, 1], [19.92787107954879, -1.5764227632252497, 14.843470039070993, 1], [19.989423425430385, -0.6734791560153905, 14.359213926171739, 1], [19.99988175629054, -0.06877306446664189, 14, 1], [20.03454039789024, 1.935207492314755, 12.80957421492216, 1], [19.429808608926177, 5.171486881684919, 10.137477168220672, 1], [19.87768181273596, 9.497351163990675, 5.968979, 1], [21.329795057383624, 15.047729923812062, 3.820045796436579, 1], [21.52156998516339, 18.980179975016434, 3.5197224435891643, 1], [21.527920082270395, 20.893746838022597, 3.5, 1], [21.529698503149024, 21.429664195581275, 3.4944764930574204, 1], [21.52141988955102, 22.25092482775538, 3.502007252168012, 1], [21.480218478496738, 23.368744067248798, 3.5558631429170746, 1]], [[20.041737734584974, -2.7930285959291217, 15.354520898279466, 1], [20.169706894886687, -1.5894172265141815, 14.804414648830921, 1], [20.23094704931422, -0.6794515438075754, 14.329031361712007, 1], [20.2408085408592, -0.06884316690428656, 13.975907798543668, 1], [20.273489272198262, 1.954697412930263, 12.80566532104802, 1], [19.65688437162301, 5.226592083369846, 10.181915281626553, 1], [20.023900156538122, 9.572621400383966, 6.072129561435096, 1], [21.379254578124506, 15.098391141471959, 3.9187594118913798, 1], [21.545182600110298, 18.987493336054975, 3.605003101385451, 1], [21.550842548896586, 20.870091640458707, 3.584322705097186, 1], [21.552427685458106, 21.39733588164268, 3.5785309120084086, 1], [21.54536451708056, 22.2065824377231, 3.5863286336789777, 1], [21.50867842454652, 23.310307273174786, 3.6413091357610017, 1]], [[20.40594618484721, -2.820708044763034, 15.276080633921255, 1], [20.537515994368214, -1.6078386713016324, 14.744356105357634, 1], [20.599121486387116, -0.6879355619583517, 14.282747851015452, 1], [20.608416011627085, -0.06900364338821018, 13.939148132416937, 1], [20.639217831098936, 1.9821209411339835, 12.800467432800612, 1], [20.001747314891986, 5.306115876062689, 10.249295766542291, 1], [20.237637536163817, 9.681782358766492, 6.22583259808834, 1], [21.449514976805517, 15.174335348746034, 4.065492415269333, 1], [21.57992999614285, 19.001080918442565, 3.735420274134082, 1], [21.584945284175742, 20.834730455741422, 3.7140289073227772, 1], [21.586349875759108, 21.34826600744622, 3.7080379984093184, 1], [21.58112725988918, 22.138895914067902, 3.716388102455463, 1], [21.55106281078853, 23.221327983587734, 3.7731076228529776, 1]], [[20.896553251824667, -2.8606298497253055, 15.166710043124404, 1], [21.03504791144836, -1.6343837078693666, 14.661694804783242, 1], [21.09817213104513, -0.7001533175394733, 14.219665647907943, 1], [21.10708183062173, -0.06923961778824746, 13.889283407596817, 1], [21.13660834766498, 2.021592283822501, 12.794405093747384, 1], [20.466330084363364, 5.412524159275467, 10.34002586650881, 1], [20.513618119919396, 9.823504617693153, 6.429354999881389, 1], [21.536320780802807, 15.276773598392356, 4.259072421756299, 1], [21.624535064611447, 19.023680869073925, 3.9130318011532386, 1], [21.629799999440408, 20.78788466327774, 3.8916246805843233, 1], [21.63127450760409, 21.2819711014696, 3.885629359642044, 1], [21.628813920304687, 22.046709193885192, 3.8948560170113535, 1], [21.607826618267254, 23.10031426673233, 3.953827745987022, 1]]]
>>>
>>> mini=0.000001 # data modified to avoid inner knot with multiplicity 4
>>>
>>> u_knots=[0.0, 0.028846153846153855, 0.057692307692307696, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.2514197274648126, 0.46332286746614004, 0.6733936359353537, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.9423076923076923, 0.9711538461538463, 1.0]
>>> v_knots=[0.0, 0.028846153846153855, 0.057692307692307696, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.3065754509112226, 0.49097355943978654, 0.6786170404802638, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.9423076923076923, 0.9711538461538463, 1.0]
>>>
>>> poles=np.array(control_pts)[:,:,0:3]
>>> weights=np.array(control_pts)[:,:,3]
>>>
>>> u_knots=[k+i*mini for i,k in enumerate(u_knots)]
>>> v_knots=[k+i*mini for i,k in enumerate(v_knots)]
>>>
>>> for k in u_knots:
... print(k)
...
0.0
0.028847153846153856
0.0576943076923077
0.1153876153846154
0.1153886153846154
0.1153896153846154
0.1153906153846154
0.2514267274648126
0.46333086746614005
0.6734026359353538
0.8846253846153846
0.8846263846153847
0.8846273846153847
0.8846283846153847
0.9423216923076922
0.9711688461538462
1.000016
>>> #------------------
>>>
>>> np.array(poles).shape
(13, 13, 3)
>>>
>>> len(u_knots)
17
>>> len(v_knots)
17
>>>
>>> for k in v_knots:
... print(k)
...
0.0
0.028847153846153856
0.0576943076923077
0.1153876153846154
0.1153886153846154
0.1153896153846154
0.1153906153846154
0.3065824509112226
0.49098155943978655
0.6786260404802639
0.8846253846153846
0.8846263846153847
0.8846273846153847
0.8846283846153847
0.9423216923076922
0.9711688461538462
1.000016
>>>
>>> uknots, umults = claps_knots(u_knots)
>>> vknots, vmults = claps_knots(v_knots)
>>>
>>> umults
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>>> vmults
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>>> sum(umults)
17
>>> sum(vmults)
17
>>>
>>>
>>> sf=Part.BSplineSurface()
>>> sf.buildFromPolesMultsKnots(poles,
... umults,vmults,uknots,vknots,
... False,False,3,3,weights)
>>>
>>> Part.show(sf.toShape())
>>>
>>>
>>>
>>>
>>> mini=0 # your data
>>>
>>> u_knots=[0.0, 0.028846153846153855, 0.057692307692307696, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.2514197274648126, 0.46332286746614004, 0.6733936359353537, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.9423076923076923, 0.9711538461538463, 1.0]
>>> v_knots=[0.0, 0.028846153846153855, 0.057692307692307696, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.3065754509112226, 0.49097355943978654, 0.6786170404802638, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.9423076923076923, 0.9711538461538463, 1.0]
>>>
>>> poles=np.array(control_pts)[:,:,0:3]
>>> weights=np.array(control_pts)[:,:,3]
>>>
>>> u_knots=[k+i*mini for i,k in enumerate(u_knots)]
>>> v_knots=[k+i*mini for i,k in enumerate(v_knots)]
>>>
>>> for k in u_knots:
... print(k)
...
0.0
0.028846153846153855
0.057692307692307696
0.11538461538461539
0.11538461538461539
0.11538461538461539
0.11538461538461539
0.2514197274648126
0.46332286746614004
0.6733936359353537
0.8846153846153847
0.8846153846153847
0.8846153846153847
0.8846153846153847
0.9423076923076923
0.9711538461538463
1.0
>>> #------------------
>>>
>>> np.array(poles).shape
(13, 13, 3)
>>>
>>> len(u_knots)
17
>>> len(v_knots)
17
>>>
>>> for k in v_knots:
... print(k)
...
0.0
0.028846153846153855
0.057692307692307696
0.11538461538461539
0.11538461538461539
0.11538461538461539
0.11538461538461539
0.3065754509112226
0.49097355943978654
0.6786170404802638
0.8846153846153847
0.8846153846153847
0.8846153846153847
0.8846153846153847
0.9423076923076923
0.9711538461538463
1.0
>>>
>>> uknots, umults = claps_knots(u_knots)
>>> vknots, vmults = claps_knots(v_knots)
>>>
>>> umults
[1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1] <------------ HERE is the error
>>> vmults
[1, 1, 1, 4, 1, 1, 1, 4, 1, 1, 1]
>>> sum(umults)
17
>>> sum(vmults)
17
>>>
>>>
>>> sf=Part.BSplineSurface()
>>> sf.buildFromPolesMultsKnots(poles,
... umults,vmults,uknots,vknots,
... False,False,3,3,weights)
Traceback (most recent call last):
File "<input>", line 3, in <module>
Part.OCCError: Geom_BSplineSurface
>>>
>>> Part.show(sf.toShape())

Code: Select all

import numpy as np
import random

control_pts=[[[9.068757563189992, -2.6944957245128247, 17.490567855962535, 1], [8.93826943501047, -1.4555105066569196, 16.551231793471505, 1], [8.903305891202592, -0.5990170393119777, 15.735865559207014, 1], [8.893076120383126, -0.08738668080722323, 15.110594625103968, 1], [8.85917492092599, 1.6081432717300113, 13.038462704861793, 1], [9.088668280701501, 2.9624500761025057, 8.05556849032455, 1], [13.395147585080677, 7.041202828732808, 2.064628861818192, 1], [18.42599564039713, 13.725410449092601, -0.10904875905113254, 1], [19.80591507076088, 19.342946012850597, -0.3576913996663066, 1], [20.021262750768603, 22.341471235911392, -0.389206865375026, 1], [20.081573452138517, 23.181244198739183, -0.3980331496462297, 1], [20.112056326905346, 24.44282131479675, -0.399619215788922, 1], [20.027070707421146, 26.114396156084428, -0.36238554956480096, 1]], [[9.554691634598832, -2.883381617409447, 17.3081651437757, 1], [9.434026645353617, -1.5891038136867082, 16.452021580661345, 1], [9.401307711001477, -0.6796829894101543, 15.674941127178476, 1], [9.389237047388155, -0.123379394701022, 15.060969486660772, 1], [9.349235176187234, 1.7201965226664746, 13.026283137030267, 1], [9.504326776874015, 3.180809940544943, 8.154850422854125, 1], [13.71112712680983, 7.071922891237927, 2.224182645847926, 1], [18.613472088365718, 13.66942234334463, 0.013057202491092545, 1], [19.92605666030484, 19.278812349589483, -0.2161272050641137, 1], [20.10677254361049, 22.264739818843516, -0.21445408774461852, 1], [20.157384194827053, 23.100984629579102, -0.21398551116645761, 1], [20.173466566117312, 24.35662543608946, -0.19897775781156268, 1], [20.070028284901166, 26.01702757227097, -0.13535157389624994, 1]], [[9.915803489549713, -2.98161008654386, 17.192682830104943, 1], [9.801534219074009, -1.6614856607494113, 16.38365688587836, 1], [9.77022720171123, -0.723856652140193, 15.629637445130513, 1], [9.757106825341074, -0.1419635570768772, 15.024179687567434, 1], [9.71362623285009, 1.7864153114833141, 13.017708128795224, 1], [9.825125640152711, 3.325971314102241, 8.228791575296022, 1], [13.943695900826066, 7.107574438840525, 2.3454389429665734, 1], [18.747825938644773, 13.647313761392988, 0.11678709750972752, 1], [20.013152453330665, 19.236166662682955, -0.09988417233606635, 1], [20.169780368039692, 22.207705340083916, -0.08462890648598906, 1], [20.213645894660967, 23.039920397034848, -0.08035648626316771, 1], [20.219709308030573, 24.288863688144346, -0.058837896649712285, 1], [20.1036098131345, 25.938206146503383, 0.014898390964687595, 1]], [[10.153846461257803, -3.0118182457126306, 17.133245317109715, 1], [10.043085205164441, -1.6849290140708024, 16.34298706267264, 1], [10.012513604330385, -0.7376654127188789, 15.599719162147556, 1], [9.99893597014986, -0.14587482594081236, 15, 1], [9.953940036943408, 1.8153040776024303, 13.012546, 1], [10.044422647886826, 3.4122296492883084, 8.277596, 1], [14.094563022808646, 7.143717404548399, 2.427847737174211, 1], [18.8318309328357, 13.650531895743912, 0.19690755308181007, 1], [20.06874512515554, 19.212290323710793, -0.01399697076283558, 1], [20.211240533548427, 22.169929095399674, 0, 1], [20.251148082224407, 22.998251316995052, 0.0039200195875364096, 1], [20.251354511988726, 24.240791304478428, 0.02440605087850957, 1], [20.128029755740208, 25.880511180480603, 0.09618623196298172, 1]], [[10.715069278161772, -3.0821803821633993, 16.995559656802264, 1], [10.61263290970905, -1.7400721735949443, 16.247802866381882, 1], [10.583810875217662, -0.770225668464383, 15.529173587847769, 1], [10.569155053667432, -0.15509737084435324, 14.942985700522797, 1], [10.520586035030464, 1.883422110908222, 13.000374, 1], [10.561512260336833, 3.615621795733029, 8.392674, 1], [14.45029893750934, 7.228940419325408, 2.62216288948566, 1], [19.02990983203672, 13.658120069707275, 0.38582693574532617, 1], [20.19982941775947, 19.15599130260965, 0.1885200641698277, 1], [20.30900119675373, 22.080854903620118, 0.1995500481701333, 1], [20.339576063224126, 22.89999804545452, 0.20263912751908894, 1], [20.325993984876188, 24.127421543130247, 0.22069237948900883, 1], [20.18570711656094, 25.744419119294065, 0.2878667707053176, 1]], [[12.137154710171684, -2.8143721913698805, 16.831586168852205, 1], [12.090508906180155, -1.5495205542278456, 16.046425658220272, 1], [12.086800293252542, -0.6377511592161078, 15.340438023110964, 1], [12.080056354192225, -0.059755657538711586, 14.791989015651577, 1], [12.057707112235063, 1.8557066859975366, 12.974443, 1], [11.933305185359648, 3.975281724048325, 8.673814, 1], [15.3082064772923, 7.624687379600255, 3.1455850617688315, 1], [19.37431472068055, 13.929706757034074, 0.9457335577523813, 1], [20.431969920642167, 19.10595922283073, 0.7207913919251576, 1], [20.573544225237903, 21.83626427349529, 0.7280384452196381, 1], [20.61319380774476, 22.60091895913431, 0.7300680694395952, 1], [20.624200178736114, 23.75031968010881, 0.7478143075850376, 1], [20.536714542662523, 25.2735670207947, 0.8155451853330927, 1]], [[14.479222674173496, -2.827309167410598, 16.33325117681234, 1], [14.476892784638942, -1.582246465633871, 15.662451251326782, 1], [14.489333219125799, -0.6635688402946606, 15.04217399113688, 1], [14.487275165337845, -0.06385715804113179, 14.551254306807028, 1], [14.480454827601031, 1.9235720537809313, 12.924359, 1], [14.248213828067437, 4.244200425861611, 9.129797, 1], [16.75096586934408, 8.051448354581666, 3.9610032761021405, 1], [20.057965361625392, 14.161066473792669, 1.7871886138158974, 1], [20.845385690978247, 18.985794576116085, 1.5706914182832277, 1], [20.932354294073644, 21.492222377420617, 1.570609926175237, 1], [20.956710894756117, 22.19417755346109, 1.5705871033327117, 1], [20.955239386721868, 23.25192434095696, 1.5838725706653396, 1], [20.871353386535286, 24.65906203502376, 1.643575006303928, 1]], [[17.093541464703122, -2.5089608137300483, 16.006337529670837, 1], [17.181239781869987, -1.4016018210875516, 15.28819153496406, 1], [17.234262778848375, -0.5932309155181043, 14.699728109619276, 1], [17.247647703039462, -0.0689260552184985, 14.275224250518303, 1], [17.2920050002584, 1.6686068728447736, 12.868429293751374, 1], [16.898035656679237, 4.482854588794428, 9.640086429627052, 1], [18.341594352637085, 8.691156664361761, 4.9373963105824465, 1], [20.75679229218072, 14.531684628370385, 2.7923453226395663, 1], [21.227643362854163, 18.939505311892784, 2.5458793816560132, 1], [21.24543888701271, 21.18225739950589, 2.536715123186111, 1], [21.25042273705098, 21.81036702853898, 2.5341485626555533, 1], [21.231126001147373, 22.760592922003234, 2.544331518689196, 1], [21.145543460982985, 24.031916263603634, 2.600090342310477, 1]], [[18.920392954152447, -2.702406015180803, 15.59430621275493, 1], [19.04243399382607, -1.5289747324705094, 14.986962154566099, 1], [19.105162694236178, -0.6516131873322063, 14.46971763628216, 1], [19.11780615945611, -0.06851640703589716, 14.088205813300071, 1], [19.15970628056484, 1.86385144367135, 12.823885367180173, 1], [18.59844405447844, 4.9697369859564775, 9.974781370512387, 1], [19.342350578774802, 9.221773507445143, 5.5913265392967695, 1], [21.148714998747696, 14.862250240082751, 3.458637780205138, 1], [21.435120022950155, 18.953404465956762, 3.2074948626717026, 1], [21.443996875199762, 20.980352702732763, 3.1912796534496644, 1], [21.44648294417024, 21.548023874282368, 3.1867383895688275, 1], [21.433741819959476, 22.413304146124826, 3.1932638675619693, 1], [21.375969784981002, 23.582827864330998, 3.2429152362895586, 1]], [[19.801195425276696, -2.7735224347570058, 15.405544885135802, 1], [19.92787107954879, -1.5764227632252497, 14.843470039070993, 1], [19.989423425430385, -0.6734791560153905, 14.359213926171739, 1], [19.99988175629054, -0.06877306446664189, 14, 1], [20.03454039789024, 1.935207492314755, 12.80957421492216, 1], [19.429808608926177, 5.171486881684919, 10.137477168220672, 1], [19.87768181273596, 9.497351163990675, 5.968979, 1], [21.329795057383624, 15.047729923812062, 3.820045796436579, 1], [21.52156998516339, 18.980179975016434, 3.5197224435891643, 1], [21.527920082270395, 20.893746838022597, 3.5, 1], [21.529698503149024, 21.429664195581275, 3.4944764930574204, 1], [21.52141988955102, 22.25092482775538, 3.502007252168012, 1], [21.480218478496738, 23.368744067248798, 3.5558631429170746, 1]], [[20.041737734584974, -2.7930285959291217, 15.354520898279466, 1], [20.169706894886687, -1.5894172265141815, 14.804414648830921, 1], [20.23094704931422, -0.6794515438075754, 14.329031361712007, 1], [20.2408085408592, -0.06884316690428656, 13.975907798543668, 1], [20.273489272198262, 1.954697412930263, 12.80566532104802, 1], [19.65688437162301, 5.226592083369846, 10.181915281626553, 1], [20.023900156538122, 9.572621400383966, 6.072129561435096, 1], [21.379254578124506, 15.098391141471959, 3.9187594118913798, 1], [21.545182600110298, 18.987493336054975, 3.605003101385451, 1], [21.550842548896586, 20.870091640458707, 3.584322705097186, 1], [21.552427685458106, 21.39733588164268, 3.5785309120084086, 1], [21.54536451708056, 22.2065824377231, 3.5863286336789777, 1], [21.50867842454652, 23.310307273174786, 3.6413091357610017, 1]], [[20.40594618484721, -2.820708044763034, 15.276080633921255, 1], [20.537515994368214, -1.6078386713016324, 14.744356105357634, 1], [20.599121486387116, -0.6879355619583517, 14.282747851015452, 1], [20.608416011627085, -0.06900364338821018, 13.939148132416937, 1], [20.639217831098936, 1.9821209411339835, 12.800467432800612, 1], [20.001747314891986, 5.306115876062689, 10.249295766542291, 1], [20.237637536163817, 9.681782358766492, 6.22583259808834, 1], [21.449514976805517, 15.174335348746034, 4.065492415269333, 1], [21.57992999614285, 19.001080918442565, 3.735420274134082, 1], [21.584945284175742, 20.834730455741422, 3.7140289073227772, 1], [21.586349875759108, 21.34826600744622, 3.7080379984093184, 1], [21.58112725988918, 22.138895914067902, 3.716388102455463, 1], [21.55106281078853, 23.221327983587734, 3.7731076228529776, 1]], [[20.896553251824667, -2.8606298497253055, 15.166710043124404, 1], [21.03504791144836, -1.6343837078693666, 14.661694804783242, 1], [21.09817213104513, -0.7001533175394733, 14.219665647907943, 1], [21.10708183062173, -0.06923961778824746, 13.889283407596817, 1], [21.13660834766498, 2.021592283822501, 12.794405093747384, 1], [20.466330084363364, 5.412524159275467, 10.34002586650881, 1], [20.513618119919396, 9.823504617693153, 6.429354999881389, 1], [21.536320780802807, 15.276773598392356, 4.259072421756299, 1], [21.624535064611447, 19.023680869073925, 3.9130318011532386, 1], [21.629799999440408, 20.78788466327774, 3.8916246805843233, 1], [21.63127450760409, 21.2819711014696, 3.885629359642044, 1], [21.628813920304687, 22.046709193885192, 3.8948560170113535, 1], [21.607826618267254, 23.10031426673233, 3.953827745987022, 1]]]

mini=0.000001 # data modified to avoid inner knot with multiplicity 4

u_knots=[0.0, 0.028846153846153855, 0.057692307692307696, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.2514197274648126, 0.46332286746614004, 0.6733936359353537, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.9423076923076923, 0.9711538461538463, 1.0]
v_knots=[0.0, 0.028846153846153855, 0.057692307692307696, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.3065754509112226, 0.49097355943978654, 0.6786170404802638, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.9423076923076923, 0.9711538461538463, 1.0]

poles=np.array(control_pts)[:,:,0:3]
weights=np.array(control_pts)[:,:,3]

u_knots=[k+i*mini for i,k in enumerate(u_knots)]
v_knots=[k+i*mini for i,k in enumerate(v_knots)]

for k in u_knots:
	print(k)

#------------------

np.array(poles).shape

len(u_knots)
len(v_knots)

for k in v_knots:
	print(k)


uknots, umults = claps_knots(u_knots)
vknots, vmults = claps_knots(v_knots)

umults
vmults
sum(umults)
sum(vmults)


sf=Part.BSplineSurface()
sf.buildFromPolesMultsKnots(poles,
			umults,vmults,uknots,vknots,
			False,False,3,3,weights)

Part.show(sf.toShape())




mini=0 # your data

u_knots=[0.0, 0.028846153846153855, 0.057692307692307696, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.2514197274648126, 0.46332286746614004, 0.6733936359353537, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.9423076923076923, 0.9711538461538463, 1.0]
v_knots=[0.0, 0.028846153846153855, 0.057692307692307696, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.11538461538461539, 0.3065754509112226, 0.49097355943978654, 0.6786170404802638, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.8846153846153847, 0.9423076923076923, 0.9711538461538463, 1.0]

poles=np.array(control_pts)[:,:,0:3]
weights=np.array(control_pts)[:,:,3]

u_knots=[k+i*mini for i,k in enumerate(u_knots)]
v_knots=[k+i*mini for i,k in enumerate(v_knots)]

for k in u_knots:
	print(k)

#------------------

np.array(poles).shape

len(u_knots)
len(v_knots)

for k in v_knots:
	print(k)


uknots, umults = claps_knots(u_knots)
vknots, vmults = claps_knots(v_knots)

umults
vmults
sum(umults)
sum(vmults)


sf=Part.BSplineSurface()
sf.buildFromPolesMultsKnots(poles,
			umults,vmults,uknots,vknots,
			False,False,3,3,weights)

Part.show(sf.toShape())

wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: how to handle unclamped BSplineSurface

Post by wmayer »

Part.OCCError: Geom_BSplineSurface

I checked the data, and I think the data satisfies
len(mults) ==len (knots)
sum(mults) == len(polers) + degree + 1

so I don't know where is the root cause of the error, please help me
I have tried your code and I cannot find an obvious mistake. So, I don't know why OpenCascade raises an error. I have to try the debug version of it and step through the code to see where and why it fails.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: how to handle unclamped BSplineSurface

Post by microelly2 »

wmayer wrote: Sun Feb 16, 2020 10:38 am I have tried your code and I cannot find an obvious mistake. So, I don't know why OpenCascade raises an error. I have to try the debug version of it and step through the code to see where and why it fails.
The problem is a multiplicity of degree +1 inside the mults list.
When the mults is at maximum equal to the degree the calculated curves goes through the related poles. This is a bezier segment.

For degree 3:
4,1,1,1,1,4 is okay (has 8 poles and goes through pole 0 and poles 7
4,3,1,4 is okay too and goes through pole 0, 3, 7
4,3,4 works with 7 poles and goes through 0, 3, 6: two bezier segments [0,1,2,3] and [3,4,5,6]
I use these bezier curves and surface segments because they are easy to edit
https://youtu.be/k8Hm43liMoQ
two bezier objects with common endpoints can be simply merged
assert polesA[-1]==polesB[0]

polesA + polesB[1:] ->
[4,3,4] + {4,3,3,4] -> [4,3,3,3,3,4]
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: how to handle unclamped BSplineSurface

Post by wmayer »

Thanks for the background information. Maybe we should add some extra checks when trying to create a B-spline with wrong values and raise a more meaningful error message.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: how to handle unclamped BSplineSurface

Post by microelly2 »

wmayer wrote: Sun Feb 16, 2020 6:08 pm Thanks for the background information. Maybe we should add some extra checks when trying to create a B-spline with wrong values and raise a more meaningful error message.
Yes, but there is more to do.
I played today a bit with periodic bsplines and there are some unexpected effects too.
I will first test it for surfaces too and than publish what should be changed.
silent_missile
Posts: 16
Joined: Mon Jul 29, 2019 11:07 pm

Re: how to handle unclamped BSplineSurface

Post by silent_missile »

Thank you experts.

To make your help more valuable, I took some more investigation about the algorithms. This is the reason why I reply so late.

Mirror extending algorithms would bring in another NURBS curve to describe the extended part.

If the user set the extend part to be another NURBS curve, the new part and the old part shares the end control point, and this point should have repeat degree of order+1 because it's end point not internal control point. For internal control points, the repeat degree should not exceed order.

In the application I want the extend surface to be one surface, so I have to reduce the repeat degree of the original end point to order, but this modification would make

len(mults) !=len (knots)
sum(mults) != len(polers) + degree + 1

so I try another method, I add a very tiny number for example 1e-6 to the 1st repeat knot for the start point and the last knot for the end point, then change of the knots looks like

old
[0, 0, 0, 0, k1, k2, k3, ...1, ,1 ,1, 1]
new
[-1e-6, 0, 0, 0, k1, k2, k3...1, 1, 1, 1+1e-6]

for an order 3 curve, the tiny modification would bring in a tiny distortion of the curve, but for CAD software, we all know: higher precision than 1e-6 meter is meaningless, because it can't be manufactured of measured in machine. So this tiny distortion is acceptable.

then prepend and append the extend part which was a new curve

[new start_ctrl_p[0] new start_ctrl_p[1], ... new start_ctrl_p[k-1],... old ctrl_p[1], old ctrl_p[2],...old last ctrl_p, new endt_ctrl_p[0] new end_ctrl_p[1], ... new end_ctrl_p[k-1]]

by NURBS theory, the k+1 control points can construct a curve with highest order k, so the user can't keep higher order continuity than the old curve, and if the user wants to get k degree continuity, the user needs extend k points, because the old curve and the new curve shares the end point, so actually the new curve has k+1 control points and can provide k order continuity

and corresponding knots_list

[-target, -1/2*target, ...-(1/2)**k*target, -1e-6, 0, 0, 0, k1, k2...kn, 1, 1, 1, 1+1e-6, 1+(1/2)**k*target, 1+(1/2)**(k-1)*target, ...1+target]

then claps the knots_list to knots and mults

the control points and the knots should satisfy

len(mults) ==len (knots)
sum(mults) == len(polers) + degree + 1

then use buildFromPolesMultsKnots function to construct the curve/surface by the control points and knots
Post Reply