Halsy Posted April 15, 2022 Posted April 15, 2022 Hii Everyone i have to find the angle between two 3d point HERE IS MY CODE (defun c:foo () (setq p1 (getpoint "\n1st:") p2 (getpoint "\n2nd:") ) (setq ang (angle (trans P1 1 2)(trans P2 0 2)) ) ) but this code does not give the correct angle between point Quote
mhupp Posted April 15, 2022 Posted April 15, 2022 This is a good read. https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/angle-between-3d-points-polyline-vertices/m-p/10596320/highlight/true#M419780 Quote
Halsy Posted April 16, 2022 Author Posted April 16, 2022 Actually I need to calculate angle between only 2 point If user select 2 point (i.e point1 and point2) then angle has to come 90 degree And angle between point p2 and point 3 has to come 0 degree And angle between point p3 and point p2 180 degree Quote
Stefan BMR Posted April 16, 2022 Posted April 16, 2022 2 points define a line and only one. In 2d, an angle is defined by 2 lines in the same plane. angle function always project the 2 points in the xOy plan. angle function assumes the first line as Ox and second as the line defined by the 2 given points. So, "Angle between two 3D points" has no meaning at all. You have to define the projection plan. Quote
Halsy Posted April 16, 2022 Author Posted April 16, 2022 Angle function is used to find angle between point which lies in xy plane but what about the point which is lies in xz and yz plane And how to measure the angle between them Quote
Stefan BMR Posted April 16, 2022 Posted April 16, 2022 59 minutes ago, Halsy said: Angle function is used to find angle between point which lies in xy plane but what about the point which is lies in xz and yz plane And how to measure the angle between them Define your second line. In 3D, you can get infinite number of angles, depending of this second line definition. (This is true for 2D too, but considering Ox axis as reference, there is only one possibility) It seems you know the angle in your code is wrong, so you know what this angle should be. If you cannot describe the problem better, then upload a dwg and explain the desired output. 1 Quote
lrm Posted April 16, 2022 Posted April 16, 2022 10 hours ago, Halsy said: Angle function is used to find angle between point which lies in xy plane but what about the point which is lies in xz and yz plane And how to measure the angle between them The ANGLE function determines the angle formed by a line passing through two points and the X WCS axis. To find the angle between two lines that may be at any orientation in 3D space define two unit vectors, v1 from from point 1 to point 2, and v2, from point 1 to point 3. Then take the arc-cosine of the dot product of the two vectors for the true angle. 2 1 Quote
lrm Posted April 20, 2022 Posted April 20, 2022 Here's a program to calculate the angle between two line defined by three points. (defun c:3dangle (/ p1 p2 p3 v1 v2 angrad angdeg) (setq p1 (getpoint "\nPick point common to both lines.") p2 (getpoint p1 "\nPick end of first line.") p3 (getpoint p1 "\nPick end of second line.") v1 (uvec (mapcar '- p2 p1)) v2 (uvec (mapcar '- p3 p1)) angrad (@acos (dot v1 v2)) angdeg (/ (* angrad 180.) 3.14159265359) ) (princ "\nAngle between the two lines (degrees): ") (princ angdeg) (princ) ) ;;------------------------------------------------------ ;; Function to return the arccos of an angle in radians: ;; author unknown (defun @acos (cosine / sine) (cond ((zerop cosine)(* pi 0.5)) ((<= cosine -1.0) pi) ((>= cosine 1.0) 0.0) (1 (atan (/ (sqrt (- 1.0 (expt cosine 2))) cosine))) ) ) ;;------------------------------------------------------ ;;; Compute the dot product of 2 vectors a and b (defun dot (a b / dd) (setq dd (mapcar '* a b)) (setq dd (+ (nth 0 dd) (nth 1 dd) (nth 2 dd))) ) ;end of dot ;;------------------------------------------------------ ; calculate unit vector of vector v1 (defun uvec (v1 / s) (setq s (distance '(0 0 0) v1 )) (setq s (mapcar '/ v1 (list s s s))) ) 2 1 Quote
Halsy Posted April 22, 2022 Author Posted April 22, 2022 is it possible to find angle between 2 point without referring common point?? Quote
lrm Posted April 22, 2022 Posted April 22, 2022 Two points define one line. To find an angle between two lines you need another line stated either explicitly or implicitly. The lisp function angle assume implicitly that the "other" line is the x axis. What assumption would you like to make about the other line if only given two points? A program could output, for example, the angles between the line defined by two points with the world X axis, Y axis and Z axis. It could also output the angle with it projection onto one of the principal planes (e.g., the XY plane) or... What do you need? Be as detailed as possible. 1 Quote
exceed Posted April 25, 2022 Posted April 25, 2022 (edited) There is p3 in the picture saying you only need 2 points. this confused me. haha "If user select 2 point (i.e point1 and point2) then angle has to come 90 degree = this is xz plane And angle between point p2 and point 3 has to come 0 degree = this is rotated xz plane. And angle between point p3 and point p2 180 degree" = this is rotated xz plane. > this is second confused point. if p2 -> p1 in 2nd and 3rd line. there 3 lines explain just 1 xz plane. "Angle function is used to find angle between point which lies in xy plane but what about the point which is lies in xz and yz plane And how to measure the angle between them" > If this is what you meant to say, there is a simple way. ; get angle anyway - 2022.04.25 exceed ; measures the angle between 2 points projected on the xy yz xz planes. (defun c:getangleanyway ( / p1 p2 p1x p1y p1z p2x p2y p2z xyang yzang xzang) (princ "\n measures the angle between 2 points projected on the xy yz xz planes.") (setq p1 (getpoint "\n pick 1st point :")) (setq p2 (getpoint "\n pick 2nd point :")) (setq p1x (car p1)) (setq p1y (cadr p1)) (setq p1z (caddr p1)) (setq p2x (car p2)) (setq p2y (cadr p2)) (setq p2z (caddr p2)) (setq xyang (angle (list p1x p1y) (list p2x p2y))) (setq yzang (angle (list p1y p1z) (list p2y p2z))) (setq xzang (angle (list p1x p1z) (list p2x p2z))) (princ "\n xy angle = ") (princ xyang) (princ " (= ") (princ (/ (* xyang 180.0) pi)) (princ " degree)") (princ "\n yz angle = ") (princ yzang) (princ " (= ") (princ (/ (* yzang 180.0) pi)) (princ " degree)") (princ "\n xz angle = ") (princ xzang) (princ " (= ") (princ (/ (* xzang 180.0) pi)) (princ " degree)") (princ) ) in others way, If you want to measure an angle from two 3d points, you can make a plane from it by specifying the 3rd point make 2 vectors from the 3rd common point, and then get the angle between them. because an angle must have three points. but I think you mean something simpler. so this Lisp separates the x, y, z values of 2 points and when measuring the xy angle, only input the x and y values to "angle" and when measuring the yz angle, only input the y and z values to "angle" and when measuring the xz value, only input the x and z values to "angle" If "angle" only works for x and y, so put the y and z values there x and y position. this is a projection. Edited April 25, 2022 by exceed 1 1 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.