kalai Posted May 19, 2011 Share Posted May 19, 2011 my coding (setq p1 '(500 200 0) (command "circle" ' (0 0 0) 10) now at this point i have to draw line from p1 to tangential point on circle. how can thisbe done? help me. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 19, 2011 Share Posted May 19, 2011 This ? (vl-load-com) (setq p1 '(500 200 0)) (command "circle" ' (0. 0. 0.) 10.) (setq obj (entlast)) (setq obj (vlax-ename->vla-object obj)) (setq p2 (vlax-curve-getClosestPointTo obj p1)) (entmakex (list (cons 0 "LINE")(cons 10 p1)(cons 11 p2))) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 19, 2011 Share Posted May 19, 2011 Tharwat, The closest point will be perpendicular, not tangential. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 19, 2011 Share Posted May 19, 2011 This will return the two points (in WCS) which are tangent to the supplied circle entity from the supplied point projected onto the plane in which the Circle resides; or nil if the supplied point lies inside the circle. ([color=BLUE]defun[/color] LM:GetTangentPoints ( pt ci [color=BLUE]/[/color] a1 c1 d1 el r1 tn ) ([color=BLUE]setq[/color] el ([color=BLUE]entget[/color] ci) c1 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 10 el)) r1 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 40 el)) d1 ([color=BLUE]distance[/color] pt c1) a1 ([color=BLUE]angle[/color] c1 pt) ) ([color=BLUE]if[/color] ([color=BLUE]<[/color] r1 d1) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] tn ([color=BLUE]sqrt[/color] ([color=BLUE]-[/color] ([color=BLUE]*[/color] d1 d1) ([color=BLUE]*[/color] r1 r1))) tn ([color=BLUE]atan[/color] tn r1) ) ([color=BLUE]list[/color] ([color=BLUE]trans[/color] ([color=BLUE]polar[/color] c1 ([color=BLUE]+[/color] a1 tn) r1) ci 0) ([color=BLUE]trans[/color] ([color=BLUE]polar[/color] c1 ([color=BLUE]-[/color] a1 tn) r1) ci 0) ) ) ) ) A test function: ([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] e p ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] e ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect Circle: "[/color]))) ([color=BLUE]eq[/color] [color=MAROON]"CIRCLE"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] e)))) ([color=BLUE]setq[/color] p ([color=BLUE]getpoint[/color] [color=MAROON]"\nSpecify Point: "[/color])) ([color=BLUE]setq[/color] p ([color=BLUE]trans[/color] p 1 0)) ) ([color=BLUE]foreach[/color] x (LM:GetTangentPoints ([color=BLUE]trans[/color] p 0 e) e) ([color=BLUE]entmakex[/color] ([color=BLUE]list[/color] ([color=BLUE]cons[/color] 0 [color=MAROON]"LINE"[/color]) ([color=BLUE]cons[/color] 10 p) ([color=BLUE]cons[/color] 11 x)) ) ) ) ([color=BLUE]princ[/color]) ) Alternatively, here is a function accepting a Point, Circle Center and Circle Radius: ([color=BLUE]defun[/color] LM:GetTangentPoints ( pt cen rad [color=BLUE]/[/color] a1 d1 tn ) ([color=BLUE]if[/color] ([color=BLUE]<[/color] rad ([color=BLUE]setq[/color] a1 ([color=BLUE]angle[/color] cen pt) d1 ([color=BLUE]distance[/color] pt cen))) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] tn ([color=BLUE]atan[/color] ([color=BLUE]sqrt[/color] ([color=BLUE]-[/color] ([color=BLUE]*[/color] d1 d1) ([color=BLUE]*[/color] rad rad))) rad)) ([color=BLUE]list[/color] ([color=BLUE]trans[/color] ([color=BLUE]polar[/color] cen ([color=BLUE]+[/color] a1 tn) rad) 1 0) ([color=BLUE]trans[/color] ([color=BLUE]polar[/color] cen ([color=BLUE]-[/color] a1 tn) rad) 1 0) ) ) ) ) Quote Link to comment Share on other sites More sharing options...
David Bethel Posted May 19, 2011 Share Posted May 19, 2011 As a starting point: This should give you length of the tangent line ( s2 ) and the length of the 3 sides forming a right triangle. [b][color=BLACK]([/color][/b]setq p1 '[b][color=FUCHSIA]([/color][/b]6 2 0[b][color=FUCHSIA])[/color][/b] [color=#8b4513];;;PICK POINT[/color] ce '[b][color=FUCHSIA]([/color][/b]0 0 0[b][color=FUCHSIA])[/color][/b] [color=#8b4513];;;CIRCLE CENTER[/color] ra 2[b][color=BLACK])[/color][/b] [color=#8b4513];;;CIRCLE RADIUS[/color] [b][color=BLACK]([/color][/b]setq s3 [b][color=FUCHSIA]([/color][/b]distance ce p1[b][color=FUCHSIA])[/color][/b] s1 ra s2 [b][color=FUCHSIA]([/color][/b]sqrt [b][color=NAVY]([/color][/b]- [b][color=MAROON]([/color][/b]* s3 s3[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]* s1 s1[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David Quote Link to comment Share on other sites More sharing options...
paulmcz Posted May 19, 2011 Share Posted May 19, 2011 This is what I would write: (setq osn (getvar "osmode") p1 '(0.0 0.0 0.0) r 10.0 dx 500.0 dy 200.0 a (sqrt (+ (* dx dx) (* dy dy))) b (sqrt (- (* a a) (* r r))) u1 (atan (/ dy dx)) u2 (atan (/ b r)) up (+ u1 u2) down (- u1 u2) p2 (polar p1 up r) p3 (polar p1 down r) p4 (polar p1 u1 a) ) (setvar "osmode" 0) (command "circle" p1 r) (command "line" p2 p4 p3"") (setvar "osmode" osn) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.