trelau / AFEM

Airframe Finite Element Modeler
GNU Lesser General Public License v2.1
40 stars 16 forks source link

Can AFEM be used as a general purpose CAD Library? #7

Closed mnesarco closed 3 years ago

mnesarco commented 4 years ago

I have just discovered this project, I have been exploring the documentation and it looks like a great library to use as a base for my little CAD project. Apparently this is designed specifically for Airplane designs but it looks very generic to me. Is there any serious limitation in using this instead of using pyOOCT directly?

My project consist of generating parts from some input parameters, I need a lot of 2D geometry to construct profiles and then build 3D objects doing lofting, extruding, and boolean operations.

Congrats for such a great work. Thanks in advance.

trelau commented 3 years ago

hi @mnesarco. i wouldn't say there are serious limitations. in large part, the project is just a bit more "pythonic" wrapper of some pyOCCT functionality. really only the afem.structures module is related to airplanes, everything else is pretty generic as you said. the only downside might be that if you find that something isn't available via afem, we might have to first add it to afem, or you otherwise use the raw pyOCCT interface in combination with afem. so, it might depend on how much functionality you may need beyond what is available. although, as a open source project, contributions are welcome 😄

mnesarco commented 3 years ago

Thank you @trelau , Sounds pretty good to me. I will start my POC with AFEM. If I can resort to pyOCCT when needed I see no major risks.

I will need a lot of work with edges (intersections, projections, extensions, tangents, etc...) any tips about where to find examples/docs aboud 2D Geometry in AFEM will be highly appreciated.

mnesarco commented 3 years ago

Hi @trelau , I am sorry if here is not the place to ask trivial questions, please point me to the right place if necessary.

I need a very simple operation that I use a lot, sometimes it is called lerp: I have defined a NURBS line between two points (p1, p2), now I want to get a point (p) on the curve by distance (d) from p1, but d could be any number so the resulting point p can be on the segment itself between p1 and p2 or outside the segment but on the infinite curve defining the actual segment.

image

I have not found any operation with a name suggesting this kind of operation in afem docs. Any tip will be highly appreciated.

Thank you.

mnesarco commented 3 years ago

I think I have found a solution:

from OCCT.GCPnts import GCPnts_AbscissaPoint

curve = ...
d = ...

adp = EdgeAdaptorCurve.by_edge(EdgeByCurve(curve).edge)
par = GCPnts_AbscissaPoint(adp.object, d, 0.).Parameter()

p = curve.eval(par)
mnesarco commented 3 years ago

Wow, this is embarrassing, the solution is so simple:

p = curve.eval( d )

trelau commented 3 years ago

If you just have two points, you can use LineByPoints and then get the line using the .line property. Then, line.eval(d) can be used like above. Note that since you are just using two points to form a line (or even a NURBS curve), evaluating the curve using the distance as the parameter just happens to give you a point along the curve at that distance since that the curve was parameterized between two points only. If you interpolated a number of points, that will not always be the case. If you are just creating a line between two points though, it should work just fine. Shall we close this issue?

mnesarco commented 3 years ago

@trelau Ok, the most common case is just two points (line segment), but in some cases i need to work with the continuation of a curve. Does the GCPnts_AbscissaPoint do the trick in that case?

trelau commented 3 years ago

What do you mean by "continuation"? If you mean extrapolate from a line, then just inputting the parameter like above will work. A Line is actually an infinite curve. If you need points along a curve at a specified distance, then this tool might be useful PointsAlongCurveByDistance.

trelau commented 3 years ago

And this tool essentially wraps the OCCT method you mentioned PointFromParameter

mnesarco commented 3 years ago

Thank you, PointFromParameter looks like what i need.

What i mean by "continuation" is:

image

Where the infinite line after P3 is tangent to curve at P3

trelau commented 3 years ago

i see. i'm not sure the tool works that way out of the box, but you could write your own function to achieve that behavior. If the parameter is outside the curve, evaluate the end point and curve tangent, and then translate that point in that direction the desired distance. Or some variation of that.

mnesarco commented 3 years ago

Yes PointFromParameter only works with internal points, so I have to manage two cases separately. Anyway I am getting more and more comfortable with your lib, great work. I suppose this Issue can be closed now. Do you have a forum for this kind of questions? I feel bad asking trivial things here because usage questions are not issues with the library.

trelau commented 3 years ago

No forum. There is a gitter chat room but no one is in it. Maybe a google group would work, but not sure if there is demand yet. For now, issues are ok if you'd like to use them, I think.