## Sketcher: Ellipse support

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

### Re: Sketcher: Ellipse support

ulrich1a wrote:All circles with the center point on the new ellipse should be tangent to the original ellipse.
Well... what you are telling here (if I got it right) that if one rolls a wheel along an ellipse, the wheel's center will draw a curve that is an ellipse. I think it's wrong. Here's why.

Let's take a bad bad ellipse that is extremely narrow, so that it looks almost like a line. And roll a wheel around it. The shape the wheel's center will draw will resemble a slot shape that is obviously not an ellipse. (slot shape, I mean, is the shape that is created by slot tool that is on sketcher's toolbar)

Just for fun, I have done a simulation of circle-tangent-ellipse constraint, using the same angle-equality technique I've used in my first line-tangent-ellipse simulation. I'm not sure if it's possible to turn this into an error function.
Attachments
ellipse tangent circle.png (67.79 KiB) Viewed 1295 times
ellipse tangent circle.FCStd
circle-tangent-ellipse constraint simulation
DeepSOIC
Posts: 7600
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

### Re: Sketcher: Ellipse support

I as a user would like to see elliptical arcs (the whole ellipse is not a very useful reflector). Although I can probably always do what I want with Booleans.
excuse me if it's already done... I wanted to check the ellipse out, but compiling on windows with libpack 10 and vs 2012 is a fail so far
abdullah
Posts: 3458
Joined: Sun May 04, 2014 3:16 pm

### Re: Sketcher: Ellipse support

I as a user would like to see elliptical arcs (the whole ellipse is not a very useful reflector). Although I can probably always do what I want with Booleans.
excuse me if it's already done... I wanted to check the ellipse out, but compiling on windows with libpack 10 and vs 2012 is a fail so far
No, it is not done yet. I planned to continue with elliptical arcs when the ellipse is in a masterizable state. At the end when you trim and Ellipse you get, well you know, and elliptical arc...

Sorry with the libpack issue, I really have no idea how to fix Windows compilation problems. I do not have any windows computer... I can only tell you that in Ubuntu it does compile... I guess that when it goes to a "masterizable state", I will get help from Werner there...

One question though, as it seems you want then as a reflector (for radiofrequency, microwaves, visible light, infrared for fiber optics?), then you are planning to have an elliptical structure in the sketcher and then revolve it using part design to create it in 3D? This is just out of curiosity...
abdullah
Posts: 3458
Joined: Sun May 04, 2014 3:16 pm

### Re: Sketcher: Ellipse support

Ok. I tried Ulrichs approach which sounded convincing to me (still does, but praxis says I am wrong).

If you just define a as a+radius and b as b+radius, you get this:
Ellipse21.png (28.8 KiB) Viewed 1258 times
Ellipse22.png (28.99 KiB) Viewed 1258 times
Ellipse23.png (28.82 KiB) Viewed 1258 times
Ellipse24.png (25.54 KiB) Viewed 1258 times
wmayer
Posts: 15749
Joined: Thu Feb 19, 2009 10:32 am

### Re: Sketcher: Ellipse support

I have found a theorem that parallel curves to an ellipse are never ellipses. Unfortunately there was no proof attached. So, I'll try to show this with the radius of curvature on the peaks of an ellipse.

From an ellipse it is known that the radius of curvature at the peaks is:
b^2/a on the major axis and a^2/b on the minor axis

Now if we form a new ellipse with length of the major axis of (a+r) and for the minor axis of (b+r) we obtain due to the above formula for the radii of curvature at the peaks:
(b+r)^2/(a+r) and (a+r)^2/(b+r)

For the parallel curve formed by the center point of the circle moving along an ellipse we know that the radii of curvature at the peaks must be:
b^2/a + r on the major axis and a^2/b + r on the minor axis (this is because the circles of curvature have the same center points)

If we consider the major axis now then it must be:
b^2/a + r = (b+r)^2 / (a+r)

after several transformation steps you will see that this is only true for r = 0
abdullah
Posts: 3458
Joined: Sun May 04, 2014 3:16 pm

### Re: Sketcher: Ellipse support

Thanks Werner!!

I found something surfing the net, but I doubt I will be able to do anything useful out of it. Someone might have some epiphany by looking at it:

http://math.stackexchange.com/questions ... each-other
abdullah
Posts: 3458
Joined: Sun May 04, 2014 3:16 pm

### Re: Sketcher: Ellipse support

While my brain rests from the maths and hopefully while someones brain manages to get a nice ellipse to circle tangent error function...

I am thinking about the implementation of the constraints of the ellipse. Following the deep silence of user input regarding this, I am tasked to make an uninformed decision (aka a Dilbert's CEO decision). I am heading in the following direction to avoid having ellipse-specific constraints (that is something I think we agreed not to have, as much as possible). For that, I am heading in the direction of providing to the user means for using a construction line as major axis.

We have seen in this thread before that trying to set a line as major axis is... involved...requiring:
1. One point on ellipse constraints on each end of the line (two constraints); plus
2. One point on line constraint (the ellipse center on the line); plus
3. A tweak usually one specific constraint

This is a no go for two reasons:
1. Specific constraint
2. Even if we could avoid that specific constrain by some artifact line another construction line tangent to the ellipse and perpendicular to the major axis construction line and...I am not even sure this works... even in that case, lack of stability as Jim indicated in his latest post and unacceptable long processing times.

As a consequence I am considering four paths:
1. Ellipse specific constraints (radiuses and phi, as in today's branch).
2. One ellipse specific constraint (phi) and radiuses as construction lines (likely to take time to converge).
3. No ellipse specific constraints, but an existing constraint that would do something unexpected when applied to an ellipse.
4. No ellipse specific constraints, but a new constraint, general, let's call it "Align construction element(s) to element's internal geometry"

Because we all understand 1 and 2, lets talk about 3 and 4.

Option 3: Examples

A) One of the constraints that one would not to expect to be applicable to an ellipse, is applicable and does something unexpected.
=> Parallel fits one construction element to the major axis (makes it same direction, through center point and coincident with the ellipse at +a and -a positions).
=> Perpendicular fits one construction element to minor axis as above
=> Coincident fits two construction points to the foci positions.

I do not like this. I put it here because it has been talked about.

Option 4:
B) A new constraint, of general use, currently only available for the ellipse, but extendable to any other elements that would need it. What it does on the ellipse, depends on the amount of elements selected when being applied to the ellipse:
B.1) ellipse and line selected => Fits the line to the major axis.
B.2) ellipse and two lines selected => Fits one line to the major axis and the second one to the minor axis.
B.3) ellipse and two construction points => Fits two points to the foci positions.
B.4) ellipse and two lines and two construction points => B.2)+B.3)

