Sections of a BSPlineCurve

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Sections of a BSPlineCurve

Post by onekk »

Probably already asked, but now I'm lost:

There is a way to section a BSPlineCurve, using some lines?

I have put together this example code.
20220813-bspline_sections.py
(18.1 KiB) Downloaded 13 times
While I have no problems in obtaining two sections, or better three, section1, section2 and section4:

With section3 I have some problems:

Code: Select all

    #sect3 = base_spline.trim(val2, val3)
    #Part.show(sect3.toShape(), "section3")
I obtain this error.

Code: Select all

line 84 in build_guide_curves
    sect3 = base_spline.trim(val2, val3)
<class 'Part.OCCError'>: Geom_BSplineCurve::Segment

calculate values for val1, val2, val3 and val4 are:

Code: Select all

0.6347036128356511 0.9011348830671121 0.1896785450093899 0.33167715079093957
I could guess that the problem is passing val2 and val3 to obtain a segment that cross the "start point" of the curve.

I could make some if conditions to generalize more the method, but the problem is to obtain section to pass to a gordon surface creations where I have to use the spline sections as "guide_curves"

Code: Select all

# InterpolateCurveNetwork(profile_curves, guide_curves, tol3, tol2)
gordon = InterpolateCurveNetwork([bs0,bs1,bs2],[bs3,bs4,bs5],0.1,0.001)
Hope of having explained decently my problem.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
edwilliams16
Veteran
Posts: 3107
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Sections of a BSPlineCurve

Post by edwilliams16 »

Shouldn't your BSpline be a periodic one?
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Sections of a BSPlineCurve

Post by onekk »

edwilliams16 wrote: Sat Aug 13, 2022 7:55 pm Shouldn't your BSpline be a periodic one?
If you intend "closed" BSpline, yes I've forgotten the correct term sorry.

EDIT:

I've checked the code and I've seen that probably the BSPline is not periodic at all,

in the original code is created with:

Code: Select all

newpoints = []

for point in cm_pts:
    newpoints.append(Vector(*point))

base_spline = Part.BSplineCurve()
base_spline.buildFromPoles(newpoints)

The test code above is created using the methods supplied from Curves WB to generate Python Code starting from the original BSPline:

Code: Select all

periodic0 = False
degree0 = 3
rational0 = False
bs0 = Part.BSplineCurve()
bs0.buildFromPolesMultsKnots(poles0, mults0, knots0, periodic0, degree0, weights0, rational0)
So now the question is how to close a BSpline?

I've already had an answer some time ago,

These forum posts explain the mechanics:

https://forum.freecadweb.org/viewtopic. ... 21#p615621

https://forum.freecadweb.org/viewtopic. ... 21#p561221

But I'm missing the passages to pass from the open BSPline to the closed BSpline using the original points.

Probably there are some passages to create the missing (in my case) mults0 and knots0 as I have only some "interpolated points that populate the poles of the first piece of code:

Code: Select all

or point in cm_pts:
    newpoints.append(Vector(*point))
END EDIT:

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
edwilliams16
Veteran
Posts: 3107
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Sections of a BSPlineCurve

Post by edwilliams16 »

I made your bspline periodic with bspline.setPeriodic(). Its parameter range is 0 <= u < 1 Being periodic makes u + n (n integer) the same point for every n.

Your u parameters go like 0 < val3 < val4 <val1 < val2 < 1

spline.trim(val3, val4) cuts out the segment between 3 and 4 as expected. However the trim function doesn't handle spline.trim(val2, val3) correctly as it doesn't realize the curve is periodic - spline.trim(val2, val3 + 1) fixes this, cutting the section out between 2 and 3 in the direction of increasing u parameter.

Note that if you want the (shorter) section between 1 and 4, starting at 1, you need spline.trim(val4, val1).reverse()

Code: Select all

import FreeCAD
from FreeCAD import Vector
import Part

DOC = FreeCAD.ActiveDocument

if DOC is None:
    FreeCAD.newDocument("test_bspline")
    DOC = FreeCAD.ActiveDocument

DOC = FreeCAD.ActiveDocument
DEBUG = False

