AH! that's right ...that's what it was...I thought I might have that screwed up...abdullah wrote:Jim, for the foci just make two lines of size major radius, coincident at the end of the minor radius, the other end point on line with the major axis (one to each side). Ulrich did it so in his first point on ellipse simulation...
This approach looks good. Variable names:DeepSOIC wrote:Here is an idea: mirror one of the focuses using the line to be constrained, and calculate the distance between the mirrored focus and the other (still real) focus! (This length) minus (sum of ellipse radii) is your error function! [(sum of ellipse radii) - the same stuff that is used as a point-on-ellipse constraint]
I know how to do it. Here is the computation with all steps. You can substitute stuff to yield a single expression if you want.ulrich1a wrote:The mathematical task is then to express xF1m and yF1m in terms of: xF1, yF1, xP1, yP1, xP2 and yP2
Code: Select all
//calculate and normalize line direction vector
dx=xP2-xP1
dy=yP2-yP1
l=sqrt(dx^2+dy^2)
dx=dx/l
dy=dy/l
//the normal to the line
nx=dy
ny=-dx //minus! thanks Ulrich!
//calculate distance btw F1 and the line - the scalar product of the normal and a vector connecting P1 and F1:
dst=nx*(xF1-xP1)+ny*(yF1-yP1)// a signed value. sign is important and should be kept
//mirror the point by double dst along normal (backwards)
xF1m=xF1-2.0*dst*nx
yF1m=yF1-2.0*dst*ny
//done =) hope I didn't goof anything
I think it should be eitherDeepSOIC wrote://the normal to the line
nx=dy
ny=dx
Code: Select all
{{{id=1|
from sympy import symbols
from sympy.utilities.codegen import codegen
a = var('a')
print "a is major axis of the ellipse"
b = var('b')
print "b is minor axis of the ellipse"
t = var('t')
print "t is an angle parameter for a point in the ellipse"
phip = var('phip')
print "phi is the angle of the major axis with the X-Axis"
X_c = var('X_c')
print "Xc is the x of the center point in the ellipse"
Y_c = var('Y_c')
print "Yc is the y of the center point in the ellipse"
X_0 = var('X_0')
print "X0 is the x of the point on the line that is the contact point"
Y_0 = var('Y_0')
print "Y0 is the y of the point on the line that is the contact point"
X_1 = var('X_1')
print "X1 is the x of the first point of the line"
Y_1 = var('Y_1')
print "Y1 is the y of the first point of the line"
X_2 = var('X_2')
print "X2 is the x of the second point of the line"
Y_2 = var('Y_2')
print "Y2 is the y of the second point of the line"
P=vector([X_0,Y_0])
print "P is the point on the line"
P1=vector([X_1,Y_1])
print "P1 is the first extreme point"
P2=vector([X_2,Y_2])
print "P2 is the first extreme point"
///
a is major axis of the ellipse
b is minor axis of the ellipse
t is an angle parameter for a point in the ellipse
phi is the angle of the major axis with the X-Axis
Xc is the x of the center point in the ellipse
Yc is the y of the center point in the ellipse
X0 is the x of the point on the line that is the contact point
Y0 is the y of the point on the line that is the contact point
X1 is the x of the first point of the line
Y1 is the y of the first point of the line
X2 is the x of the second point of the line
Y2 is the y of the second point of the line
P is the point on the line
P1 is the first extreme point
P2 is the first extreme point
}}}
{{{id=2|
dF=sqrt(a^2-b^2)
F1=vector([X_c,Y_c])+dF*vector([cos(phip), sin(phip)])
F2=vector([X_c,Y_c])-dF*vector([cos(phip), sin(phip)])
X_F1=F1[0]
Y_F1=F1[1]
X_F2=F2[0]
Y_F2=F2[1]
///
}}}
{{{id=3|
t_v=(P2-P1)/sqrt((P2-P1)*(P2-P1))
show(t_v)
///
<html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}\left(-\frac{X_{1} - X_{2}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}},\,-\frac{Y_{1} - Y_{2}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}}\right)</script></html>
}}}
{{{id=4|
N=vector([t_v[1],-t_v[0]])
show(N)
///
<html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}\left(-\frac{Y_{1} - Y_{2}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}},\,\frac{X_{1} - X_{2}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}}\right)</script></html>
}}}
{{{id=5|
d_lF1=N*(P1-F1)
show(d_lF1)
///
<html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{{\left(\sqrt{a^{2} - b^{2}} \sin\left(\mbox{phip}\right) - Y_{1} + Y_{c}\right)} {\left(X_{1} - X_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}} + \frac{{\left(\sqrt{a^{2} - b^{2}} \cos\left(\mbox{phip}\right) - X_{1} + X_{c}\right)} {\left(Y_{1} - Y_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}}</script></html>
}}}
{{{id=7|
print "this is the mirror of F1"
F1_m = F1 - 2*d_lF1*N
show(F1_m)
///
this is the mirror of F1
<html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}\left(-\frac{2 \, {\left(\frac{{\left(\sqrt{a^{2} - b^{2}} \sin\left(\mbox{phip}\right) - Y_{1} + Y_{c}\right)} {\left(X_{1} - X_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}} - \frac{{\left(\sqrt{a^{2} - b^{2}} \cos\left(\mbox{phip}\right) - X_{1} + X_{c}\right)} {\left(Y_{1} - Y_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}}\right)} {\left(Y_{1} - Y_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}} + \sqrt{a^{2} - b^{2}} \cos\left(\mbox{phip}\right) + X_{c},\,\frac{2 \, {\left(\frac{{\left(\sqrt{a^{2} - b^{2}} \sin\left(\mbox{phip}\right) - Y_{1} + Y_{c}\right)} {\left(X_{1} - X_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}} - \frac{{\left(\sqrt{a^{2} - b^{2}} \cos\left(\mbox{phip}\right) - X_{1} + X_{c}\right)} {\left(Y_{1} - Y_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}}\right)} {\left(X_{1} - X_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}} + \sqrt{a^{2} - b^{2}} \sin\left(\mbox{phip}\right) + Y_{c}\right)</script></html>
}}}
{{{id=8|
DM = sqrt((F1_m-F2)*(F1_m-F2)) - 2*a
show(DM)
///
<html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}-2 \, a + \sqrt{4 \, {\left(\frac{{\left(\frac{{\left(\sqrt{a^{2} - b^{2}} \sin\left(\mbox{phip}\right) - Y_{1} + Y_{c}\right)} {\left(X_{1} - X_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}} - \frac{{\left(\sqrt{a^{2} - b^{2}} \cos\left(\mbox{phip}\right) - X_{1} + X_{c}\right)} {\left(Y_{1} - Y_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}}\right)} {\left(X_{1} - X_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}} + \sqrt{a^{2} - b^{2}} \sin\left(\mbox{phip}\right)\right)}^{2} + 4 \, {\left(\frac{{\left(\frac{{\left(\sqrt{a^{2} - b^{2}} \sin\left(\mbox{phip}\right) - Y_{1} + Y_{c}\right)} {\left(X_{1} - X_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}} - \frac{{\left(\sqrt{a^{2} - b^{2}} \cos\left(\mbox{phip}\right) - X_{1} + X_{c}\right)} {\left(Y_{1} - Y_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}}\right)} {\left(Y_{1} - Y_{2}\right)}}{\sqrt{{\left(X_{1} - X_{2}\right)}^{2} + {\left(Y_{1} - Y_{2}\right)}^{2}}} - \sqrt{a^{2} - b^{2}} \cos\left(\mbox{phip}\right)\right)}^{2}}</script></html>
}}}
Hey Jim! I think it is indeed interesting to try this things out, because if want to get rid of specific constraints, then this has to work well...But I was please to work out a method of constraining the ellipse with the lines without the specific ellipse constraints....I thought that was interesting.![]()
Only opening that sketch takes a long while, like a minute and a half...Adjusting the angle constraint on the line on the major axis will rotate the ellipse...this works well for small movements of about 10 degrees at a time but some larger steps cause FreeCAD to have to think for a long time...some angles are invalid for some reason...it does not like 0 or 180 degrees. At first I tried to change from 120 to 40 degrees, FreeCAD said that 40 degrees was invalid after having thought about it for a long time...yet later when I moved it 10 degrees at a time FreeCAD had no problems going to 40 degrees.