With any of Options 3 and 4, we would still need to look into how the ellipse performs when using construction elements (I am confident it will work, eventually,...)

Please, let me know what you think about this, because I want to make a decision (and would not like it to be Dilbert's CEO type ).
ulrich1a
Posts: 1922
Joined: Sun Jul 07, 2013 12:08 pm

### Re: Sketcher: Ellipse support

wmayer wrote:I have found a theorem that parallel curves to an ellipse are never ellipses. Unfortunately there was no proof attached. So, I'll try to show this with the radius of curvature on the peaks of an ellipse.
I feel sorry, that you all were forced to do all that math and tests, because I made just a guess without proof. It is my fault.

After some considerations I think the tangent between ellipse and circle is needing two things:
1. The point on the ellipse
2. The bisecting line of the angle of the two lines from this point to the focus points of the ellipse. (It was already shown by DeepSOIC, that this bisecting line is normal to the tangent line of an ellipse)
The center of a tangent circle sits on the bisecting line. The distance between the ellipse point and the circle center has to equal to the circle radius.
For two ellipses the bisecting line has to be common for both ellipses and the point on the ellipse has to be common for both ellipses.
I did not do the math so far.
My question regarding this is as follows: Do we need for every constraint a single error function or is it possible to apply two error functions at the same time, that may be of a simpler structure?
If this is possible, some already existing constraints may be reused for other tasks. So only a new error function for the bisecting line of the two lines from the ellipse point to the focus points is needed?

I made an error function for the point on ellipse without sqare root:
err=−(−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
Ellipse_Focus_point_equation_rev2.wxm.zip
Does this help?

abdullah wrote:Please, let me know what you think about this, because I want to make a decision (and would not like it to be Dilbert's CEO type ).
My actual preference is the following:
Let the ellipse have at least one construction line (for example between the two focus points) and selectable points at both ends of the major radius.
This is the minimal requirement to be able to constrain the ellipse with standard constraints. (As Normandc already said, other CAD packages do have more selectable lines and points for ellipses.)
The construction line can be used to rotate the ellipse to any angle needed. So no specific phi-constraint for the ellipse is needed.
Applying distances between the focus points and the points at the end of the major axis will fully define the ellipse.
With this approach no specific ellipse constraints are needed at all.
But I think it will be useful for a lot of cases, where a user wants to just input major and minor radius. So the radius constraint should have an extension, when applied to an ellipse to put in one or both radii.
The minor radius should be recalculated into the distance of the focus points. So the minor radius will show up nowhere in the solver equation system in order to avoid redundancies by design.
The phi parameter is not needed in the solver equation system, as it is already represented by the location of the to focus points.

My two cents.

Ulrich
DeepSOIC
Posts: 7600
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

### Re: Sketcher: Ellipse support

I have come up with a proposal for line-perpendicular-ellipse error function.
The function is:
normal constraint error function.gif (9.41 KiB) Viewed 1193 times
c is ellipse's center,
a and b are ellipse radii (aka axes, lengths are important!),
l is the (unnormalized) direction vector of the line (l=p2-p1),
p1 is one of the ends of the line,
n is a normal to the line (unnormalized) nx=ly, ny=-lx
(a,l) stands for scalar product of vectors a and l
Complete derivation is too long to post directly here. It is algebraic and relatively simple. See the following doc: https://drive.google.com/file/d/0B9lBm- ... sp=sharing
Hopefully, it will work. BTW, this can be slightly modified to become a tangent constraint function.

EDIT: it may be a good idea to make F independent of the length of the line. This can be done by normalizing vector n.
The length of vector l will go away in fractions anyway, so no need to normalize l
DeepSOIC
Posts: 7600
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

### Re: Sketcher: Ellipse support

I have tried a similar approach to circle-tangent-ellipse problem and got stuck being unable to analytically solve this little crazy 4-th order polynomial equation:
neat_4thorder_eq.gif (4.74 KiB) Viewed 1182 times

Not surprising I got a 4-th order one - there are 2 to 4 potential tangency points if the circle's center is fixed, depending on where the center actually is.
Attachments
4 circles with common center are tangent to an ellipse
4_tangent_circles.png (21.84 KiB) Viewed 1177 times