if DEBUG:
    import sys
    freecadpython = sys.executable.replace('freecad', 'python')
    App.Console.PrintMessage('Using ' + freecadpython +'\n')
    try:
        import debugpy
    except ModuleNotFoundError:
        App.Console.PrintMessage('Install debugpy by: ' + freecadpython + ' -m pip install --upgrade debugpy\n')
    #see https://github.com/microsoft/debugpy/issues/262
       
    debugpy.configure(python=freecadpython)
    if not debugpy.is_client_connected():
        debugpy.listen(5678)

    App.Console.PrintMessage("Waiting for debugger attach\n")
    debugpy.wait_for_client()
    debugpy.breakpoint()


poles0 = [Vector (-56.64199999999988, -108.52651511673002, 0.0), Vector (-47.7919859277423, -105.28034589991853, 0.0), Vector (-38.888377225634116, -102.18420059598452, 0.0), Vector (-29.933716868418003, -99.23896350022585, 0.0), Vector (-20.930562411786696, -96.44547580679159, 0.0), Vector (-11.881485261914264, -93.8045353684272, 0.0), Vector (-2.7890699410333184, -91.316896468599, 0.0), Vector (6.344086650735676, -88.98326960606119, 0.0), Vector (15.51537597708844, -86.80432129192957, 0.0), Vector (24.722178610566417, -84.7806738593182, 0.0), Vector (33.961864980694756, -82.91290528559352, 0.0), Vector (43.2317961250195, -81.20154902729735, 0.0), Vector (52.529324442825086, -79.64709386778577, 0.0), Vector (61.851794451321, -78.2499837776262, 0.0), Vector (71.19654354407778, -77.0106177877949, 0.0), Vector (80.56090275149953, -75.92934987570902, 0.0), Vector (89.94219750311183, -75.00648886412569, 0.0), Vector (99.33774839145133, -74.24229833293975, 0.0), Vector (108.74487193733486, -73.63699654390155, 0.0), Vector (118.16088135629343, -73.19075637827893, 0.0), Vector (127.58308732594845, -72.90370528748042, 0.0), Vector (137.00879875411403, -72.77592525665375, 0.0), Vector (146.43532354740452, -72.8074527812696, 0.0), Vector (155.85996938012778, -72.99827885669845, 0.0), Vector (165.28004446324445, -73.3483489807819, 0.0), Vector (174.69285831317472, -73.85756316939978, 0.0), Vector (184.09572252023216, -74.52577598502626, 0.0), Vector (193.4859515164646, -75.35279657826868, 0.0), Vector (202.86086334268361, -76.33838874237631, 0.0), Vector (212.21778041446356, -77.48227098070413, 0.0), Vector (221.5540302868914, -78.7841165871107, 0.0), Vector (230.86694641784777, -80.24355373927051, 0.0), Vector (240.15386892960242, -81.86016560486962, 0.0), Vector (248.9731868856047, -85.14998874821593, 0.0), Vector (258.0410087091944, -87.71242906404285, 0.0), Vector (267.315911594915, -89.37606047063355, 0.0), Vector (276.7090296974566, -90.12494317723734, 0.0), Vector (286.13036451326974, -89.95190189635201, 0.0), Vector (295.4896471853463, -88.85859459247474, 0.0), Vector (304.6972033983433, -86.85549659660789, 0.0), Vector (313.6648125772109, -83.96180023872353, 0.0), Vector (322.30655315706497, -80.20523095984058, 0.0), Vector (330.53962582549855, -75.62178166560417, 0.0), Vector (338.28514684958265, -70.25536786661178, 0.0), Vector (345.46890388643305, -64.15740690969784, 0.0), Vector (352.022067035678, -57.38632533169853, 0.0), Vector (357.88184832100256, -50.00699905589909, 0.0), Vector (362.99210328206374, -42.090131794823264, 0.0), Vector (367.30386891272974, -33.71157761508846, 0.0), Vector (370.7758327914832, -24.951614155051914, 0.0), Vector (373.37472890909754, -15.894173458784934, 0.0), Vector (375.07565640103434, -6.626037796003672, 0.0), Vector (375.8623181306826, 2.7639918269342156, 0.0), Vector (375.7271768374974, 12.185946498201766, 0.0), Vector (374.67152735393176, 21.549551421755083, 0.0), Vector (372.70548419922807, 30.765090869361334, 0.0), Vector (369.8478846689366, 39.744267776017224, 0.0), Vector (366.1261083486925, 48.401049742695974, 0.0), Vector (361.5758147815475, 56.65249334059703, 0.0), Vector (356.24060180235057, 64.41953881897251, 0.0), Vector (350.1715878127872, 71.62776760217787, 0.0), Vector (343.4269219994341, 78.2081153181218, 0.0), Vector (336.07122718758876, 84.09753352636085, 0.0), Vector (328.1749806690735, 89.23959380560476, 0.0), Vector (319.81383893649934, 93.58502841267831, 0.0), Vector (311.06791279393406, 97.09220233270787, 0.0), Vector (302.0209997893683, 99.72751219766985, 0.0), Vector (292.75978132329845, 101.4657082511312, 0.0), Vector (283.372992126182, 102.29013627433534, 0.0), Vector (273.9505700622782, 102.19289715566003, 0.0), Vector (264.5827944058706, 101.17492257456162, 0.0), Vector (255.35942084633317, 99.24596607485276, 0.0), Vector (246.36882150983, 96.42450961284332, 0.0), Vector (237.5202028867966, 93.17832912815834, 0.0), Vector (228.54791246815876, 90.28841710413747, 0.0), Vector (219.48088552023586, 87.71109112774258, 0.0), Vector (210.33000867385084, 85.44944575208109, 0.0), Vector (201.1062692370266, 83.50619649773063, 0.0), Vector (191.8207420027061, 81.88367659225872, 0.0), Vector (182.4845759514291, 80.58383416875398, 0.0), Vector (173.108980864934, 79.60822992673508, 0.0), Vector (163.70521386675577, 78.95803525824402, 0.0), Vector (154.28456590598313, 78.63403084137514, 0.0), Vector (144.85834820040026, 78.63660570292757, 0.0), Vector (135.43787865529208, 78.96575675130725, 0.0), Vector (126.03446827422198, 79.62108878023884, 0.0), Vector (116.65940757809443, 80.60181494328333, 0.0), Vector (107.32395304881051, 81.906757698592, 0.0), Vector (98.0393136137959, 83.53435022276142, 0.0), Vector (88.84751156665534, 85.61398007591114, 0.0), Vector (79.87942134582622, 88.50760264707017, 0.0), Vector (71.21543499690037, 92.21368337188969, 0.0), Vector (62.928978829625414, 96.7008136331015, 0.0), Vector (55.09027962792554, 101.93096550647208, 0.0), Vector (47.765769485807155, 107.85981404318282, 0.0), Vector (40.705096851224106, 114.10246454243367, 0.0), Vector (33.0891850669656, 119.65062891067672, 0.0), Vector (24.944104225869552, 124.38791698030678, 0.0), Vector (16.35586442629087, 128.26430412655296, 0.0), Vector (7.415155418800371, 131.23885663172535, 0.0), Vector (-1.7836110558102618, 133.28016393544735, 0.0), Vector (-11.143298231846394, 134.36667032263264, 0.0), Vector (-20.565070059637296, 134.48690254666175, 0.0), Vector (-29.949434890493947, 133.6395909841122, 0.0), Vector (-39.19729608463493, 131.8336830416769, 0.0), Vector (-48.270454181715664, 129.2804599061286, 0.0), Vector (-57.5089533295608, 127.42972731993632, 0.0), Vector (-66.89367294037379, 126.59180403182881, 0.0), Vector (-76.31391379172884, 126.7765739232957, 0.0), Vector (-85.6585576637372, 127.98185750638619, 0.0), Vector (-94.8173780548756, 130.19343763226863, 0.0), Vector (-103.6823403793832, 133.38522719227907, 0.0), Vector (-112.17085347036885, 137.4780138798098, 0.0), Vector (-120.65208512897192, 141.5914933122695, 0.0), Vector (-129.28199710883348, 145.3831450246506, 0.0), Vector (-138.0483826169826, 148.8476058211778, 0.0), Vector (-146.93884182208242, 151.97997530937928, 0.0), Vector (-155.94079939367936, 154.77582283156812, 0.0), Vector (-165.04152228969062, 157.23119373189596, 0.0), Vector (-174.2281377669716, 159.3426149501141, 0.0), Vector (-183.4876515894865, 161.10709993412962, 0.0), Vector (-192.80696640832755, 162.52215286440807, 0.0), Vector (-202.17290028758512, 163.5857721842472, 0.0), Vector (-211.57220534986374, 164.29645343092852, 0.0), Vector (-220.9915865150705, 164.65319136374202, 0.0), Vector (-230.4177203059712, 164.65548138587363, 0.0), Vector (-239.8372734695545, 164.30331626568707, 0.0), Vector (-249.22853449018976, 163.5020019746425, 0.0), Vector (-258.5580520344799, 162.1611102782264, 0.0), Vector (-267.79485060824834, 160.28509315187446, 0.0), Vector (-276.90826255916727, 157.8801792732538, 0.0), Vector (-285.8680298982814, 154.9543533420542, 0.0), Vector (-294.64440476138225, 151.51732956950514, 0.0), Vector (-303.2082481766877, 147.58051942563668, 0.0), Vector (-311.5311268109003, 143.15699375136927, 0.0), Vector (-319.58540737243305, 138.2614393612261, 0.0), Vector (-327.3443483583684, 132.91011028075388, 0.0), Vector (-334.7821888405356, 127.1207737805518, 0.0), Vector (-341.8742339959225, 120.91265138608436, 0.0), Vector (-348.59693709744846, 114.3063550591347, 0.0), Vector (-354.92797769287307, 107.32381876278644, 0.0), Vector (-360.84633571227687, 99.98822563714938, 0.0), Vector (-366.33236125806394, 92.32393102761692, 0.0), Vector (-371.3678398457723, 84.35638162121437, 0.0), Vector (-375.9360528790835, 76.11203095951754, 0.0), Vector (-380.0218331582426, 67.61825160865317, 0.0), Vector (-383.6116152375935, 58.90324427799037, 0.0), Vector (-386.6934804650339, 49.99594418926365, 0.0), Vector (-389.2571965538506, 40.925925006997495, 0.0), Vector (-391.29425155555316, 31.72330064919743, 0.0), Vector (-392.79788212090693, 22.418625304314663, 0.0), Vector (-393.7630959553371, 13.042791986440472, 0.0), Vector (-394.18668839414755, 3.6269299655461933, 0.0), Vector (-394.0672530425209, -5.797698586684166, 0.0), Vector (-393.4051864449753, -15.199802392277414, 0.0), Vector (-392.20268676877276, -24.54816495903038, 0.0), Vector (-390.46374650565167, -33.81174822427022, 0.0), Vector (-388.19413921611374, -42.95979560619893, 0.0), Vector (-385.4014003602775, -51.96193412067626, 0.0), Vector (-382.0948022789424, -60.78827522439799, 0.0), Vector (-378.28532340793083, -69.40951404965112, 0.0), Vector (-373.9856118279206, -77.7970267011743, 0.0), Vector (-369.20994327078904, -85.92296529207947, 0.0), Vector (-363.97417372189454, -93.76035040330142, 0.0), Vector (-358.295686775662, -101.28316065959544, 0.0), Vector (-352.1933359192628, -108.46641912467514, 0.0), Vector (-345.6873819360138, -115.28627622864603, 0.0), Vector (-338.7994256363284, -121.72008895240168, 0.0), Vector (-331.55233613956204, -127.74649600607765, 0.0), Vector (-323.9701749448695, -133.34548875195904, 0.0), Vector (-316.0781160431691, -138.4984776363663, 0.0), Vector (-307.90236233545636, -143.18835390995378, 0.0), Vector (-299.47005863497196, -147.39954643150082, 0.0), Vector (-290.80920154206865, -151.1180733665976, 0.0), Vector (-281.9485464910087, -154.33158860957718, 0.0), Vector (-272.9175122773122, -157.0294227745658, 0.0), Vector (-263.74608338263846, -159.2026186195549, 0.0), Vector (-254.46471042149864, -160.84396078588082, 0.0), Vector (-245.10420904033384, -161.94799975437246, 0.0), Vector (-235.69565760462729, -162.51106993862865, 0.0), Vector (-226.27029401374764, -162.53130185535292, 0.0), Vector (-216.85941198611442, -162.00862833133766, 0.0), Vector (-207.49425715903539, -160.94478472649007, 0.0), Vector (-198.1985167781159, -159.38308570070905, 0.0), Vector (-188.9523935803173, -157.54821083259674, 0.0), Vector (-179.75662582212215, -155.47567245952763, 0.0), Vector (-170.6173213759986, -153.16684717129846, 0.0), Vector (-161.5405506112146, -150.62326850059287, 0.0), Vector (-152.5323423618721, -147.84662590440263, 0.0), Vector (-143.59867992252498, -144.83876364188166, 0.0), Vector (-134.7454970740472, -141.60167954938044, 0.0), Vector (-125.97867414238848, -138.13752371347425, 0.0), Vector (-117.30403409283193, -134.44859704286455, 0.0), Vector (-108.72727723911248, -130.53748016363102, 0.0), Vector (-100.17069133143457, -126.58197619956104, 0.0), Vector (-91.56235700959934, -122.74039394627562, 0.0), Vector (-82.90379093769877, -119.01341023504551, 0.0), Vector (-74.19651862993283, -115.40168170653487, 0.0), Vector (-65.44207418183686, -111.9058446951102, 0.0), Vector (-56.641999999999854, -108.52651511673002, 0.0)]
weights0 = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
knots0 = [0.0, 0.005076142131979695, 0.01015228426395939, 0.015228426395939087, 0.02030456852791878, 0.025380710659898477, 0.030456852791878174, 0.03553299492385787, 0.04060913705583756, 0.04568527918781726, 0.050761421319796954, 0.05583756345177665, 0.06091370558375635, 0.06598984771573604, 0.07106598984771574, 0.07614213197969544, 0.08121827411167512, 0.08629441624365482, 0.09137055837563451, 0.09644670050761421, 0.10152284263959391, 0.1065989847715736, 0.1116751269035533, 0.116751269035533, 0.1218274111675127, 0.12690355329949238, 0.1319796954314721, 0.13705583756345177, 0.14213197969543148, 0.14720812182741116, 0.15228426395939088, 0.15736040609137056, 0.16243654822335024, 0.16751269035532995, 0.17258883248730963, 0.17766497461928935, 0.18274111675126903, 0.18781725888324874, 0.19289340101522842, 0.19796954314720813, 0.20304568527918782, 0.20812182741116753, 0.2131979695431472, 0.2182741116751269, 0.2233502538071066, 0.22842639593908629, 0.233502538071066, 0.23857868020304568, 0.2436548223350254, 0.24873096446700507, 0.25380710659898476, 0.25888324873096447, 0.2639593908629442, 0.26903553299492383, 0.27411167512690354, 0.27918781725888325, 0.28426395939086296, 0.2893401015228426, 0.29441624365482233, 0.29949238578680204, 0.30456852791878175, 0.3096446700507614, 0.3147208121827411, 0.3197969543147208, 0.3248730964467005, 0.3299492385786802, 0.3350253807106599, 0.3401015228426396, 0.34517766497461927, 0.350253807106599, 0.3553299492385787, 0.3604060913705584, 0.36548223350253806, 0.37055837563451777, 0.3756345177664975, 0.38071065989847713, 0.38578680203045684, 0.39086294416243655, 0.39593908629441626, 0.4010152284263959, 0.40609137055837563, 0.41116751269035534, 0.41624365482233505, 0.4213197969543147, 0.4263959390862944, 0.43147208121827413, 0.4365482233502538, 0.4416243654822335, 0.4467005076142132, 0.4517766497461929, 0.45685279187817257, 0.4619289340101523, 0.467005076142132, 0.4720812182741117, 0.47715736040609136, 0.48223350253807107, 0.4873096446700508, 0.49238578680203043, 0.49746192893401014, 0.5025380710659898, 0.5076142131979695, 0.5126903553299492, 0.5177664974619289, 0.5228426395939086, 0.5279187817258884, 0.5329949238578681, 0.5380710659898477, 0.5431472081218274, 0.5482233502538071, 0.5532994923857868, 0.5583756345177665, 0.5634517766497462, 0.5685279187817259, 0.5736040609137056, 0.5786802030456852, 0.583756345177665, 0.5888324873096447, 0.5939086294416244, 0.5989847715736041, 0.6040609137055838, 0.6091370558375635, 0.6142131979695431, 0.6192893401015228, 0.6243654822335025, 0.6294416243654822, 0.6345177664974619, 0.6395939086294417, 0.6446700507614214, 0.649746192893401, 0.6548223350253807, 0.6598984771573604, 0.6649746192893401, 0.6700507614213198, 0.6751269035532995, 0.6802030456852792, 0.6852791878172588, 0.6903553299492385, 0.6954314720812182, 0.700507614213198, 0.7055837563451777, 0.7106598984771574, 0.7157360406091371, 0.7208121827411168, 0.7258883248730964, 0.7309644670050761, 0.7360406091370558, 0.7411167512690355, 0.7461928934010152, 0.751269035532995, 0.7563451776649747, 0.7614213197969543, 0.766497461928934, 0.7715736040609137, 0.7766497461928934, 0.7817258883248731, 0.7868020304568528, 0.7918781725888325, 0.7969543147208121, 0.8020304568527918, 0.8071065989847716, 0.8121827411167513, 0.817258883248731, 0.8223350253807107, 0.8274111675126904, 0.8324873096446701, 0.8375634517766497, 0.8426395939086294, 0.8477157360406091, 0.8527918781725888, 0.8578680203045685, 0.8629441624365483, 0.868020304568528, 0.8730964467005076, 0.8781725888324873, 0.883248730964467, 0.8883248730964467, 0.8934010152284264, 0.8984771573604061, 0.9035532994923858, 0.9086294416243654, 0.9137055837563451, 0.9187817258883249, 0.9238578680203046, 0.9289340101522843, 0.934010152284264, 0.9390862944162437, 0.9441624365482234, 0.949238578680203, 0.9543147208121827, 0.9593908629441624, 0.9644670050761421, 0.9695431472081218, 0.9746192893401016, 0.9796954314720813, 0.9847715736040609, 0.9898477157360406, 0.9949238578680203, 1.0]
mults0 = [4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4]
periodic0 = False
degree0 = 3
rational0 = False
bs0 = Part.BSplineCurve()
bs0.buildFromPolesMultsKnots(poles0, mults0, knots0, periodic0, degree0, weights0, rational0)
bs0.setPeriodic()

