## Sketcher: Ellipse support

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
DeepSOIC
Posts: 7829
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

### Re: Sketcher: Ellipse support

ulrich1a wrote:I think it should be either
nx=-dy
ny=dx
or
nx=dy
ny=-dx
Of course! I goofed it!
abdullah
Posts: 3584
Joined: Sun May 04, 2014 3:16 pm

### Re: Sketcher: Ellipse support

This was wrong in my calculations:
F1_m = F1 - 2*d_lF1*N
Should have been this:
F1_m = F1 + 2*d_lF1*N
Anyway it has problems converging (sketch fails to solve many times). I am going to try the squared version of the distance as error function instead of the distance...
abdullah
Posts: 3584
Joined: Sun May 04, 2014 3:16 pm

### Re: Sketcher: Ellipse support

Ok. Just implemented the square distance error function. It works more or less well. Meaning my implementation of tangent was as bad as the DeepSOIC's normal distance one. With the squared distance this is much better than my previous implementation. Still, if you for the tangent line to be vertical and then you change your mind and apply a horizontal constraint to it, the solver crashes (if you help it a little bit by moving it out of the full vertical, it converges to horizontal). Needs more testing. Probably still needs improvements.

Teaser:
Ellipse19.png (92.69 KiB) Viewed 1251 times
Where can you find this?
https://github.com/abdullahtahiriyo/Fre ... master.git
79ec397..a5ee25b sketcher_ellipse2 -> sketcher_ellipse2

What how do we know you did it right?

Well you can check my math. By using sage I produce the C code of the calculations directly from the formulas, so if you check the math and it is ok, then the c code corresponding to them should be ok.

How can I check your math?

By installing sage from their web page or Ubuntu PPA, or using an online server. You can find this information previously on this thread.

The files of tangent and point on ellipse are attached to this post.
Ellipse.zip
Probably Ulrich's PointOnObject can be improved by using the squared distance, as in this case.

If you can suggest any improvement, please do it.

Forum moderators, is there any chance that the extension sws is allowed? This extension is for the sage work sheets. If we continue exchanging math it might be useful...

Just if you are just curious, a sage notebook looks like this:
sage.png (86.25 KiB) Viewed 1247 times
abdullah
Posts: 3584
Joined: Sun May 04, 2014 3:16 pm

### Re: Sketcher: Ellipse support

Ok. The temporal line tangent to ellipse award goes to DeepSOIC... (note the organisation reserves the right to reallocate the award... )

The new quest is for ellipse tangent to a circunference (note. it can be external or internal tangent)...

Edit: I forgot to say, here the parameters are the 5 of the ellipse (or anything derivable from them) + 2 (x0,y0 of center of circle) + 1 (r, radius of circle).
DeepSOIC
Posts: 7829
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

### Re: Sketcher: Ellipse support

cool!
abdullah wrote: ellipse tangent to a circunference
Did you mean tangent circle? Ugh!! I wonder how will the solver explode when a circle touches an ellipse in two points . Whatever. That's not the end, one would want ellipse-to-ellipse tangency . Crazy!
Maybe it is not worth doing now, and hope for a line-in-between way of doing this (i.e. a line that is tangent to ellipse and circle and has a point that is on those three).
abdullah
Posts: 3584
Joined: Sun May 04, 2014 3:16 pm

### Re: Sketcher: Ellipse support

Well, we could certainly build it using a construction line in-between.

However, for example in the case of two circles, we do not use a construction line. Then this is the basis for the arc of circle and arc of ellipse tangent to ellipse and circle...

I was thinking on doing circle to ellipse and ellipse to ellipse, but maybe DeepSOIC is right... is it worth it?

I am open to any comments... do you think that we should focus on the already available constraints and how to make the ellipse support implementation "masterizable" without further working on those constraints?? What do you think should bear priority?? You are the users, you have the experience, let me hear your voices!!!
abdullah
Posts: 3584
Joined: Sun May 04, 2014 3:16 pm

### Re: Sketcher: Ellipse support

Hey Jim!!

Still to constrain the ellipse, I have to cheat putting a radius constraint...
Ellipse20.png (50.95 KiB) Viewed 1218 times
See file
jmaustpc
Posts: 10383
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

### Re: Sketcher: Ellipse support

abdullah wrote:Hey Jim!!

Still to constrain the ellipse, I have to cheat putting a radius constraint...
the trick I worked out was to put a construction line at the end of the major axis (or minor would work), make this line perpendicular to the major axis construction line and tangent to the edge of the ellipse.

The line on the major axis has two point on lines and a third point on line with the centre of the ellipse.
Ellipse20.png (51.06 KiB) Viewed 1212 times

Jim
jmaustpc
Posts: 10383
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

### Re: Sketcher: Ellipse support

ulrich1a
Posts: 1958
Joined: Sun Jul 07, 2013 12:08 pm

### Re: Sketcher: Ellipse support

abdullah wrote:The new quest is for ellipse tangent to a circunference (note. it can be external or internal tangent)...
The tangent of ellipse to circle do more or less already exist. Is it not the point on ellipse constraint with