(defun c:tan-pt-el ( / o ox oy osm ptt1 ptt2 pt m z xo yo a b pta ptb )
(setq osm (getvar 'osmode))
(setvar "osmode" 0)
(setq o (list 0 0 0))
(setq ox (list 1 0 0))
(setq oy (list 0 1 0))
(command "xline" o ox "")
(command "xline" o oy "")
(command "zoom" "c" o "" "")
(command "regen")
(prompt "\nEnter point of tangent at x axis (first tangent definition) : ")
(setq ptt1 (getpoint o))
(prompt "\nEnter point of tangent at y axis (second tangent definition) : ")
(setq ptt2 (getpoint o))
(command "xline" ptt1 ptt2 "")
(setvar "osmode" 512)
(setq pt (getpoint "\nPick point on tangent through witch I draw ellipse : "))
(command "point" pt "")
(setvar "pdmode" 3)
(setvar "pdsize" 0)
(setvar "osmode" 0)
(setq m (car ptt1))
(setq z (cadr ptt2))
(if (minusp m) (setq m (- m)))
(if (minusp z) (setq z (- z)))
(if (minusp (car pt)) (setq xo (- (car pt))) (setq xo (car pt)))
(if (minusp (cadr pt)) (setq yo (- (cadr pt))) (setq yo (cadr pt)))
(setq b (sqrt (* z yo)))
(setq a (sqrt (/ (* (expt b 2) m xo) (* z yo))))
(setq pta (list a 0 0))
(setq ptb (list 0 b 0))
(command "ellipse" "c" o pta ptb "")
(setvar 'osmode osm)
(princ)
)
Here is my (unfinished) version.
tgA=z/x=l/y=s/p=(x+m)/h (1)
s=p*tgA
z=x*tgA
l=y*tgA
z*h=x*(x+m)
m=(z*h-x^2)/x
y=l/tgA
h^2=x*y (2)
h=sqrt(x*y)
(x+m)^2=z*l (3)
p^2=x^2+h^2 (4)
p*r=h*(x+y) (5)
r=h*(x+y)/p
r^2=h^2+y^2 (6)
q^2=m^2+(l-h)^2 (7)
s^2=z^2+(x+m)^2 (8)
(p+q)^2=l^2+(x+m)^2 (9)
(p+q)^2=l^2+z*l (...3)
(p+q)^2=l*(l+z)
s^2=(l+z)^2-(p+q)^2 (10)
s^2=(l+z)^2-l*(l+z) (...9)
s^2=l^2+2*l*z+z^2-l^2-l*z
s^2=z^2+l*z
(x+y)^2=k^2+k^2-2*k*k*cos(180-2A) (11)
(x+y)^2=2*k^2-2*k^2*cos(180-2A)
(x+y)^2=2*k^2*(1-cos(180-2A))
(x+y)^2=2*k^2*(1+cos2A)
2*k^2=(x+y)^2/(1+cos2A)
4*k^2=(2*x^2+4*x*y+2*y^2)/(1+cos2A)
4*k^2=(2*x^2+4*x*(l/tgA)+2*(l/tgA)^2)/(1+cos2A)
---------------------------
(s+r)^2+q^2=(2*k)^2 (12)
s^2+2*s*r+r^2+q^2=4*k^2 (...10)
z^2+l*z+2*p*tgA*h*(x+y)/p+h^2+y^2+q^2=4*k^2 (...1...5...6)
x^2*tgA^2+l*x*tgA+2*tgA*h*(x+y)+h^2+y^2+q^2=4*k^2 (...1)
x^2*tgA^2+l*x*tgA+2*tgA*(sqrt(x*y))*(x+y)+x*y+y^2+q^2=4*k^2 (...2)
----------------------- ---
+ tgA^2*(x+y)^2 - tgA^2*(x+y)^2 = 0
---------------
+(tgA*(x+y)+(sqrt(x*y)))^2 - tgA^2*(x+y)^2
x^2*tgA^2+l*x*tgA+(tgA*(x+y)+(sqrt(x*y)))^2-tgA^2*(x+y)^2+y^2+q^2=4*k^2
(tgA*(x+y)+(sqrt(x*y)))^2-x^2*tgA^2-2*x*y*tgA^2-y^2*tgA^2+y^2+q^2+x^2*tgA^2+l*x*tgA=4*k^2
((x*tgA+y*tgA)+(sqrt(x*y)))^2-x^2*tgA^2-2*x*y*tgA^2-y^2*tgA^2+y^2+q^2+x^2*tgA^2+l*x*tgA=4*k^2 (...1...2)
((z+l)+h)^2-z^2-2*h^2*tgA^2-l^2+(l/tgA)^2+q^2+z^2+l*z=4*k^2
---- ----
(z+l+h)^2-2*h^2*tgA^2-l^2+(l/tgA)^2+q^2+l*z=4*k^2
z^2+l^2+h^2+2*z*l+2*z*h+2*l*h-2*h^2*tgA^2-l^2+(l/tgA)^2+q^2+l*z=4*k^2
---- ------ ---- ----
z^2+h^2+3*z*l+2*z*h+2*l*h-2*h^2*tgA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tgA)+2*x*tgA*l+(l/tgA)^2+x^2+l^2=(2*x^2+4*x*(l/tgA)+2*(l/tgA)^2)/(1+cos2A) (...11)
x^2*tgA^2+x^2*tgA^2*cos2A+2*x*(l/tgA)+2*x*(l/tgA)*cos2A+2*x*tgA*l+2*x*tgA*l*cos2A+(l/tgA)^2+(l/tgA)^2*cos2A+x^2+x^2*cos2A+l^2+l^2*cos2A-2*x^2-4*x*(l/tgA)-2*(l/tgA)^2=0
------------------------- -------------- ------
x^2*(tgA^2+tgA^2*cos2A+1+cos2A-2)+2*x*(l/tgA)+2*x*(l/tgA)*cos2A+2*x*tgA*l+2*x*tgA*l*cos2A+(l/tgA)^2+(l/tgA)^2*cos2A+l^2+l^2*cos2A-4*x*(l/tgA)-2*(l/tgA)^2=0
-------------------------------------------------------- ------------
x^2*(tgA^2+tgA^2*cos2A+1+cos2A-2)+x*(2*(l/tgA)+2*(l/tgA)*cos2A+2*tgA*l+2*tgA*l*cos2A-4*(l/tgA))+(l/tgA)^2+(l/tgA)^2*cos2A+l^2+l^2*cos2A-2*(l/tgA)^2=0
x^2*((1+cos2A)*(tgA^2+1)-2)+x*((1+cos2A)(2*(l/tgA)+2*l*tgA)-4*(l/tgA))+((1+cos2A)*((l/tgA)^2+l^2)-2*(l/tgA)^2)=0
----------------------------------------------------------------------------------------------------------------
-((1+cos2A)*(2*(l/tgA)+2*l*tgA)-4*(l/tgA))[+-](sqrt(((1+cos2A)(2*(l/tgA)+2*l*tgA)-4*(l/tgA))^2-4*((1+cos2A)*(tgA^2+1)-2)*((1+cos2A)*((l/tgA)^2+l^2)-2*(l/tgA)^2)))
x = ------------------------------------------------------------------------------------------------------------------------------------------------------------------
2*((1+cos2A)*(tgA^2+1)-2)
-b[+-](sqrt(b^2-4*a*c))
x = -----------------------
2*a
Stephan: Thank you.You're welcome Martin.
I will try Lee, as much as my English allows me.Code - Auto/Visual Lisp: [Select]
b (* y (/ (- y (* m x)) (- (* 2 y) (* m x))))
Could you possibly shed some light?
(defun _ellipse ( p1 d1 p2 d2 / i1 i2 r1 tmp )
(if (setq i1 (inters p1 (mapcar '+ p1 d1) p2 (mapcar '+ p2 d2) nil))
(progn
(if (< (distance p1 i1) (distance p2 i1))
(setq tmp p1 p1 p2 p2 tmp)
)
(setq i2 (inters i1 (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) p1 p2) p1 (polar p1 (+ (angle p1 i1) (/ pi 2.0)) 1.0) nil)
r1 (distance p1 i2)
p2 (trans (mapcar '- p2 i2) 0 (mapcar '- p1 i2))
p2 (mapcar '* p2 p2)
p2 (trans (list (sqrt (/ (car p2) (- 1.0 (/ (caddr p2) (* r1 r1))))) 0.0) (mapcar '- p1 i2) 0)
)
(command "_.ellipse" "_C" "_non" i2 "_non" p1 "_non" (mapcar '+ i2 p2))
)
)
)
(defun c:test ( / d1 d2 p1 p2 )
(if
(and
(setq p1 (getpoint "\n1st point: "))
(setq d1 (getpoint "\n1st direction: " p1))
(setq p2 (getpoint "\n2nd point: "))
(setq d2 (getpoint "\n2nd direction: " p2))
)
(_ellipse p1 (mapcar '- d1 p1) p2 (mapcar '- d2 p2))
)
(princ)
)
(command "pline" (list 0. 0. 0.) "w" 2.0 2.0 (list 2. 0. 0.) "a" "w" 2.0 4.0 (list 4. 3. 0.) "l" (list 2.3247915 7. 0.) "")
As shown in the attachment the resulting lwpolyline is inelegant, the alignment of the arcs in the outline with the adjacent line segments is poor, and the width at the wide end of the arc is incorrect. The code in PPL.LSP (available on this site) provides a reasonable approximation of the actual outline, anomalies included. The image on the right is using either Stefan's or Lee's routine to create the ellipses.