samifox Posted August 4, 2015 Share Posted August 4, 2015 hi how can i tell if 3 points form a corner? what about giving it some tolerance? lets say its still a corner if it didn't exceed 80-100 degrees range? Thanks Shay Quote Link to comment Share on other sites More sharing options...
jonathann3891 Posted August 4, 2015 Share Posted August 4, 2015 Can you clarify? Quote Link to comment Share on other sites More sharing options...
samifox Posted August 4, 2015 Author Share Posted August 4, 2015 lets say i have a list containing those 3 points, i want it to tell me if they form a 90 degree corner, and if its still between 80 to 100 degree, its ok..ill take it as a rorner as well :P:P Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 4, 2015 Share Posted August 4, 2015 There are many ways to approach the task, here is one: (defun corner-p ( p1 p2 p3 ) (equal 0.0 (apply '+ (mapcar '* (mapcar '- p3 p2) (mapcar '- p1 p2))) 1e- ) Here's another: (defun corner-p ( p1 p2 p3 ) (equal 0.0 (cos (- (angle p2 p1) (angle p2 p3))) 1e- ) And another: (defun corner-p ( p1 p2 p3 ) ((lambda ( v ) (equal (caddr (trans p2 0 v)) (caddr (trans p3 0 v)) 1e-) (mapcar '- p1 p2)) ) Quote Link to comment Share on other sites More sharing options...
samifox Posted August 5, 2015 Author Share Posted August 5, 2015 There are many ways to approach the task, here is one: (defun corner-p ( p1 p2 p3 ) (equal 0.0 (apply '+ (mapcar '* (mapcar '- p3 p2) (mapcar '- p1 p2))) 1e- ) Here's another: (defun corner-p ( p1 p2 p3 ) (equal 0.0 (cos (- (angle p2 p1) (angle p2 p3))) 1e- ) And another: (defun corner-p ( p1 p2 p3 ) ((lambda ( v ) (equal (caddr (trans p2 0 v)) (caddr (trans p3 0 v)) 1e-) (mapcar '- p1 p2)) ) Thanks Lee 1-e8 is the thing that im afraid of.... i assume that (equal a b 1-e8) is the tolerance i asked for, but how can i translate it to degree range(aka limit 80 to 100 degrees)? ? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 5, 2015 Share Posted August 5, 2015 Thanks Lee You're welcome. 1-e8 is the thing that im afraid of.... i assume that (equal a b 1-e8) is the tolerance i asked for, but how can i translate it to degree range(aka limit 80 to 100 degrees)? ? 1e-8 (0.00000001) is indeed the tolerance used for each comparison, however, this tolerance will represent different quantities depending on the method used. For example, the first method uses the vector dot product of the two vectors, therefore the tolerance will be a factor of the lengths of the two vectors and the cosine of the angle between them (since a·b = |a||b|cosθ); the tolerance used in the second method will also be a factor of the cosine of the angle between the two vectors (but not dependent on the vector length); finally, in the third method, the tolerance represents the linear distance between point p2 and the projection of point p3 onto the line p1-p2. Quote Link to comment Share on other sites More sharing options...
samifox Posted August 5, 2015 Author Share Posted August 5, 2015 You're welcome. 1e-8 (0.00000001) is indeed the tolerance used for each comparison, however, this tolerance will represent different quantities depending on the method used. For example, the first method uses the vector dot product of the two vectors, therefore the tolerance will be a factor of the lengths of the two vectors and the cosine of the angle between them (since a·b = |a||b|cosθ); the tolerance used in the second method will also be a factor of the cosine of the angle between the two vectors (but not dependent on the vector length); finally, in the third method, the tolerance represents the linear distance between point p2 and the projection of point p3 onto the line p1-p2. First of all, i want to say that i love u Lee !!! if i ever come to London im sure gonna meet you (if u will) second...continue the interesting relationships ratio....i still cant simplify it to a parameter that say... (if (and (the following 3 points form a corner) ( (the corner not exceed minimum of 80 degrees) (the corner not exceed maximum of 100 degrees) ) (princ "the corner is ok") (princ "cant accept that corner due to limit violation") ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 5, 2015 Share Posted August 5, 2015 That's very kind of you to say. Since the cosine function is periodic with roots at pi/2, 3pi/2 etc it suffices to test whether the cosine of the angle between the vectors lies within a given range of the root, e.g.: (defun corner-p ( p1 p2 p3 tol ) (equal 0.0 (cos (- (angle p2 p1) (angle p2 p3))) (cos (+ (/ pi 2) tol))) ) So, for 10 degrees either way: (corner-p (getpoint) (getpoint) (getpoint) (* pi (/ 10.0 180.0))) 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.