Author Topic: Line normal to plane  (Read 2414 times)

0 Members and 1 Guest are viewing this topic.

Kate M

  • Guest
Line normal to plane
« on: October 23, 2006, 02:16:53 PM »
Hey gurus,

I'm trying to draw a line normal to a plane, defined by picking three points. The line would have a picked start point and a preset length. I'd hoped this would be possible without programming, but it seems like way too much work that way, since I'll have to do it over and over. :roll:

I found this bit of code from gile:
Code: [Select]
;;; NORM_3PTS Returns the normal vector of the plane defined by 3 points (from Swamp user gile)
;;; Respects the "right hand rule" with p0 as origin
(defun norm_3pts (p0 p1 p2 / norm)
  (cond
    ((inters p0 p1 p0 p2)
     (foreach p '(p1 p2)
       (set p (mapcar '- (eval p) p0))
     )
     (setq norm (list (- (* (cadr p1) (caddr p2)) (* (caddr p1) (cadr p2)))
      (- (* (caddr p1) (car p2)) (* (car p1) (caddr p2)))
      (- (* (car p1) (cadr p2)) (* (cadr p1) (car p2)))
)
   norm (mapcar '(lambda (x) (* x (/ 1 (distance '(0 0 0) norm))))
norm
)
     )
    )
  )
)

But now I don't know what to do with it. Can somebody point me in the right direction? (oy -- no pun intended)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Line normal to plane
« Reply #1 on: October 24, 2006, 09:46:28 AM »
I'm not a 3D guy so there may be a better way, but this is how I would do it.
At the command line enter UCS 3
Pick the points to define the new plane


Draw the line
Pick the starting point of the line
Then use the 'Relative Coordinates'   @0,0,<your line length>

This will draw a line in the Z direction of the length you desire.

Code: [Select]
Command: ucs

Current ucs name:  *NO NAME*
Enter an option [New/Move/orthoGraphic/Prev/Restore/Save/Del/Apply/?/World]
<World>: 3

Specify new origin point <0,0,0>:
Specify point on positive portion of X-axis <0'-1",0'-0",0'-0">:
Specify point on positive-Y portion of the UCS XY plane <0'-0",0'-1",0'-0">:
Command:
Command: _line Specify first point:
Specify next point or [Undo]: @0,0,25
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Line normal to plane
« Reply #2 on: October 24, 2006, 09:49:08 AM »
Hi,

To calculate the line's end point coordinates, you have to make the product of each coordinate of the one unit vector returned by Norm_3Pts by the line's length (len). Then add this vector to the start point (dep) ;

Code: [Select]
(mapcar '(lambda (x1 x2)
   (+ x1 (* x2 len))
)
dep
(norm_3pts p0 p1 p2)
)

Here's an example :

Code: [Select]
(defun c:normal_line (/ p0 p1 p2 dep len)
  (vl-load-com)
  (prompt "\nSpecify 3 points to define the plane.")
  (setq p0 (getpoint "\nFirst point: "))
  (setq p1 (getpoint "Second point: "))
  (setq p2 (getpoint "Third point: "))
  (setq dep (getpoint "\nSpecify the line start point: "))
  (setq len (getdist dep "\nSpecify the line's length: "))
  (vla-addLine
    (vla-get-ModelSpace
      (vla-get-ActiveDocument (vlax-get-acad-object))
    )
    (vlax-3d-point (trans dep 1 0))
    (vlax-3d-point
      (trans (mapcar '(lambda (x1 x2)
(+ x1 (* x2 len))
      )
     dep
     (norm_3pts p0 p1 p2)
     )
     1
     0
      )
    )
  )
  (princ)
)
Speaking English as a French Frog

Kate M

  • Guest
Re: Line normal to plane
« Reply #3 on: October 24, 2006, 09:56:01 AM »
CAB, thanks for the UCS reminder. I'd forgotten about the 3 points option. I may be able to work with that...

Gile, how do I get your normal_line routine to find the norm_3pts routine? Do they have to be in the same file, or point to each other somehow?

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Line normal to plane
« Reply #4 on: October 24, 2006, 10:04:01 AM »
Kate,

It doesn't matter, the two codes can be copied in the same file or in two different files.
The file(s) have to be loaded (one or both)
Speaking English as a French Frog

Kate M

  • Guest
Re: Line normal to plane
« Reply #5 on: October 24, 2006, 10:07:33 AM »
I keep getting a "no function definition" error, whether they're in the same file or not.

When they're in the same file it looks like this:
Code: [Select]
(defun c:normal_line (/ p0 p1 p2 dep len)
  (vl-load-com)
  (prompt "\nSpecify 3 points to define the plane.")
  (setq p0 (getpoint "\nFirst point: "))
  (setq p1 (getpoint "Second point: "))
  (setq p2 (getpoint "Third point: "))
  (setq dep (getpoint "\nSpecify the line start point: "))
  (setq len (getdist dep "\nSpecify the line's length: "))
  (vla-addLine
    (vla-get-ModelSpace
      (vla-get-ActiveDocument (vlax-get-acad-object))
    )
    (vlax-3d-point (trans dep 1 0))
    (vlax-3d-point
      (trans (mapcar '(lambda (x1 x2)
(+ x1 (* x2 len))
      )
     dep
     (norm_3pts p0 p1 p2)
     )
     1
     0
      )
    )
  )
  (princ)
)

;;; NORM_3PTS Returns the normal vector of the plane defined by 3 points
;;; Respects the "right hand rule" with p0 as origin
(defun c:norm_3pts (p0 p1 p2 / norm)
  (cond
    ((inters p0 p1 p0 p2)
     (foreach p '(p1 p2)
       (set p (mapcar '- (eval p) p0))
     )
     (setq norm (list (- (* (cadr p1) (caddr p2)) (* (caddr p1) (cadr p2)))
      (- (* (caddr p1) (car p2)) (* (car p1) (caddr p2)))
      (- (* (car p1) (cadr p2)) (* (cadr p1) (car p2)))
)
   norm (mapcar '(lambda (x) (* x (/ 1 (distance '(0 0 0) norm))))
norm
)
     )
    )
  )
)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Line normal to plane
« Reply #6 on: October 24, 2006, 10:31:03 AM »
You wouldn't replace (defun norm_3pts ...) by (defun c:norm_3pts ...).

Norm_3pts is a routine to be called by other functions, not a command function.
« Last Edit: October 24, 2006, 10:32:34 AM by gile »
Speaking English as a French Frog

Kate M

  • Guest
Re: Line normal to plane
« Reply #7 on: October 24, 2006, 01:28:59 PM »
Whoops -- I was messing around with that before I realized it was meant to be called by something else...guess I forgot to put it back. :angel:

Thanks for the assistance...slowly but surely "learning to fish." 8-)

deegeecees

  • Guest
Re: Line normal to plane
« Reply #8 on: October 24, 2006, 01:47:01 PM »
If you have an entity on the plane you wish to draw perp or parallel, try UCS -> E