Hudson Posted August 6, 2009 Share Posted August 6, 2009 Hi, I'm new this week to all coding in Cad.. and haven't been programming for at least 7 years... at any rate I'm having a fair amount of success I'm at the point where I'm trying to get my program to start at a point on an arc, and then get chords of the same length to run along the arc. I don't know the most logical way to go about it as I don't have enough experience with making programs in cad. Thoughts are making circles and finding the intersection I want and drawing chords from that. Or possibly the easiest from the radius of the arc figuring out what rotation angle is needed so that the chords are placed on the arc end to end. Any and all help is greatly appreciated, thank you for your time! Quote Link to comment Share on other sites More sharing options...
Hudson Posted August 6, 2009 Author Share Posted August 6, 2009 Been doing more thinking. If I can: - find where I want to start the chord - draw a circle with radius = chord length - find the correct intersection of the circle (much smaller than arc radius) with the arc - draw the first chord - draw a line from both ends back to the origin of the arc - find the internal angle It should be fairly easy to rotate a copy with that information... Does that sound like the easiest way to go about it, or is there an easier way? Quote Link to comment Share on other sites More sharing options...
lpseifert Posted August 6, 2009 Share Posted August 6, 2009 maybe you might to be able to gather something from this ;;;Creates chords along curve w/ user entered divisions LPS 2008-11 (defun c:test (/ oldecho oldsnap obj div endpt totlen arclen chrdpt dist newpt) (vl-load-com) (setq oldecho (getvar "cmdecho") oldsnap (getvar "osmode") ) (setvar "cmdecho" 0) (setvar "osmode" 0) (setq ent (entsel "\nPick arc: ") obj (vlax-ename->vla-object (car ent)) div (getint "\nEnter number of chords: ") endpt (vlax-curve-getEndPoint obj) totlen (vlax-curve-getDistAtPoint obj endpt) arclen (/ totlen div) chrdpt (vlax-curve-getPointAtDist obj 0) dist 0 ) (repeat div (setq newpt(vlax-curve-getPointatDist obj (+ arclen dist))) (command "line" chrdpt newpt "") (setq dist (+ arclen dist)) (setq chrdpt newpt) );repeat (setvar "cmdecho" oldecho) (setvar "osmode" oldsnap) (princ) );defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 6, 2009 Share Posted August 6, 2009 Nice one Larry Quote Link to comment Share on other sites More sharing options...
lpseifert Posted August 6, 2009 Share Posted August 6, 2009 Thanks Lee... it's kinda basic compared to some of the code I've seen of yours. I don't even try and decipher yours anymore, it's way over my head. Quote Link to comment Share on other sites More sharing options...
Hudson Posted August 6, 2009 Author Share Posted August 6, 2009 Larry, thanks! I will give that a go Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 6, 2009 Share Posted August 6, 2009 Thanks Lee... it's kinda basic compared to some of the code I've seen of yours. I don't even try and decipher yours anymore, it's way over my head. Ahh, cheers mate. I'd be happy to explain anything that I've posted Quote Link to comment Share on other sites More sharing options...
Hudson Posted August 6, 2009 Author Share Posted August 6, 2009 Neat program.. it certainly helps me understand how to find points on the arc. I will need to add some logic in order to make it work via chord length and relate that to arc length, not divisions of arc length. The easiest way to do that I figure is to make a circle with radius = desired chord length, draw the line, figure out the length of arc covered by the chord.. and then that program will get me going. Could anyone help me with finding the intersection of the circle.. or correct my logic? Thanks! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 6, 2009 Share Posted August 6, 2009 You can easily find the radius of the arc, so why not just find the angle subtended by the desired chord and use it (and the radius) to find the corresponding arc length? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 6, 2009 Share Posted August 6, 2009 Thanks Lee, but to be truthful the way things are I don't think CAD holds much of a future for me anymore. I might as well just go bear hunting. lmao - I would too, but there is a distinct shortage of bears in the UK Quote Link to comment Share on other sites More sharing options...
Hudson Posted August 6, 2009 Author Share Posted August 6, 2009 Lee, You're more than right Sometimes I get caught up in a particular thought train. I'm thinking too much about how I would draw it in CAD. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 6, 2009 Share Posted August 6, 2009 No worries I'm the opposite - not being a CAD user, I just think about the mathematical twist on things Quote Link to comment Share on other sites More sharing options...
lpseifert Posted August 6, 2009 Share Posted August 6, 2009 read... bear hunting=motorcycle ride Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 6, 2009 Share Posted August 6, 2009 Ok Hudson, so I couldn't resist a Maths problem [i][color=#990099];; ============ Chrd.lsp ===============[/color][/i] [i][color=#990099];;[/color][/i] [i][color=#990099];; FUNCTION:[/color][/i] [i][color=#990099];; Will create chords of a user[/color][/i] [i][color=#990099];; specified length along an arc.[/color][/i] [i][color=#990099];;[/color][/i] [i][color=#990099];; SYNTAX: CHRD[/color][/i] [i][color=#990099];;[/color][/i] [i][color=#990099];; AUTHOR:[/color][/i] [i][color=#990099];; Copyright (c) 2009, Lee McDonnell[/color][/i] [i][color=#990099];; (Contact Lee Mac, CADTutor.net)[/color][/i] [i][color=#990099];;[/color][/i] [i][color=#990099];; VERSION:[/color][/i] [i][color=#990099];; 1.0 ~ 06.08.2009[/color][/i] [i][color=#990099];;[/color][/i] [i][color=#990099];; =====================================[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:chrd [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] *error* doc spc ent Obj rad maxChrd cLen aLen i stpt pt[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] *error* [b][color=RED]([/color][/b]msg[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] doc [b][color=RED]([/color][/b][b][color=BLUE]vla-EndUndoMark[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]wcmatch[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcase[/color][/b] msg[b][color=RED])[/color][/b] [b][color=#ff00ff]"*BREAK,*CANCEL*,*EXIT*"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\n** Error: "[/color][/b] msg [b][color=#ff00ff]" **"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] doc [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-Acad-Object[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] spc [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]zerop[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-activespace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]=[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-mspace[/color][/b] doc[b][color=RED])[/color][/b] [b][color=Blue]:vlax-true[/color][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-modelspace[/color][/b] doc[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-paperspace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-modelspace[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ent [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entsel[/color][/b] [b][color=#ff00ff]"\nSelect Arc: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#ff00ff]"AcDbArc"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ObjectName[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] Obj [b][color=RED]([/color][/b][b][color=BLUE]vlax-ename->vla-object[/color][/b] ent[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-StartUndoMark[/color][/b] doc[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] rad [b][color=RED]([/color][/b][b][color=BLUE]vla-get-Radius[/color][/b] Obj[b][color=RED])[/color][/b] maxChrd [b][color=RED]([/color][/b][b][color=BLUE]sqrt[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=#009900]2[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]expt[/color][/b] rad [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]-[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cos[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-TotalAngle[/color][/b] Obj[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] cLen [b][color=RED]([/color][/b][b][color=BLUE]getdist[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\nSpecify Chord Length <"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-princ-to-string[/color][/b] maxChrd[b][color=RED])[/color][/b] [b][color=#ff00ff]"> : "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] cLen[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] cLen maxChrd[b][color=RED])[/color][/b] [b][color=BLUE]nil[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; Exit Loop[/color][/i] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]<=[/color][/b] cLen maxChrd[b][color=RED])[/color][/b] [b][color=BLUE]nil[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]t[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\n** Chord cannot exceed "[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-princ-to-string[/color][/b] maxChrd[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] aLen [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] rad [b][color=RED]([/color][/b]acos [b][color=RED]([/color][/b][b][color=BLUE]-[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]expt[/color][/b] cLen [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=#009900]2[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]expt[/color][/b] rad [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] i [b][color=#009900]1[/color][/b] stpt [b][color=RED]([/color][/b][b][color=BLUE]vlax-curve-getStartPoint[/color][/b] Obj[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] pt [b][color=RED]([/color][/b][b][color=BLUE]vlax-curve-getPointatDist[/color][/b] Obj [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] i aLen[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-AddLine[/color][/b] spc [b][color=RED]([/color][/b][b][color=BLUE]vlax-3D-point[/color][/b] stpt[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-3D-point[/color][/b] pt[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] i[b][color=RED])[/color][/b] stpt pt[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-EndUndoMark[/color][/b] doc[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n** Nothing Selected or that isn't an Arc... **"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Inverse Cosine (ArcCos) LMac[/color][/i] [i][color=#990099];; Args: -1 <= x <= 1[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] acos [b][color=RED]([/color][/b]x[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]<[/color][/b] [b][color=#009999]1.[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]abs[/color][/b] x[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=BLUE]nil[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=BLUE]zerop[/color][/b] x[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] [b][color=BLUE]pi[/color][/b] [b][color=#009999]2.[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]t[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]atan[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]sqrt[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]-[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]expt[/color][/b] x [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] x[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] Sorry to spoil your fun Let me know if you want me to explain any of the code with you, I'd be more than happy to. Lee Quote Link to comment Share on other sites More sharing options...
Hudson Posted August 6, 2009 Author Share Posted August 6, 2009 Lee, That's amazing! Thanks, that gets me really close to solving this part of the program. Interesting code, I've never used vla-* yet. vla-AddLine looks like it could be a handy thing to have in the tool belt.. I'm still mastering entmake the value and significance of the variable spc escapes me. This while loop: (while (setq pt (vlax-curve-getPointatDist Obj (* i aLen)) terminates when vlax-curve-getPointatDist returns nill or some other error code? very fancy! Thanks again, I'm going to start monkeying with it. Andrew Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 6, 2009 Share Posted August 6, 2009 Thanks Andrew, The vla-* functions are Visual LISP, a somewhat different approach to the usual AutoLISP (using entmake etc), but the curve functions (vlax-curve-*) are a handy bunch. The spc variable is just to determine what you are working in, i.e. Model/Paper space, and adds the line to the correct space block, using vla-addLine. See here for more on that: http://www.cadtutor.net/forum/showpost.php?p=259934&postcount=13 vlax-curve-getPointatDist will return nil when it cannot get a point on the curve, hence when another chord cannot be fitted onto the arc. I enjoyed writing this one, you don't normally get to use this much geometry in LISPs Quote Link to comment Share on other sites More sharing options...
Hudson Posted August 6, 2009 Author Share Posted August 6, 2009 Very informative.. all of my experience is before visual / object oriented stuff. That piece of code gets me much closer to solving the problem.. it would have taken me quite some time to get that far. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 6, 2009 Share Posted August 6, 2009 Not a problem, happy to help out mate Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted July 16, 2011 Share Posted July 16, 2011 How about an "ellipse arc", instead of "circle arc"? Quote Link to comment Share on other sites More sharing options...
devitg Posted July 16, 2011 Share Posted July 16, 2011 Hi Ahankhah. seem to be you want to do a "ellipitical" polygon , or a part of it Is it so? 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.