Edge midpoint fix

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
tpavlicek
Posts: 60
Joined: Sun Jan 07, 2018 2:15 am

Edge midpoint fix

Post by tpavlicek »

Hello,

I have noticed that if "Edge midpoint" cosmetic vertex is added to an edge constituted by a Bezier curve, it is not placed in the half way between endpoints, but slightly off. Thus I have created Pull Request #4878 to fix this behavior. For better idea, here's the illustrating picture:
MidPoint.png
MidPoint.png (17.51 KiB) Viewed 2498 times
CurrentMidPoint = how the midpoint is currently added
FixedMidPoint = how the midpoint is placed according to my pull request

In case of any comments, issues or suggestions, please let me know.

Kind regards,

Tomas
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Edge midpoint fix

Post by openBrain »

Hmmm. Your solution seems to me worse than the original one... :? What is the criteria decide the center of the spline ?
tpavlicek
Posts: 60
Joined: Sun Jan 07, 2018 2:15 am

Re: Edge midpoint fix

Post by tpavlicek »

Hi,

in my pull request the midpoint criterium is the actual path length. The lengths of the trajectories from the midpoint to the endpoints are the same, thus midpoint is really "halving" the curve.

The current solution basically takes the average of curve endpoint parameters to compute the midpoint. This works well for curves of constant velocity (lines, arcs of circles), however gives wrong results for Bezier curves, arcs of ellipses etc. where the velocity changes along the path.

This is not much about esthetics, but rather about midpoint definition.

Kind regards,

Tomas
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Edge midpoint fix

Post by openBrain »

tpavlicek wrote: Mon Jun 21, 2021 3:05 pm in my pull request the midpoint criterium is the actual path length. The lengths of the trajectories from the midpoint to the endpoints are the same, thus midpoint is really "halving" the curve.
Do you mean you take the mid-path length of the 3D representation ? Or of the 2D representation ?
tpavlicek
Posts: 60
Joined: Sun Jan 07, 2018 2:15 am

Re: Edge midpoint fix

Post by tpavlicek »

openBrain wrote: Mon Jun 21, 2021 3:21 pm Do you mean you take the mid-path length of the 3D representation ? Or of the 2D representation ?
The edge 2D projection - the very same curve which is used to compute the midpoint now.

Tomas
user1234
Veteran
Posts: 3345
Joined: Mon Jul 11, 2016 5:08 pm

Re: Edge midpoint fix

Post by user1234 »

A good fix! When i saw the screenshot with the correct one, i looks also a little bit false. But i measure it with the caliper on the screen and it seems correct to me.

Greetings
user1234
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Edge midpoint fix

Post by uwestoehr »

I was asked to review your PR and since I don't have the time right now to compile, I can at least say, the code looks good and reasonable.
However, and this is what I always say ;) : Add comments!
Others should get what you are doing and why also years later. So please add comments why you use GCPnts_AbscissaPoint::Length. You can also refer in the comment to this thread.

Concerning the concerns here in previous posts, you could make a screenshot with arcs, then it should become more clear what the problem is.
tpavlicek
Posts: 60
Joined: Sun Jan 07, 2018 2:15 am

Re: Edge midpoint fix

Post by tpavlicek »

Hello,
uwestoehr wrote: Wed Jun 23, 2021 1:41 pm Add comments!
Sure, understood. I have added a new commit with a few comments to describe what's going on.

uwestoehr wrote: Wed Jun 23, 2021 1:41 pm Concerning the concerns here in previous posts, you could make a screenshot with arcs, then it should become more clear what the problem is.
Ok, here is another example. Arc of ellipse, longer axis is horizontal, shorter axis vertical, simple 1st quadrant arc. "ParameterAverageMidpoint" shows where the midpoint is added now, "HalvedLengthMidpoint" shows the proposed fix:

MidPoint2.png
MidPoint2.png (30.72 KiB) Viewed 2260 times

The arc length is 105.05mm (could be verified using online ellipse circumference calculators), thus the midpoint should be placed 52,525mm from both start and end points when tracing the arc. While the current implementation is clearly off, the dimensions in the proposed fix indicate correct placement.

Kind regards,

Tomas
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Edge midpoint fix

Post by uwestoehr »

Many thanks for your improved PR. I approved it.

Yes, the PR fixes the bug correctly. Here an example from me:
- the midpoint close to the center of the spline is the one with the PR, the one more to the right is the one without the PR.
FreeCAD_wnG0B6oVjd.png
FreeCAD_wnG0B6oVjd.png (8.39 KiB) Viewed 2204 times

@tpavlicek, while you are at coding midpoints, could you perhaps a look why the addition of midpoints cannot be undone like every other FreeCAD feature?
domad
Veteran
Posts: 2053
Joined: Mon Jun 22, 2020 12:16 pm

Re: Edge midpoint fix

Post by domad »

Good evening to the Community!
I thought it appropriate to reply to clarify some (of inaccuracies indicated as bugs).
In TechDraw the possibility of identifying the center of a spline and / or a curve and / or a compound curve is not contemplated, the function "create center line with two vertices" does not have this purpose, but only that of drawing a line centrally orthogonal to the two vertices chosen according to option: vertical, horizontal or aligned.

In my opinion we are wrong to underestimate FreeCad thinking that it is not able to accurately identify the midpoint of any spline and / or compound curve [tpavlicek writes:… ..The arc length is 105.05mm (could be verified using online ellipse circumference calculators ) ……] probably because he has not thoroughly studied the tools available to FreeCad.

Just use the “Curves” workbench and everything returns to “normal”.

In the following images a trivial example of the power and versatility of FreeCad regarding ellipses and splines (try to experiment if it is also possible with other famous commercial cads).

If the curve (or compound curve) can be identified as an arc, then its length can also be indicated as a development in TechDraw using the macro "TechDrawTools V 0.4.2-multilanguage" by @edi and domad, otherwise to know the parameters we can use another macro "FCInfo_en_Ver_1-22-rmu_Docked" by @ mario52 that will give us a lot of information ... .. exportable in different table formats.
I hope I was helpful. ;)
Happy weekend to the community!
Attachments
arc_length_dimensioning.png
arc_length_dimensioning.png (153.08 KiB) Viewed 2090 times
spline_midpoint_with_wb_Curves.png
spline_midpoint_with_wb_Curves.png (161.57 KiB) Viewed 2098 times
Post Reply