def build_guide_curves(base_spline, fact1, fact2):
    """Build guide curves for gordon surface."""
    sp_dims = base_spline.toShape().BoundBox

    xmax = sp_dims.XMax
    xmin = sp_dims.XMin
    ymin = sp_dims.YMin
    ymax = sp_dims.YMax

    dim_x = sp_dims.XLength


    int_incr = 1.0  

    tol1 = 0.01  

    # Create  lines to find intersection points:
    lines = []

    idx = 0
    xpos = xmin
    xpos_std_min = xmin + dim_x * fact1
    xpos_std_max = xmin + dim_x * fact2

    Part.show(base_spline.toShape(), "base_spline")

    line1 = Part.LineSegment(
        Vector(xpos_std_min, ymin - int_incr, 0),
        Vector(xpos_std_min, ymax + int_incr, 0))
  
    Part.show(line1.toShape(), "line1")

    pts1 = base_spline.intersect(line1, tol1)

    print(pts1, "points1")

    val1 = base_spline.parameter(Vector(pts1[0].X, pts1[0].Y, pts1[0].Z))
    val2 = base_spline.parameter(Vector(pts1[1].X, pts1[1].Y, pts1[1].Z))
    
    sect1 = base_spline.trim(val1, val2)
    Part.show(sect1.toShape(), "section1-2")
    
    line2 = Part.LineSegment(
        Vector(xpos_std_max, ymin - int_incr, 0),
        Vector(xpos_std_max, ymax + int_incr, 0))
  
    Part.show(line2.toShape(), "line2")

    pts2 =  base_spline.intersect(line2, tol1)

    print(pts2, "points2")

    val3 = base_spline.parameter(Vector(pts2[0].X, pts2[0].Y, pts2[0].Z))
    val4 = base_spline.parameter(Vector(pts2[1].X, pts2[1].Y, pts2[1].Z))
    
    sect2 = base_spline.trim(val3, val4)
    Part.show(sect2.toShape(), "section3-4")

    print(val1, val2, val3, val4)

    sect3 = base_spline.trim(val2, val3 + 1)
    Part.show(sect3.toShape(), "section2-3")

    sect4 = base_spline.trim(val4, val1)
    sect4.reverse()
    Part.show(sect4.toShape(), "section1-4")
    for i, val in enumerate([val1,val2,val3,val4]):
        Part.show(Part.Vertex(base_spline.value(val)), 'val'+str(i + 1))


build_guide_curves(bs0, 0.2, 0.9)

DOC.recompute()
EDIT corrected typos
Last edited by edwilliams16 on Sun Aug 14, 2022 9:43 pm, edited 1 time in total.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Sections of a BSPlineCurve

Post by onekk »

Thanks @edwilliams16, I will study tomorrow the code (now I'm on mobile).

Many thanks again.

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply