benhubel Posted October 8, 2019 Share Posted October 8, 2019 (edited) I have come across this useful bit of code, posted by Bruno.Valsecchi. https://forums.augi.com/showthread.php?113430-Ruberband-for-an-Arc-getpoint I've been playing around with it for a while now, and it's exactly what I need to get a bit of my own code working. However I seem to be unable to decipher it properly. It seems to be dynamically changing the number of segments based on the angle of p1-p3. As the angle of p1-p3 gets closer to matching the angle of p1-p2, the number of segments seems to decrease, eventually reducing to one segment and then disappearing, which is an issue. I've managed to identify nm as the variable used to store the number of segments, however I can't figure out where it calculates the length per segment. I'm not familiar enough with the math used to work it out myself, so it has pretty much been guesswork so far. My current goal is to modify the code to where everything works the same, except that the number of segments in the arc never drops below 6 at any time. I imagine that this is probably a very simple task for somebody who actually comprehends what is going on here, but it seems to have me defeated. If anybody could help me understand what's going on a little bit better, either by explaining it, linking to a page that explains it, or by modifying the code so that I can reverse engineer the changes, that would be very helpful. ((lambda ( / p1 p2 ll pt_m px1 px2 key p3 px3 px4 pt_cen rad inc ang nm lst_pt pa1 pa2) (initget 9) (setq p1 (getpoint "\nFirst point: ")) (initget 9) (setq p2 (getpoint p1 "\nNext point: ")) (setq ll (list p1 p2) pt_m (mapcar '/ (list (apply '+ (mapcar 'car ll)) (apply '+ (mapcar 'cadr ll)) (apply '+ (mapcar 'caddr ll)) ) '(2.0 2.0 2.0) ) px1 (polar pt_m (+ (angle p1 p2) (* pi 0.5)) (distance p1 p2)) px2 (polar pt_m (- (angle p1 p2) (* pi 0.5)) (distance p1 p2)) ) (princ "\nLast point: ") (while (and (setq key (grread T 4 0)) (/= (car key) 3)) (cond ((eq (car key) 5) (redraw) (setq p3 (cadr key) ll (list p1 p3) pt_m (mapcar '/ (list (apply '+ (mapcar 'car ll)) (apply '+ (mapcar 'cadr ll)) (apply '+ (mapcar 'caddr ll)) ) '(2.0 2.0 2.0) ) px3 (polar pt_m (+ (angle p1 p3) (* pi 0.5)) (distance p1 p3)) px4 (polar pt_m (- (angle p1 p3) (* pi 0.5)) (distance p1 p3)) pt_cen (inters px1 px2 px3 px4 nil) ) (cond (pt_cen (setq rad (distance pt_cen p3) inc (angle pt_cen p1) ang (+ (* 2.0 pi) (angle pt_cen p3)) nm (fix (/ (rem (- ang inc) (* 2.0 pi)) (/ (* pi 2.0) 36.0))) lst_pt '() ) (repeat nm (setq pa1 (polar pt_cen inc rad) inc (+ inc (/ (* pi 2.0) 36.0)) pa2 (polar pt_cen inc rad) lst_pt (append lst_pt (list pa1 pa2)) ) ) (setq lst_pt (append lst_pt (list (if pa2 pa2 p1) p3))) (grvecs lst_pt) ) ) ) ) ) (prin1) )) Thank you Edited October 8, 2019 by benhubel 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.