Difficulties with working with small distances
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Be nice to others! Read the FreeCAD code of conduct!
-
- Posts: 14
- Joined: Tue Nov 12, 2013 11:03 pm
Difficulties with working with small distances
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?
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?
Re: Difficulties with working with small distances
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.
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.
Re: Difficulties with working with small distances
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.
Re: Difficulties with working with small distances
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....
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!
Re: Difficulties with working with small distances
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.Draft rounds the points to the same number and creates a line where the start and the end point is the same (length 0)
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.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....
Re: Difficulties with working with small distances
Thanks for debugging! I'll already add something to prevent that from happening...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.
Re: Difficulties with working with small distances
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).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.
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
Re: Difficulties with working with small distances
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...
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!
-
- Posts: 14
- Joined: Tue Nov 12, 2013 11:03 pm
Re: Difficulties with working with small distances
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
>>> Part.Line(V[0],V[1])
<Line (2e-05,0,0) (2.1e-05,0,0) >
Many thanks!
Sam
Re: Difficulties with working with small distances
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
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.