Open TobyBorland opened 5 months ago
Seems the inline code has overflowed or I've used the wrong formatting, here's a link to the same code in my test repository.
https://github.com/TobyBorland/STEPaffine/blob/main/src/tests/UV_surface_issue.py
Another view,
Surface and control points showing unusual behaviour of closed B-spline surface evalpoints,
Present workaround is to generate a knotvector from supplied control points rather than using the knotvector generated within the FreeCAD OpenCASCADE kernel.
Evaluated evalpts surface point generation, evaluate() appears to use incomplete basis points set.
Describe the bug u,v, parametric values of a closed Bspline surface do not appear to correspond with the anticipated model geometry. This happens on a B-spline-with-knots surface exported by the FreeCAD STEP geometry engine, while other surfaces behave as anticipated. This surface is closed along one side.
S.evalpts[0] S..evaluate_single((0., 0.)) S.derivatives(0.0, 0.0, 0) do not return the same point.
I may have misunderstood some aspect to this library, please comment and reassign as appropriate.
To Reproduce `from geomdl import BSpline from geomdl import evaluators import numpy as np from geomdl import compatibility from geomdl import helpers
knotUvector = [0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0] knotVvector = [1.408501368196, 1.570796326795, 1.570796326795, 1.570796326795, 2.356194490192, 2.356194490192, 2.856730419592, 2.856730419592, 2.981864401942, 2.981864401942, 3.106998384292, 3.106998384292, 3.169565375467, 3.169565375467, 3.232132366642, 3.232132366642, 3.357266348992, 3.357266348992, 3.525162636266, 3.525162636266, 3.793796695902, 3.793796695902, 4.223611191322, 4.223611191322, 4.911314383992, 4.911314383992, 5.39291028181, 5.39291028181, 5.874506179628, 5.874506179628, 6.046294058204, 6.046294058204, 6.218081936781, 6.218081936781, 6.261028906425, 6.261028906425, 6.303975876069, 6.303975876069, 6.389869815357, 6.389869815357, 6.561657693933, 6.561657693933, 6.796162586065, 6.796162586065, 7.140594928107, 7.140594928107, 7.691686675375, 7.691686675375, 7.853981633974, 7.853981633974, 7.853981633974, 8.639379797371]
knotVvector = [kv - min(_knotVvector) for kv in _knotVvector]
controlPointsList = [[[5.00000000e-01, 4.89842542e-16, 1.94000000e+00], [0.5 , 0.34334628, 1.94], [0.47970362, 0.69078459, 1.94], [0.39544685, 1.25001608, 1.94], [0.35363397, 1.46634455, 1.94], [0.25173233, 1.73076161, 1.94], [0.22875243, 1.78300213, 1.94], [0.17014475, 1.88498053, 1.94], [0.14147652, 1.93836645, 1.94], [0.03817818, 1.9990141 , 1.94], [-0.02525655, 2.00311907, 1.94], [-0.09998333, 1.96538689, 1.94], [-0.12277512, 1.94064082, 1.94], [-0.18402992, 1.86740293, 1.94], [-0.21140698, 1.81577046, 1.94], [-0.26822354, 1.69431319, 1.94], [-0.29350409, 1.62318021, 1.94], [-0.35104497, 1.43583831, 1.94], [-0.37754281, 1.31929509, 1.94], [-0.43441625, 1.01719295, 1.94], [-0.45762795, 0.8298337 , 1.94], [-0.4990324 , 0.34106292, 1.94], [-0.50564302, 0.03948469, 1.94], [-0.48873301, -0.47279363, 1.94], [-0.4734661 , -0.68443663, 1.94], [-0.42093597, -1.10461872, 1.94], [-0.38541925, -1.31292279, 1.94], [-0.30373212, -1.59271487, 1.94], [-0.2789671 , -1.66608308, 1.94], [-0.21601647, -1.80952625, 1.94], [-0.18303939, -1.88172746, 1.94], [-0.098698 , -1.96187381, 1.94], [-0.07931412, -1.97794075, 1.94], [-0.02281914, -2.00114215, 1.94], [ 0.01938063, -2.00183212, 1.94], [ 0.10560777, -1.96848121, 1.94], [ 0.13224001, -1.93181438, 1.94], [ 0.20923139, -1.82931073, 1.94], [ 0.24071689, -1.75812759, 1.94], [ 0.30781136, -1.58676168, 1.94], [ 0.33673456, -1.48501092, 1.94], [ 0.39638483, -1.23617637, 1.94], [ 0.42187291, -1.08683116, 1.94], [ 0.4735693 , -0.69679181, 1.94], [ 0.49067666, -0.4547692 , 1.94], [ 0.49905809, -0.14204254, 1.94], [ 0.5 , -0.0709492, 1.94 ], [5.00000000e-01, 4.89842542e-16, 1.94000000e+00]], [ [5.00000000e-01, 4.89842542e-16, 1.95570796e+00], [0.5 , 0.34318685, 1.95570796], [0.47966684, 0.69102865, 1.95570796], [0.39547029, 1.24986054, 1.95570796], [0.35344318, 1.46683961, 1.95570796], [0.25178002, 1.73063785, 1.95570796], [0.22861271, 1.78324524, 1.95570796], [0.17028446, 1.88473742, 1.95570796], [0.14012147, 1.93916201, 1.95570796], [0.0388557 , 1.99861632, 1.95570796], [-0.02606528, 2.00271071, 1.95570796], [-0.0991746 , 1.96579525, 1.95570796], [-0.1229573 , 1.940423 , 1.95570796], [-0.18366557, 1.86783855, 1.95570796], [-0.21148693, 1.81559954, 1.95570796], [-0.26811626, 1.69454252, 1.95570796], [-0.29353978, 1.62306403, 1.95570796], [-0.35098788, 1.43602419, 1.95570796], [-0.37756172, 1.31919464, 1.95570796], [-0.43438599, 1.01735367, 1.95570796], [-0.45763656, 0.82973205, 1.95570796], [-0.49901862, 0.34122555, 1.95570796], [-0.50563829, 0.03934136, 1.95570796], [-0.48873633, -0.47269325, 1.95570796], [-0.47344945, -0.68456984, 1.95570796], [-0.42095262, -1.10448551, 1.95570796], [-0.38532937, -1.31323062, 1.95570796], [-0.30376417, -1.59260507, 1.95570796], [-0.27887457, -1.66629393, 1.95570796], [-0.216109 , -1.80931541, 1.95570796], [-0.18221003, -1.88251557, 1.95570796], [-0.09890534, -1.96167678, 1.95570796], [-0.07863915, -1.97821795, 1.95570796], [-0.02349411, -2.00086495, 1.95570796], [ 0.02008333, -2.00156033, 1.95570796], [ 0.10420237, -1.9690248 , 1.95570796], [ 0.13243341, -1.9315569 , 1.95570796], [ 0.20884459, -1.8298257 , 1.95570796], [ 0.24078512, -1.75795331, 1.95570796], [ 0.30771822, -1.58699958, 1.95570796], [ 0.336762 , -1.48489647, 1.95570796], [ 0.39634453, -1.23634447, 1.95570796], [ 0.42188595, -1.08673276, 1.95570796], [ 0.47354843, -0.69694924, 1.95570796], [ 0.49067972, -0.45465521, 1.95570796], [ 0.4990572 , -0.14207611, 1.95570796], [ 0.5 , -0.07091625, 1.95570796], [5.00000000e-01, 4.89842542e-16, 1.95570796e+00]], [ [4.86998832e-01, 4.89046476e-16, 1.98699883e+00], [0.48699883, 0.342868 , 1.98699883], [0.46673723, 0.68957982, 1.98699883], [0.38266109, 1.24761249, 1.98699883], [0.34093014, 1.46315448, 1.98699883], [0.23974395, 1.72571507, 1.98699883], [0.21706105, 1.77725323, 1.98699883], [0.15929167, 1.87777298, 1.98699883], [0.13082889, 1.92954148, 1.98699883], [0.03362825, 1.9866091 , 1.98699883], [-0.02182267, 1.9902884 , 1.98699883], [-0.09169706, 1.95500636, 1.98699883], [-0.11334884, 1.9316463 , 1.98699883], [-0.17296406, 1.86036874, 1.98699883], [-0.19987048, 1.80974882, 1.98699883], [-0.25612534, 1.68949231, 1.98699883], [-0.28118298, 1.61901445, 1.98699883], [-0.33844554, 1.43257872, 1.98699883], [-0.36482281, 1.31658841, 1.98699883], [-0.42154875, 1.01526977, 1.98699883], [-0.44469901, 0.82843134, 1.98699883], [-0.4860363 , 0.34045341, 1.98699883], [-0.49263473, 0.03948361, 1.98699883], [-0.47574886, -0.47206357, 1.98699883], [-0.4605154 , -0.68322344, 1.98699883], [-0.40808518, -1.10260628, 1.98699883], [-0.37266948, -1.31020261, 1.98699883], [-0.29134814, -1.5887418 , 1.98699883], [-0.26678432, -1.66149098, 1.98699883], [-0.20438887, -1.80366908, 1.98699883], [-0.17159547, -1.87466718, 1.98699883], [-0.09036418, -1.95185812, 1.98699883], [-0.07235017, -1.96674586, 1.98699883], [-0.01990501, -1.98828408, 1.98699883], [ 0.01679873, -1.98889098, 1.98699883], [ 0.09670157, -1.95798619, 1.98699883], [ 0.1224248 , -1.92323386, 1.98699883], [ 0.19767559, -1.82304756, 1.98699883], [ 0.22881526, -1.75286481, 1.98699883], [ 0.2954256 , -1.58273541, 1.98699883], [ 0.3241739 , -1.48163681, 1.98699883], [ 0.38362096, -1.23364992, 1.98699883], [ 0.40902358, -1.08482771, 1.98699883], [ 0.46061824, -0.69555585, 1.98699883], [ 0.47768933, -0.45407891, 1.98699883], [ 0.48605889, -0.14179493, 1.98699883], [ 0.48699883, -0.07085037, 1.98699883], [4.86998832e-01, 4.89046476e-16, 1.98699883e+00]], [ [4.55707963e-01, 4.87130526e-16, 2.00000000e+00], [0.45570796, 0.34144534, 2. ], [0.43546743, 0.68709594, 2. ], [0.35192856, 1.24156264, 2. ], [0.31002992, 1.45632001, 2. ], [0.2109719 , 1.71335835, 2. ], [0.18868458, 1.76383105, 2. ], [0.13340877, 1.86001193, 2. ], [0.1028943 , 1.90965694, 2. ], [0.0238317 , 1.95607551, 2. ], [-0.01493569, 1.95871229, 2. ], [-0.0703763 , 1.93071838, 2. ], [-0.09097223, 1.90962753, 2. ], [-0.1457104 , 1.84418108, 2. ], [-0.17224094, 1.79496496, 2. ], [-0.22682497, 1.67828019, 2. ], [-0.25158964, 1.60879053, 2. ], [-0.3080243 , 1.42505025, 2. ], [-0.33424087, 1.30990294, 2. ], [-0.39052806, 1.01091489, 2. ], [-0.41359665, 0.82488302, 2. ], [-0.45473415, 0.33926352, 2. ], [-0.46131868, 0.03923685, 2. ], [-0.4445046, -0.4701355, 2. ], [-0.42931762, -0.68053046, 2. ], [-0.37718462, -1.09753587, 2. ], [-0.3418306, -1.3041801, 2. ], [-0.26159733, -1.57899248, 2. ], [-0.23730552, -1.65079797, 2. ], [-0.17656149, -1.78921303, 2. ], [-0.14263981, -1.85901713, 2. ], [-0.07065974, -1.927417 , 2. ], [-0.05443979, -1.94027447, 2. ], [-0.01404107, -1.95686544, 2. ], [ 0.01178166, -1.95728162, 2. ], [ 0.0728724 , -1.93365296, 2. ], [ 0.09913126, -1.90214387, 2. ], [ 0.16920455, -1.80885073, 2. ], [ 0.20028696, -1.73990163, 2. ], [ 0.26545723, -1.57345033, 2. ], [ 0.29398994, -1.47332114, 2. ], [ 0.35283258, -1.22785565, 2. ], [ 0.37812037, -1.07983828, 2. ], [ 0.42941245, -0.69284936, 2. ], [ 0.44643695, -0.45222337, 2. ], [ 0.45477123, -0.14125616, 2. ], [ 0.45570796, -0.07055639, 2. ], [4.55707963e-01, 4.87130526e-16, 2.00000000e+00]], [ [4.40000000e-01, 4.86168722e-16, 2.00000000e+00], [0.44 , 0.34077118, 2. ], [0.41977928, 0.68578778, 2. ], [0.336495 , 1.23856467, 2. ], [0.29456594, 1.45276485, 2. ], [0.19651641, 1.70718636, 2. ], [0.1744747 , 1.75703212, 2. ], [0.12038053, 1.85115693, 2. ], [0.08921129, 1.89947525, 2. ], [0.01874379, 1.94084753, 2. ], [-0.01127545, 1.94296363, 2. ], [-0.0598763 , 1.91842336, 2. ], [-0.07969348, 1.89862881, 2. ], [-0.13212057, 1.83594557, 2. ], [-0.15835089, 1.78758639, 2. ], [-0.21214317, 1.67259416, 2. ], [-0.23672487, 1.6036873 , 2. ], [-0.29276722, 1.42122432, 2. ], [-0.31888405, 1.30657205, 2. ], [-0.37496332, 1.0086884 , 2. ], [-0.39798116, 0.82312728, 2. ], [-0.43902399, 0.33862537, 2. ], [-0.44559926, 0.03914896, 2. ], [-0.42881919, -0.4691928 , 2. ], [-0.41366057, -0.67914515, 2. ], [-0.36166841, -1.09502398, 2. ], [-0.32637208, -1.30107955, 2. ], [-0.24665442, -1.57412589, 2. ], [-0.22253043, -1.64537717, 2. ], [-0.16256897, -1.78200904, 2. ], [-0.12831229, -1.85096302, 2. ], [-0.0607161 , -1.91519705, 2. ], [-0.04561823, -1.9269163 , 2. ], [-0.01092797, -1.94116291, 2. ], [ 0.00908672, -1.941482 , 2. ], [ 0.06126296, -1.92130129, 2. ], [ 0.0873894 , -1.89162136, 2. ], [ 0.15500922, -1.80159469, 2. ], [ 0.18594868, -1.73343788, 2. ], [ 0.25043654, -1.56872952, 2. ], [ 0.27883076, -1.46917541, 2. ], [ 0.33738697, -1.22490475, 2. ], [ 0.36260374, -1.07735828, 2. ], [ 0.41375243, -0.69145119, 2. ], [ 0.43074754, -0.4513205 , 2. ], [ 0.4390651 , -0.14097727, 2. ], [ 0.44 , -0.07041708, 2. ], [4.40000000e-01, 4.86168722e-16, 2.00000000e+00]]]
BsplineKnotSurface = BSpline.Surface()
BsplineKnotSurface = BSpline.Surface(normalize_kv=False)
BsplineKnotSurface.degree_u = 3 BsplineKnotSurface.degree_v = 3 BsplineKnotSurface.ctrlpts_size_u = len(controlPointsList) BsplineKnotSurface.ctrlpts_size_v = len(controlPointsList[0]) BsplineKnotSurface.ctrlpts2d = controlPointsList BsplineKnotSurface.knotvector_u = knotUvector BsplineKnotSurface.knotvector_v = knotVvector
BsplineKnotSurface.evaluator = evaluators.SurfaceEvaluator2()
Set evaluation delta
deltaFactor = 4 BsplineKnotSurface.delta_u = 1/(BsplineKnotSurface.ctrlpts_size_u deltaFactor) BsplineKnotSurface.delta_v = 1/(BsplineKnotSurface.ctrlpts_size_v deltaFactor)
BsplineKnotSurface.delta = 0.025
Evaluate surface points
BsplineKnotSurface.evaluate()
test_A = BsplineKnotSurface.evalpts[0] test_B = BsplineKnotSurface.evaluate_single((0., 0.)) test_C = BsplineKnotSurface.derivatives(0.0, 0.0, 0)
if np.allclose(test_A, test_B) and np.allclose(test_A, test_C[0][0]) and np.allclose(test_B, test_C[0][0]): print("PASS") else: print("FAIL")
pass`
Expected Behavior It is anticipated that the surface point calculated from a (0.0, 0.0) u,v parametric description is at the corresponding zero corner of the model. While the point generated within evalpts[0] corresponds to this corner, a similar search using
Configuration:
Screenshots (Optional) (Green dot is anticipated position, red dot is calculated zero-derivative position)
Additional Details (Optional) Add any other context about the problem here.