In the snip below you select a segment of a closed polygon. Pick a point inside of the polygon. Draws a line from the picked point to a point that makes the line perpendicular to the segment. Should also set dwl_ang to the same angle as the line. I only want the angle but I put the (command "line" .......) in just to test. The line never fails to be perp. to the segment, but the variable dwl_ang is sometimes wrong, but not all the time. I can't pin point when and why I get a bogus angle. Is there something wrong here that anyone can see? (while (not (and (setq ent (entsel "\nSelect milling edge: ")) (setq endpnts (segmentpts ent)) ) ) ) (setvar "osmode" 0) (initget 1) (setq inside_pnt (getpoint "\nPick point inside board edges: ")) (command "line" inside_pnt (osnap (car (cdr ent)) "perp") "") (setq dwl_ang (angle inside_pnt (osnap (car (cdr ent)) "perp"))) -- Ken Alexander Acad2004 Windows XP "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein
Jason, I didn't include it because all it does is find the endpoints of the segment selected. That function doesn't redefine ent. -- Ken Alexander Acad2004 Windows XP "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein
Gottcha. That line should be commented out. My tests have been done without running that function. -- Ken Alexander Acad2004 Windows XP "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein
(I just commented that line out....) I couldn't get it to fail, tried several variations of picking segments. Don't see anything that jumps out at me.
Ken, Compare this to the code you posted. After you draw the line, osnap may perform differently since it has a new entity to work with (ie the line). Does this work better? (while (not ; (and (setq ent (entsel "\nSelect milling edge: ")) ; (setq endpnts (segmentpts ent)) ; ) ) ) (setvar "osmode" 0) (initget 1) (setq inside_pnt (getpoint "\nPick point inside board edges: ")) (setq per_pnt (osnap (cadr ent) "perp")) (command "line" inside_pnt per_pnt "") (setq dwl_ang (angle inside_pnt per_pnt))
Hi, Ken. My guess is that the second (osnap (car (cdr ent)) "perp") may be picking up the line just drawn. How about (setq p2 (osnap (car (cdr ent)) "perp")) and then (setq dwl_ang (angle inside_pnt p2))? You also have to watch out for using (osnap) with pick points and objects of different or varying elevations. Hmm, maybe also change that to "quick,perp".
Perpendicular and Tangent OSNAP are dependent on more than just a 'pick point'. They use the value of LASTPOINT to compute the result. Hence, you should *always* set LASTPOINT to the point you want to compute a perpendicular direction _from_. Sometimes, the last use of (getpoint) does this for you, but it would be unwise to depend on it. Also, using OSNAP is somewhat unpredictable, because it uses the (entsel) type object selection to identify the entity that is involved in the operation. If you can compute the desired point more directly (e.g., inters, polar, etc.), that's a safer tactic.
Let me correct myself: Actually, it is the last point passed to the (command) function that sometimes does this for you (as is the case in Doug's code), not the last response to (getpoint).
Good points Tony! This might work better. (defun C:TEST () (while (not (setq ENT (entsel "\nSelect milling edge: ")) ) ) (setvar "osmode" 0) (initget 1) (setvar "lastpoint" (setq INSIDE_PNT (getpoint "\nPick point inside board edges: "))) (setq PER_PNT (osnap (cadr ENT) "perp")) (command "line" "non" INSIDE_PNT "non" PER_PNT "") ;for visibility only (setq DWL_ANG (angle INSIDE_PNT PER_PNT)))
Finally the internet is back up. I need to clarify the line. I'm trying to get the angle that is perp. to the segment going towards the inside of the polygon. My use of the line was simply a test. Remove the (command "line"...) and just try to get the angle, it doesn't always come up with the correct angle. I would rather not use osnaps to come up with this, but at this point I haven't been able to come up with another method. -- Ken Alexander Acad2004 Windows XP "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein
Doug, Seems to work fine this way. I like Tony's suggestion of not using osnaps but can't come up with anything yet. I need a vlax-curve-getclosestpointtoparam type function. Thanks -- Ken Alexander Acad2004 Windows XP "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein
Thanks Tony, I'm going to work on your last suggestion a little bit more. -- Ken Alexander Acad2004 Windows XP "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein
BTW (cadr ENT) looks a little better too. <g> -- Ken Alexander Acad2004 Windows XP "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein
John, Thanks for the input and the SegmentPts function. -- Ken Alexander Acad2004 Windows XP "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein
Putting together some trig. I'll post it for expert review. -- Ken Alexander Acad2004 Windows XP "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein
Ken, Does this help? ;; sp1 - first segment point ;; sp2 - second segment point ;; pkpt - point picked inside pline ;; return a point such that a line ;; from pkpt to return point is ;; perpendicular to segment (defun PerPt ( sp1 sp2 pkpt / segang pkang ang h d ) (setq segang (angle sp1 sp2) pkang (angle sp1 pkpt) ang (abs (- segang pkang)) h (distance sp1 pkpt) d (* h (cos ang)) ) (polar sp1 segang d) ) Joe Burke