Jump to content

Recommended Posts

Posted

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

Posted

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 :x

Posted

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

Posted
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 :)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...