Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Curve Curvature" node outputs wrong values for FreeCAD curves #3804

Closed
rendetto opened this issue Dec 31, 2020 · 10 comments
Closed

"Curve Curvature" node outputs wrong values for FreeCAD curves #3804

rendetto opened this issue Dec 31, 2020 · 10 comments
Assignees
Labels

Comments

@rendetto
Copy link
Contributor

rendetto commented Dec 31, 2020

I created a simple test case using 1m arc (converted to NURBS).
Curvature node outputs 1.0 when Native and Geomdl are used, but when FreeCAD is used the values are not 1.0.

FreeCAD_NURBS_Curve_WrongCurvature

Here's the test file I'm using:
FreeCAD_NURBS_Curve_WrongCurvature.zip

@rendetto
Copy link
Contributor Author

rendetto commented Jan 28, 2021

I did a test to visualize the arc center point and it's not where it is supposed to be:
FreeCAD_NURBS_Curve_Center
Also the calculated arc Radius seem to oscillate around 1.0.

@portnov
Copy link
Collaborator

portnov commented Jan 28, 2021

Other implementations give correct result?

@rendetto
Copy link
Contributor Author

Yes, others are fine. Just FreeCAD is doing this and only for curves.
FreeCAD surfaces don't have such problems.

@portnov portnov added the NURBS label Jan 28, 2021
@portnov
Copy link
Collaborator

portnov commented Jan 28, 2021

I see. FreeCAD's Nurbs API does not have explicit methods for 2nd derivative; so the curvature is evaluated numerically, hence there is precision loss. I can try to add some kind of "precision" parameter to the node, so the user could somehow try to control this loss of precision...

@rendetto
Copy link
Contributor Author

rendetto commented Jan 28, 2021

Sounds great! I'm surprised that FreeCAD lacks such basic feature. I just found that OCC has it and even 3rd derivative:
https://dev.opencascade.org/doc/refman/html/class_geom_adaptor___curve.html#ab233e6b1967c5da228701cac6400d88d

Did you ever considered implementing PythonOCC? I know it's a huge thing but it's the whole OCC.

@rendetto
Copy link
Contributor Author

rendetto commented Jan 28, 2021

I just found curvatureAt() and centerOfCurvatureAt() methods at this page (scroll to the bottom):

https://wiki.freecadweb.org/TopoShape_API

Could those two be of any use?

@portnov
Copy link
Collaborator

portnov commented Jan 29, 2021

Hm, I'll look into it.

@rendetto
Copy link
Contributor Author

rendetto commented Jan 29, 2021

Your idea about adding a "precision" parameter on the existing algorithm looks really promising.
Because even if those FreeCAD methods solve the curvature, radius and center problems, there's also a torsion problem.
Torsion from FreeCAD curve gets also precision loss, and I didn't found such method on the FreeCAD API.

I'm not much into math so I don't know if some hybrid approach will be possible, e.g. deriving torsion from curvatureAt() somehow.
Maybe an option in "Curve Curvature" node for switching between Native and FreeCAD method will be an optimal solution?

Thanks

@rendetto
Copy link
Contributor Author

rendetto commented Jul 21, 2021

@portnov I tested adding the curvatureAt() method to ...utils/curve/freecad.py and the node now outputs correct results.
Fix_FreeCAD_NURBS_Curve_WrongCurvature
I simply replicated the tangents code, but I'm sure that I messed the things up. Please can you take a look at it.
freecad.zip

While we can use curvatureAt() for the curvature/radius and center, there is still the problem with the torsion node and FreeCAD does not have an explicit API for it. So can you please consider implementing your first idea - adding a precision parameter to the original implementation of second and third derivatives?

Thanks

@portnov
Copy link
Collaborator

portnov commented Aug 17, 2021

It appears that the problem was that I used tangent method of FreeCad's curves, while thinking that it returns the derivative of the curve; while it returns the normalized derivative vector. For non-normalized derivative, FreeCad has getD1 method.

portnov added a commit that referenced this issue Aug 17, 2021
introduce explicit tangent_delta parameter.

Add "tangent_delta" to "curve curvature" node.

refs #3804
@portnov portnov closed this as completed Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants