Sketcher: Ellipse support

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
marktaff
Posts: 47
Joined: Sun Sep 21, 2014 3:25 pm
Location: Seattle, Washington, USA

Re: Sketcher: Ellipse support

Post by marktaff »

ulrich1a wrote: Have a look here: viewtopic.php?f=10&t=7520&start=40#p61810

git clone URL your_directory
should do the job.

Ulrich
That did not have the expected results; I must be doing something wrong or misunderstanding something.

I currently have the main master in /home/mark/freecad/freecad, building in /home/mark/freecad/freecad-build.
I put the ellipse stuff in /home/mark/freecad/freecad-ellipse via:

Code: Select all

git clone https://github.com/abdullahtahiriyo/FreeCAD_sf_master.git freecad-ellipse
and building in /home/mark/freecad/freecad-ellipse-build.

freecad-ellipse configured, built, and ran just fine, but there was none of the ellipse stuff apparently in it--no way to draw an ellipse, no ellipse icons in the resource file, etc. I'd appreciate any help pointing out my error(s). Thanks.
Available on chat.freenode.net#freecad while working on FreeCad
User avatar
quick61
Veteran
Posts: 3803
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Sketcher: Ellipse support

Post by quick61 »

Once you have cloned the source, cd into your ~/freecad-ellipse directory and do -

Code: Select all

git branch
This will tell you which branch your in. It should return -

Code: Select all

* master
Now do -

Code: Select all

git branch -r
And you will see a list of all the branches that are included in your clone, the ones that are of intrest for Sketcher: Ellipse support look like -

Code: Select all

origin/sketcher_elipse
origin/sketcher_ellipse2
origin/sketcher_ellipse2_tangent_circunf_ulrich1a_original_pointonellipse
origin/sketcher_ellipse2_tangent_circunf_ulrich1a_squared_pointonellipse
origin/sketcher_ellipse_master
Decide which branch you want to build - and for this example we'll use "sketcher_ellipse_master" and do -

Code: Select all

git checkout sketcher_ellipse_master
and you will see the message -

Code: Select all

Switched to a new branch 'sketcher_ellipse_master'
If you now do -

Code: Select all

git branch


You will now see -

Code: Select all

  master
* sketcher_ellipse_master
With the * noting which branch you are in.

From this point, now configure your build with cmake or cmake-gui and compile as always.

Edit - now my question is, which branch should we be building if we want to look and test? Is sketcher_ellipse_master the current one?

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
marktaff
Posts: 47
Joined: Sun Sep 21, 2014 3:25 pm
Location: Seattle, Washington, USA

Re: Sketcher: Ellipse support

Post by marktaff »

Thank you so much Mark! I am now on the correct branch.
Available on chat.freenode.net#freecad while working on FreeCad
User avatar
quick61
Veteran
Posts: 3803
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: Sketcher: Ellipse support

Post by quick61 »

marktaff wrote:Thank you so much Mark! I am now on the correct branch.
Your welcome. While I do not even come close to resembling a programmer, I have been using git enough while bug testing different FeeeCAD branches to know some of the git basics.

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Ellipse support

Post by abdullah »

You picked the right branch out of 5 possilities Mark-quick61!! :o ... you should play lotto this week!!! :lol:

Because all the solver parameters are going to change, I would welcome a general equation of the ellipse based on those parameters. Let's say we pick the one of the eccentricity... I need an ellipse equation based only on those parameters. Why? To derive the error function and the gradient, the partials, that now have to be with respect to this new parameters, as they are the solver params... for example part(error)/part(e)...

... when I started, I chose phi, also because I was using the cartesian parametric equation, which is a function of phi...
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Sketcher: Ellipse support

Post by ulrich1a »

abdullah wrote:I need an ellipse equation based only on those parameters.
The ellipse equation for this parametrization is:
2*a=sqrt((yF2−yp)^2+(xF2−xp)^2)+sqrt((yF1−yp)^2+(xF1−xp)^2)
xp and yp are the points on an ellipse.
F1 and F2 are the foci
a is the major radius.
See this post: viewtopic.php?f=10&t=7520&start=110#p62721

It may work also with this equation:
0=−(−yF2^2+2*yp*yF2+yF1^2−2*yp*yF1−xF2^2+2*xp*xF2+xF1^2−2*xp*xF1−4*a^2)^2/(16*a^2)+yF2^2−2*yp*yF2+
xF2^2−2*xp*xF2+yp^2+xp^2
See this post: viewtopic.php?f=10&t=7520&start=160#p63282
The ellipse equation is just equal to the point on ellipse error equation with the error set to zero.

So I thought it would not be so much work to use the parametrization of F1, F2 and a, as the last added constraints are already based on the new parametrization.

