Difficulties with working with small distances

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
SamMallinson
Posts: 14
Joined: Tue Nov 12, 2013 11:03 pm

Difficulties with working with small distances

Post by SamMallinson »

I have been trying to create some geometry with small distances between points which define the geometry. Unfortunately, there seems to be some limitation / difficulty when working with small distances in FreeCAD. BTW, I am using v0.14.

For example, when I try to create a Line using Part.Line:

>>> from FreeCAD import Vector
>>> V=[Vector(20e-6,0,0),Vector(21e-6,0,0)]
>>> import Part
>>> Part.Line(V[0],V[1])
Traceback (most recent call last):
File "<input>", line 1, in <module>
Exception: Both points are equal

But, I can create an edge object (as opposed to the Line object returned by Part.Line) using

>>> Part.makeLine(V[0],V[1])
<Edge object at 0B3FB6D0>

I can also create a Document object using

>>> Draft.makeLine(V[0],V[1])
<Document object>

However, when I try to access various properties by using the Shape method, for example

>>> Draft.makeLine(V[0],V[1]).Shape.Length
0.0

That is not 1.0e-6, which is the right value. Note that Part.makeLine seems to be OK.

>>> Part.makeLine(V[0],V[1]).Length
9.999999999999972e-07

I have found several references to Preference::Confusion (part of the OpenCascade header Precision.hxx) in the file src/Mod/Part/App/Geometry.cpp - in particular, in the function void GeomLineSegment::setPoints, which compares the distance between two points, p1 and p2 with the return from Preference::Confusion

if (p1.Distance(p2) < Preference::Confusion()) Standard_Failure::Raise("Both points are equal");

Is it best to use Part.makeLine, given that it does not suffer from errors like Part.Line and Draft.makeLine?
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Difficulties with working with small distances

Post by wmayer »

Thanks for pointing this out. It's often not clear which tolerance to use because the cad kernel offers quite a lot predefined values. So, at least the inconsistency between Part.Line and Part.makeLine is fixed.

The draft stuff is a bit more complicated because it uses its own internal tolerance. In your case the shape is invalid and thus the Length attribute returns 0. So, maybe we should raise an exception here.
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Difficulties with working with small distances

Post by yorik »

Yes indeed the draft module uses a precision value settable in the preferences, which rounds your input values. I'm not sure why the draft line creation succeeds but creates an invalid shape, I'll investigate... Maybe actually I should drop that draft precision value and use the global one of freecad.
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Difficulties with working with small distances

Post by jriegel »

Draft rounds the points to the same number and creates a line where the start and the end point is the same (length 0) :)

Catia uses a global accuracy of 0.001 mm. But this makes it impossible to design on nm level. But not quit sure why you need to design that small....
Stop whining - start coding!
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Difficulties with working with small distances

Post by wmayer »

Draft rounds the points to the same number and creates a line where the start and the end point is the same (length 0)
When debugging through the code the Draft.makeLine() passes and empty list to Part.Wire() which raises an exception because it fails to create a shape. But Daft.makeLine() ignores the exception and leave the shape invalid.
Catia uses a global accuracy of 0.001 mm. But this makes it impossible to design on nm level. But not quit sure why you need to design that small....
OpenCascade uses a accuracy of 1e-7. But I guess for real stuff this is OK because here we are already in the dimension of the wave lengths of light.
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Difficulties with working with small distances

Post by yorik »

When debugging through the code the Draft.makeLine() passes and empty list to Part.Wire() which raises an exception because it fails to create a shape. But Daft.makeLine() ignores the exception and leave the shape invalid.
Thanks for debugging! I'll already add something to prevent that from happening...
ediloren
Posts: 210
Joined: Wed May 08, 2013 9:23 pm
Location: Italy
Contact:

Re: Difficulties with working with small distances

Post by ediloren »

OpenCascade uses a accuracy of 1e-7. But I guess for real stuff this is OK because here we are already in the dimension of the wave lengths of light.
Well this is useful to know in perspective, since my application will deal also with nanometric structures (today our E.M. software at FastFieldSolvers deals with structures with dimensions from meters to nanometers according to the application, e.g. electrical links to quantum computing).

Most of the users are naively not scaling the models even when possible. I will have to keep it in mind if nothing can be done against the OpenCascade accuracy of 1e-7. Of course other ideas are welcome.

Ciao
Enrico
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Difficulties with working with small distances

Post by jriegel »

Hi Enrico,
we have to admit that CAD systems has a range where they work properly. If you leave that range you will get lots of trouble! So I think the most practical is to design your stuff with an factor. Your simulation software can undo the factor on the geometry...
Stop whining - start coding!
SamMallinson
Posts: 14
Joined: Tue Nov 12, 2013 11:03 pm

Re: Difficulties with working with small distances

Post by SamMallinson »

I see that a new commit was made a short while ago to the git repository. I have updated my local copy of the repository and recompiled. I can confirm that the change has fixed the problem I mentioned:

>>> Part.Line(V[0],V[1])
<Line (2e-05,0,0) (2.1e-05,0,0) >

Many thanks!

Sam
novis
Posts: 8
Joined: Sun Dec 08, 2013 9:09 pm

Re: Difficulties with working with small distances

Post by novis »

I need some help. Being new to FreeCad I want to make sure I can draw objects with sizes in the range of 0,001mm. Have tried to find out the number of decimal points there are to the given mm setting. I find only two. But need three. Cannot find anywhere that can confirm that such dimensions can be drawn and given their dimensions to the 0,001 mm accuracy. Thank you for your help.
Enrico - Please let me know how scaling is done as you mention it is possible. I have searched the Help and do not find any hints how to do that. Scale 1000:1 would probably do the job. Thanks
Last edited by novis on Thu Dec 19, 2013 2:28 am, edited 1 time in total.
Post Reply