sadhu Posted June 6, 2011 Posted June 6, 2011 I'm looking for a lisp that tells me if I turned left or right as i click on the screen (2D - left or right respect to the two previous points). I was thinking of equation of a line, slope, direction etc. - it started getting complicated. If somebody has done this before and/or can just give me some hints to work on I'll be grateful. Quote
Lee Mac Posted June 6, 2011 Posted June 6, 2011 An example using one of those functions: (defun c:test ( / lst ) (if (and (car (setq lst (list (getpoint "\nPick First Point: ")))) (car (setq lst (cons (getpoint "\nPick Next Point: " (car lst)) lst))) ) (while (progn (redraw) (mapcar '(lambda ( a b ) (grdraw a b -1)) lst (cdr lst)) (car (setq lst (cons (getpoint "\nPick Next Point: " (car lst)) lst))) ) (if (LM:Clockwise-p (caddr lst) (cadr lst) (car lst)) (princ "\n--> You Turned Right! -->") (princ "\n<-- You Turned Left! <--") ) ) ) (redraw) (princ) ) Quote
Tharwat Posted June 6, 2011 Posted June 6, 2011 I am not sure , but it is nice idea . (defun c:foo (/ p p1) (if (setq p (getpoint "\n First point :")) (while (setq p1 (getpoint P "\n Next point :")) (if (> (car p1) (car p)) (princ "\n You turned RIGHT Buddy .... ") (princ "\n You turned LEFT Buddy .... ") ) ) (princ) ) (princ) ) Quote
sadhu Posted June 6, 2011 Author Posted June 6, 2011 Thank you Lee. It works perfectly. You have a great web site too. Quote
irneb Posted June 6, 2011 Posted June 6, 2011 Tharwat, yours is checking if the new point's X value is larger than the previous point. What happens if your line was going downwards and you now go to the left? Your code will show it as turned right. The basic idea is you need 3 points to calculate - the 1st & 2nd to get the angle thus far, and then see if the angle goes larger (left) or smaller (right) to the 3rd point. Quote
sadhu Posted June 6, 2011 Author Posted June 6, 2011 Tharwat : I tried your code but didn't get the result I wanted. Good try and thanks. Quote
Lee Mac Posted June 6, 2011 Posted June 6, 2011 Thank you Lee. It works perfectly. You have a great web site too. Thanks Sadhu I'm really glad you like my site too Quote
Tharwat Posted June 6, 2011 Posted June 6, 2011 Tharwat, yours is checking if the new point's X value is larger than the previous point. What happens if your line was going downwards and you now go to the left? Your code will show it as turned right. The basic idea is you need 3 points to calculate - the 1st & 2nd to get the angle thus far, and then see if the angle goes larger (left) or smaller (right) to the 3rd point. Thanks a lot irneb . You're right , I did not think of it that way , and that why codes were a little bit poor with one side checking (the x value). Regards. Quote
irneb Posted June 6, 2011 Posted June 6, 2011 Thanks a lot irneb . You're right , I did not think of it that way , and that why codes were a little bit poor with one side checking (the x value). Regards. No prob, I could see you had an idea of what to do. :wink: Quote
BIGAL Posted June 7, 2011 Posted June 7, 2011 You may want to revert back to first principles of a line and another point the first two points "line" give an angle of direction and the point is then left or right depending on the original direction. This also means when upside down your left is right, but it is correct. Having done stuff for designing house walls which way is inside. You can use the vl-curve-getclosestpointo command to calculate closet pt at sq off and get new angle so know R & L. this has an advantage if your pick point is not sq to previous line. you can elaborate this by picking an existing line depending on end picked this gives angle direction accepted as start end hence only need two picks. Quote
Lee Mac Posted June 7, 2011 Posted June 7, 2011 You can use the vl-curve-getclosestpointo command to calculate closet pt at sq off and get new angle so know R & L. this has an advantage if your pick point is not sq to previous line. you can elaborate this by picking an existing line depending on end picked this gives angle direction accepted as start end hence only need two picks. But this method requires the creation of entities to use the curve functions with - it is much easier to just use the point data. Quote
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.