View Issue Details

IDProjectCategoryView StatusLast Update
0004416DraftBugpublic2020-11-11 02:41
Reporterjeb6kids Assigned Tochrisb  
PrioritynormalSeverityblockReproducibilityalways
Status closedResolutionfixed 
PlatformDell VostroOSMicrosoft Windows 10 ProOS VersionVersion 10.0.183
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\todo.py", line 167, in doTasks
    Gui.doCommand(string)
  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\make_sketch.py", 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\geometry.py", 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\geometry.py", 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\geometry.py", line 215, in getSplineNormal
    n.normalize()
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) ))
    n.normalize()
    return n

This is what was printed out on the Report view:

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

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)

Activities

jeb6kids

2020-08-03 19:05

reporter  

mickeymouse6.FCStd (90,851 bytes)

mikeprice99

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 importSVG.py ensures a vector transformation is always applied, even if it does nothing useful.

Kunda1

2020-10-10 14:06

administrator   ~0014821

@chrisb is this related to https://forum.freecadweb.org/viewtopic.php?f=3&t=51004 ?

vocx

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.

chennes

2020-11-10 16:52

administrator   ~0014971

Was this fixed by PR https://github.com/FreeCAD/FreeCAD/pull/3954 ?

Kunda1

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

marioalexis


Committer: yorik Details Diff
Improve make_sketch and geometric related functions Affected Issues
0004416
mod - src/Mod/Draft/DraftGeomUtils.py Diff File
mod - src/Mod/Draft/draftgeoutils/edges.py Diff File
mod - src/Mod/Draft/draftgeoutils/geometry.py Diff File
mod - src/Mod/Draft/draftgeoutils/offsets.py Diff File
mod - src/Mod/Draft/draftgeoutils/wires.py Diff File
mod - src/Mod/Draft/draftguitools/gui_draft2sketch.py Diff File
mod - src/Mod/Draft/draftmake/make_sketch.py Diff File
mod - src/Mod/Draft/draftobjects/patharray.py 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