View Issue Details

IDProjectCategoryView StatusLast Update
0004416DraftBugpublic2020-11-11 02:41
Reporterjeb6kids Assigned Tochrisb  
Status closedResolutionfixed 
PlatformDell VostroOSMicrosoft Windows 10 ProOS VersionVersion 10.0.183
Product Version0.19 
Summary0004416: "Cannot normalize null vector" in Draft2Sketch
DescriptionI used Inkscape to create a set of paths to import into FreeCAD.
Upon importing the resulting .svg file, 15 path* Draft objects appeared under my Body. One by one I used the "Convert bidirectionally between Draft objects and Sketches" tool on the Draft workbench to create sketches that appeared also under my Body.

However, when converting one draft object, python threw a red stack trace to the report view:

13:18:15 Traceback (most recent call last):
  File "C:\Users\Master\Downloads\FreeCAD\FreeCAD_0.19.22164-Win-Conda_vc14.x-x86_64\Mod\Draft\draftutils\", line 167, in doTasks
  File "<string>", line 1, in <module>
  File "C:\Users\Master\Downloads\FreeCAD\FreeCAD_0.19.22164-Win-Conda_vc14.x-x86_64\Mod\Draft\draftmake\", line 93, in make_sketch
    if not DraftGeomUtils.isPlanar(shape):
  File "C:\Users\Master\Downloads\FreeCAD\FreeCAD_0.19.22164-Win-Conda_vc14.x-x86_64\Mod\Draft\draftgeoutils\", line 286, in isPlanar
    n = getNormal(shape)
  File "C:\Users\Master\Downloads\FreeCAD\FreeCAD_0.19.22164-Win-Conda_vc14.x-x86_64\Mod\Draft\draftgeoutils\", line 249, in getNormal
    n = getSplineNormal(e)
  File "C:\Users\Master\Downloads\FreeCAD\FreeCAD_0.19.22164-Win-Conda_vc14.x-x86_64\Mod\Draft\draftgeoutils\", line 215, in getSplineNormal
Base.FreeCADError: Cannot normalize null vector

I found the "getSplineNormal() function def and added a few debug statements:

def getSplineNormal(edge):
    """Find the normal of a BSpline edge."""
    print( "edge=[{}]\n".format( str(edge) ))
    startPoint = edge.valueAt(edge.FirstParameter)
    endPoint = edge.valueAt(edge.LastParameter)
    print( "startPoint=[{}]\n".format( str(startPoint) ))
    print( "endPoint=[{}]\n".format( str(endPoint) ))
    midParameter = (edge.FirstParameter
                    + (edge.LastParameter - edge.FirstParameter) / 2)
    midPoint = edge.valueAt(midParameter)
    print( "midPoint=[{}]\n".format( str(midPoint) ))
    v1 = midPoint - startPoint
    v2 = midPoint - endPoint
    print( "v1=[{}] v2=[{}]\n".format( str(v1), str(v2) ))
    n = v1.cross(v2)
    print( "n=[{}]\n".format( str(n) ))
    return n

This is what was printed out on the Report view:

13:18:15 edge=[<Edge object at 000002265C28A220>]
13:18:15 startPoint=[Vector (-2581.953, -2921.6615, 0.0)]
13:18:15 endPoint=[Vector (-2581.953, -2918.0896000000002, 0.0)]
13:18:15 midPoint=[Vector (-2581.953, -2919.87555, 0.0)]
13:18:15 v1=[Vector (0.0, 1.785949999999957, 0.0)] v2=[Vector (0.0, -1.785949999999957, 0.0)]
13:18:15 n=[Vector (0.0, 0.0, -0.0)]

So it appears that my draft object was a legitimate object, but just happened to contain a bspline that was exactly vertical (having no arc, i.e. a line segment).
Steps To ReproduceOpen attached *.FCStd file in FreeCAD 0.19
Navigate to the Draft workbench
Select path864
Press the "Convert bidirectionally between Draft objects and Sketches" tool
Tagsimport, SVG
FreeCAD InformationOS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22164 (Git)
Build type: Release
Branch: master
Hash: f2a9f712e8d68ee2393d0fe748c02096c4148a32
Python version: 3.8.5
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United States (en_US)



2020-08-03 19:05


mickeymouse6.FCStd (90,851 bytes)


2020-08-05 08:49

reporter   ~0014701

I'd just like to confirm that I've found the same problem.

I addition I've discovered that when importing SVGs all the elements are correctly converted, but after the import of elements they are all then converted to BSplines when a Vector transformation is applied. A quirk in ensures a vector transformation is always applied, even if it does nothing useful.


2020-10-10 14:06

administrator   ~0014821

@chrisb is this related to ?


2020-10-10 22:27

reporter   ~0014831

I have mentioned this problem in this thread, Improvements in SVG.

The problem was first reported in Regression in Draft To Sketch, with reference to particular commits that broke the behavior.

The problem is that when importing edges from an SVG file, the importer creates Edges that are of curve type "BSplineCurve". This is done even for straight edges that could be of type "Line" instead.

The code cannot compute a normal vector for these BSplines (actually straight lines), and thus produces an error when trying to normalize the null vector (0,0,0).

In this thread, SVG cannot be converted to a sketch, Chris_G mentions that the normal calculation for closed edges doesn't work either. So a different way to calculate the normal should be used. This is a separate problem; the issue with the "straight BSplines" should still be addressed.


2020-11-10 16:52

reporter   ~0014971

Was this fixed by PR ?


2020-11-11 02:41

administrator   ~0014972

@chrisb, JFYI, I'm trying to associate the commits with tickets before I close tickets. It seems like a good way to easily understand how bugs have been fixed.

FreeCAD master aa88f3de

Related Changesets

FreeCAD: master aa88f3de

2020-10-10 02:13:46


Committer: yorik Details Diff
Improve make_sketch and geometric related functions Affected Issues
mod - src/Mod/Draft/ Diff File
mod - src/Mod/Draft/draftgeoutils/ Diff File
mod - src/Mod/Draft/draftgeoutils/ Diff File
mod - src/Mod/Draft/draftgeoutils/ Diff File
mod - src/Mod/Draft/draftgeoutils/ Diff File
mod - src/Mod/Draft/draftguitools/ Diff File
mod - src/Mod/Draft/draftmake/ Diff File
mod - src/Mod/Draft/draftobjects/ Diff File

Issue History

Date Modified Username Field Change
2020-08-03 19:05 jeb6kids New Issue
2020-08-03 19:05 jeb6kids File Added: mickeymouse6.FCStd
2020-08-05 08:49 mikeprice99 Note Added: 0014701
2020-10-10 14:05 Kunda1 Tag Attached: SVG
2020-10-10 14:06 Kunda1 Note Added: 0014821
2020-10-10 22:27 vocx Note Added: 0014831
2020-10-22 11:21 Kunda1 Tag Attached: import
2020-11-10 16:52 chennes Note Added: 0014971
2020-11-11 00:01 chrisb Assigned To => chrisb
2020-11-11 00:01 chrisb Status new => closed
2020-11-11 00:01 chrisb Resolution open => fixed
2020-11-11 02:41 Kunda1 Note Added: 0014972
2020-11-11 02:41 Kunda1 Changeset attached => FreeCAD master aa88f3de