The existing drawing method may be reused:
Center_point = (F1 + F2) / 2
b^2 = a^2 - (|(F1 + F2)/2|)^2

Ulrich
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Sketcher: Ellipse support

Post by DeepSOIC »

Sorry, I don't have time today to properly craft my posts.
The ellipse eq in brand new polar (perifocal) coordinates and brand new eccentricity-based parameterization is:
universal equation for conics
universal equation for conics
ellipse_eq_polar.gif (2.35 KiB) Viewed 2803 times
It should be valid for all conics.
I got it by substituting a=d/(1-e) into the previously mentioned polar equation of ellipse based on a.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Ellipse support

Post by abdullah »

I wanted to summarize what I did today and which design decisions I took and why.

I have been thinking about the representation and I decided to give a try first to UlrichDeepSOIC approach. Why? because this representation is much closer to the current work done (further reasons follow). Can't we use the perifocal approach? Yes, we can solve the equations using the perifocal if this is more convenient, however, the basic parameters in this approach has to be well, continue reading...

...then I coded all those changes (yes including calculations of PoE and Line tangent to Ellipse) and realized (yes it should have come to my mind earlier) that because the center is a UI point to which a constraint can be set (for example, a coincident constraint), and the sketcher solving relies on a midpoint,startpoint,endpoint (yes, also so deep inside) and maps UI midpoint to sketcher solving midpoint, it follows that the center point has to be a parameter of the ellipse. (side note: could we have painted in the UI a focus and constraint a focus? theoretically yes, but this would mean that for the UI it would be a "center" or middle point, while obviously would not be the point in the center)...

... so I modified the UlrichDeepSOIC to use a focus (the positively defined one) and the center. This way the parameters are:
Center x,y
Focus1 x,y
Minor radius r (5 DoF)

...I have just finished the changes (yes including calculations of PoE and Line tangent to Ellipse) . It does compile, but I think I made a mistake when mapping parameters, because the constraints do not work properly (tangent is a secant and point on ellipse is point far away from the ellipse, a total success :lol: ) (but they converge nicely in the solver :) )... I will take a look when I have time...

This is the code:

https://github.com/abdullahtahiriyo/Fre ... master.git
* [new branch] sketcher_ellipse_solver_modified_ulrich1a_proposal


Calculus (sage worksheets) are attached...

I still do not dispose the perifocal approach, I just want to see if this solves our problems...
Attachments
Ellipse_sage.zip
(6.74 KiB) Downloaded 49 times
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Sketcher: Ellipse support

Post by DeepSOIC »

abdullah wrote:I still do not dispose the perifocal approach, I just want to see if this solves our problems...
You don't. But I do. Here is why.
I have written an error function in perifocal coordinates for point-on-object constraint. The error function is very simple - it is just an ellipse equation with all terms thrown into the right side (i.e. equality is substituted by subthaction). It is fine for ellipse and parabola, but it is an epic fail for hyperbola. The reason for that is that if a point happens to be slightly off but enough to cross the asymptote (which can be very close to the hyperbola!), the error function will switch to the other branch of hyperbola. This is absolutely unacceptable..

This doesn't rule out the perifocal approach completely, but it turns out that math there is not as simple as I expected, it will unlikely be universal to all conics and I don't see any advantages anymore compared to our previous path with vector/cartesian math.
User avatar
marktaff
Posts: 47
Joined: Sun Sep 21, 2014 3:25 pm
Location: Seattle, Washington, USA

Re: Sketcher: Ellipse support

Post by marktaff »

DeepSOIC wrote: I have written an error function in perifocal coordinates for point-on-object constraint. The error function is very simple - it is just an ellipse equation with all terms thrown into the right side (i.e. equality is substituted by subthaction). It is fine for ellipse and parabola, but it is an epic fail for hyperbola. The reason for that is that if a point happens to be slightly off but enough to cross the asymptote (which can be very close to the hyperbola!), the error function will switch to the other branch of hyperbola. This is absolutely unacceptable..

This doesn't rule out the perifocal approach completely, but it turns out that math there is not as simple as I expected, it will unlikely be universal to all conics and I don't see any advantages anymore compared to our previous path with vector/cartesian math.
Some things will vertainly be easier in cartesian coords than polar coords. To be clear, a perifocal frame doesn't imply using polar or cartesian--it is just a question of how you place the basis vectors.

Your point about the hyperbola asymptote and error functions is quite interesting--I suppose this is an issue we will have with any function with asymptotes. I'm going to start digging in to abdullah's code to see if I can get a better handle on it.

Cheers!
Available on chat.freenode.net#freecad while working on FreeCad
Post Reply