JONTHEPOPE Posted December 9, 2010 Posted December 9, 2010 I quite enjoy this web site and using autolisp code. Does any one know a way i can write a simple code using formula y=mx+b or any other type of graphing calculations? Thanks jtp Quote
Lee Mac Posted December 10, 2010 Posted December 10, 2010 This will graph most functions: http://www.cadtutor.net/forum/showthread.php?53014-Drawing-Sine-Cosine-Waves-Any-thoughts&p=358974&viewfull=1#post358974 Use the function: (setq fun (lambda ( x ) (+ (* m x) c))) For arbitrary values of m & c. Quote
pBe Posted December 10, 2010 Posted December 10, 2010 Lee Mac, How would you write this code? (defun c:testL (/ L1 L2 1data 2data 1A 1B 2A 2B s_t X1 X2 X3 X4 line_distance) (while (not (and (setq L1 (car (entsel "\nSelect a Line: ")) L2 (car (entsel "\nSelect another Line: ")) ) ) ) ) (cond ((setq 1data (entget L1) 2data (entget L2) 1A (cdr (assoc 10 1data)) ; start of first Line 1B (cdr (assoc 11 1data)) ; end of first Line 2A (cdr (assoc 10 2data)) ; start of second Line 2B (cdr (assoc 11 2data)) ; end of second Line s_t 0 ) (repeat 3 (setq x1 (nth s_t 1A) x2 (nth s_t 1B) x3 (nth s_t 2A) x4 (nth s_t 2B) ) (setq vts (/ (* (abs (- x3 x1)) (* (abs (- x2 x1)) (abs (- x4 x3))) ) (* (abs (- x2 x1)) (abs (- x4 x3))) ) ) (set (setq vv (read (strcat "D" (itoa (+ s_t 1))))) vts) (setq s_t (1+ s_t)) ) (setq line-distance (sqrt (+ (* d1 d1) (* d2 d2) (* d3 d3)))) (princ) ) ) ) Its an equation for getting shortest distance between two skew lines... somehow i'm not getting the results i need.. This part is where i'm not sure (formula) (setq line-distance (sqrt (+ (* d1 d1) (* d2 d2) (* d3 d3)))) Math... arrrgh Quote
Lee Mac Posted December 10, 2010 Posted December 10, 2010 Something like this? ;; Minimum Distance between Skew Lines l1 & l2 - Lee Mac 2010 (defun LM:MinDistance ( l1 l2 ) ( (lambda ( a b c d ) (abs (vxv (mapcar '- d b) (unit (v^v (mapcar '- b a) (mapcar '- d c))))) ) (cdr (assoc 10 (setq l1 (entget l1)))) (cdr (assoc 11 l1)) (cdr (assoc 10 (setq l2 (entget l2)))) (cdr (assoc 11 l2)) ) ) ;; Vector Dot Product - Lee Mac 2010 ;; Args: u,v - vectors in R^n (defun vxv ( u v ) (apply '+ (mapcar '* u v)) ) ;; Vector Cross (Wedge) Product - Lee Mac 2010 ;; Args: u,v - vectors in R^3 (defun v^v ( u v ) (list (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u))) (- (* (car v) (caddr u)) (* (car u) (caddr v))) (- (* (car u) (cadr v)) (* (car v) (cadr u))) ) ) ;; Unit Vector - Lee Mac 2010 ;; Args: v - vector in R^n (defun unit ( v ) ( (lambda ( n ) (if (equal 0.0 n 1e-14) nil (vxs v (/ 1.0 n)))) (norm v)) ) ;; Vector x Scalar - Lee Mac 2010 ;; Args: v - vector in R^n, s - real scalar (defun vxs ( v s ) (mapcar '(lambda ( n ) (* n s)) v) ) ;; Vector Norm - Lee Mac 2010 ;; Args: v - vector in R^n (defun norm ( v ) (sqrt (apply '+ (mapcar '* v v))) ) Each line can lie in infinitely many planes, but only two of these are parallel to each other in 3-space, so taking the cross product of the two direction vectors of the lines we can find the normal vector to these parallel planes. Then, we can project any vector between the two planes to the unit normal using the dot product to get the shortest distance. This may be of help to you: http://lee-mac.com/mathematicalfunctions.html Lee Quote
pBe Posted December 12, 2010 Posted December 12, 2010 Something like this? ;; Minimum Distance between Skew Lines l1 & l2 - Lee Mac 2010.... Each line can lie in infinitely many planes, but only two of these are parallel to each other in 3-space, so taking the cross product of the two direction vectors of the lines we can find the normal vector to these parallel planes. Then, we can project any vector between the two planes to the unit normal using the dot product to get the shortest distance. This may be of help to you: http://lee-mac.com/mathematicalfunctions.html Lee Oh yeah... thanks Lee 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.