ForCAD - A Fortran library for geometric modeling

I am currently on vacation, so for simplicity, I will explain with a curve example:

How to Describe a Curve?

To describe a curve in physical space, you discretize your parametric space, which ranges from 0 to 1. These points are saved in X_{t}. Then you map these points X_{t} to physical space, and you can visualize your curve in physical space with coordinates X_{g}. (For simplicity, I didn’t draw the control points X_{c}.)

If the resolution is low (i.e., the number of discrete points in parametric space X_{t} is small), your curve will have a low resolution and appear as a set of lines. If you increase the resolution (i.e., increase the number of discrete points in parametric space \hat{X}_{t}), you can draw your curve with more points, resulting in a better resolution \hat{X}_{g}.

(Both curves X_{g} and \hat{X}_{g} are the same but drawn with different resolutions.)

The Idea Behind nearest_point():

Now, let’s say you have a point P and you want to find the closest point on the curve. The nearest_point() function compares the coordinates of point P with the coordinates of X_{gi} and finds the closest point on the curve. If your resolution is low, the accuracy of finding the closest point is reduced. If you increase the resolution, the accuracy will improve.

To call the function:

call curve%nearest_point(P, nearest_Xg, nearest_Xt, id)

Here, you provide the coordinates of point P. Depending on the resolution of your curve, the nearest_point() subroutine finds the nearest X_{gi} on the curve and gives the corresponding parametric coordinates X_{ti} and the id of this point (i). For instance, in this example, for the finest curve, the id of the closest point on the curve is 2.

This is an approximated solution that depends on the discretization. It is also possible to find the exact point, but this feature is not yet implemented in ForCAD.

Hi @Ali ,

thank you for your time dedicated to that explanation, I got that…

I don’t agree with some things you wrote, i.e. “If the resolution is low (i.e., the number of discrete points in parametric space Xt is small, your curve will have a low resolution and appear as a set of lines”.
The point is to interpolate those points with for example a cubic spline!

Anyway for simplicity let’s say you have interpolated those given points with a cubic spline or a NURBS, so that now we can even forget about them…

I don’t see the point using Xg to find the closest point…you use Xgi only to find the NURBS representation…

By the way, I’m just saying that a realistic/engineering use case would need to find the closest point based on the NURBS description of the surface, thereby giving the closest point with an arbitrary accuracy!
Have a look at those functions in the SISL library…it is a really good library built over the years by experts…

Have a great day

Please take a look at the NURBS description in The NURBS Book or Wikipedia:
grafik

In ForCAD, X_{gi}(X_{ti}) is C(u), u is X_{ti}, and X_c are P (As I mentioned, I didn’t draw control points in the last figure). The NURBS Basis function in ForCAD is T_{gc} instead of R:

X_{gi}(X_{ti}) = T_{gc}(X_{ti}) \cdot X_c

If you evaluate your curve only with three points, you get three points on the curve, as shown in the last picture. If you evaluate the curve with more points, you get a better resolution. Could you tell me which parts you don’t agree with?

You don’t have to evaluate the curve with three points, once you have the NURBS description of a curve, you can use an (almost) arbitrary precision to evaluate the curve/surface…

Did I mention that? No! :wink: You don’t have to evaluate a curve with three points. That was just an example that I could easily draw on paper to show that the number of evaluation points determines the visualized resolution of the curve.

The precision you refer to is related to the distances between the evaluation points. This means you can specify either the number of points or the distance between each point as a measure of precision. Both approaches can achieve the same result.

v0.6.0 is released with some new features:

  • Added ansatz() procedures to compute shape functions, derivatives of shape functions and (dV, dA and dL). These can be used for IGA.
  • Added nearest_point2() to compute the nearest point on a NURBS object using optimization (Newton Method).
  • Added a generic method derivative2() to compute the second derivative of NURBS objects.
  • Added cmp_elemFace*() to extract element connectivity of faces.
  • Added cmp_degreeFace() to extract the degrees of faces.
  • Added cmp_length() to compute the length of a NURBS curve.
  • Added cmp_area() to compute the area of a NURBS surface.
  • Added cmp_volume() to compute the volume of a NURBS volume.
    • The gauss_legendre() subroutine from stdlib is used for integration.

Full Changelog: CHANGELOG.md

I am considering adding a new GUI to visualize and modify NURBS objects. Would OpenGL be a good choice for this purpose? If you have any suggestions, please let me know.

3 Likes

Amazing!

I wanted to ask a question. How do you handle errors or failable operations?

For example: In OpenCASCADE (C++ codebase), even simple operations such as chamfer, fillet, etc. would crash the code. Over the last few years, they’ve worked hard to use C++ exceptions, and handle those errors.

Since Fortran lacks a dedicated error handling system, it can become difficult.

Thanks! Yes, it is difficult! For now, I use error stop as I mainly use pure procedures. You can see an example here: forcad/src/forcad_nurbs_volume.f90 at f59ff9c058df9c68da298fa83e42bd123df35f4d · gha3mi/forcad · GitHub.

In a next version, I plan to remove error stop and add an optional integer variable for status or implement a check_status() method. Are there any other smart solutions?