Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

3D extrusion vector for trans parameter using three 3D points

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
365 Views, 4 Replies

3D extrusion vector for trans parameter using three 3D points

hi,
could anyone help me with this? i've browsed around but i'm not finding the exact answer - i want to change my ucs so that the new XY plane is defined by three 3D points. then find p1local which is p1 translated into the new UCS.

one way to do this is:
(command "UCS" "N" "3" p1 p2 p3)
(setq p1local (trans p1 0 1))

instead of above which takes super-long, i want to find the 3D extrusion vector to pass into trans so that i can do (setq p1local (trans p1 '(0 0 1) v1)) where v1 is the unit vector normal to the plane defined by p1 p2 and p3. I think I'm getting the normal correctly (shown below) but when i pass this vector into trans function, it doesn't work - this does not seem to be the "3D extrusion vector" that trans wants as a parameter even though thet fact that '(0 0 1) is 3D extrusion vectorfor WCS hints that it could be. does this have anything to do with that the new UCS origin is always (0 0 0)?
can anyone tell me how i can calculate vector1 in (trans p1 '(0 0 1) vector1) to get p1local?

thank you in advance,

;; kat park 2006
(defun C:getNormal ( Point1 Point2 Point3 )

(setq Edge1 (vectorDiff Point2 Point1)
Edge2 (vectorDiff Point3 Point1))

(setq crossed (cross-product Edge1 Edge2))
(setq normVal (vectorNorm crossed))
(setq unitVector (list (/ (car crossed) normVal)
(/ (cadr crossed) normVal)
(/ (caddr crossed) normVal)))
(eval 'unitVector)
)

; vector norm (length)
(defun vectorNorm (Point1)
(eval '(sqrt (+ (expt (car Point1) 2.0)
(expt (cadr Point1) 2.0)
(expt (caddr Point1) 2.0))))
)

; vector cross-product
; A x B = (Ay*Bz - Az*By) (Az*Bx - Ax*Bz) (Ax*By - Ay*Bx)
(defun cross-product (Point1 Point2)
(eval '(list (- (* (cadr Point1) (caddr Point2)) (* (caddr Point1) (cadr Point2)))
(- (* (caddr Point1) (car Point2)) (* (car Point1) (caddr Point2)))
(- (* (car Point1) (cadr Point2)) (* (cadr Point1) (car Point2)))))
)

; subtract vector
; A - B = (Ax - Bx) (Ay - By) (Az - Bz)
(defun vectorDiff (Point1 Point2)
(eval '(list (- (car Point1) (car Point2))
(- (cadr Point1) (cadr Point2))
(- (caddr Point1) (caddr Point2)) ))
)
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Hi ,

The extrusion vector option of trans is useful for defining an OCS, but
cannot be relied upon for just any random UCS. As it sounds like you know,
a single extrusion vector does not fully define a coordinate system. So
when you supply only an extrusion vector to trans it fills in the blanks
using the Arbitrary Axis Algorithm described in the DXF Reference. In other
words it uses the single OCS corresponding to the supplied vector, not
necessarily the UCS you intend it to. To my knowledge there is not a built
in function to translate coordinates to a random UCS without actually
presetting it current. However, you could make your own replacement for the
trans function that works how you want it to, or adapt or use similar
functions that have been posted in this newsgroup. Which direction do you
want to go with it?
--
James Allen, EIT
Malicoat-Winslow Engineers, P.C.
Columbia, MO


wrote in message news:5161379@discussion.autodesk.com...
hi,
could anyone help me with this? i've browsed around but i'm not finding
the exact answer - i want to change my ucs so that the new XY plane is
defined by three 3D points. then find p1local which is p1 translated into
the new UCS.

one way to do this is:
(command "UCS" "N" "3" p1 p2 p3)
(setq p1local (trans p1 0 1))

instead of above which takes super-long, i want to find the 3D extrusion
vector to pass into trans so that i can do (setq p1local (trans p1 '(0 0 1)
v1)) where v1 is the unit vector normal to the plane defined by p1 p2 and
p3. I think I'm getting the normal correctly (shown below) but when i pass
this vector into trans function, it doesn't work - this does not seem to be
the "3D extrusion vector" that trans wants as a parameter even though thet
fact that '(0 0 1) is 3D extrusion vectorfor WCS hints that it could be.
does this have anything to do with that the new UCS origin is always (0 0
0)?
can anyone tell me how i can calculate vector1 in (trans p1 '(0 0 1)
vector1) to get p1local?

thank you in advance,

;; kat park 2006
(defun C:getNormal ( Point1 Point2 Point3 )

(setq Edge1 (vectorDiff Point2 Point1)
Edge2 (vectorDiff Point3 Point1))

(setq crossed (cross-product Edge1 Edge2))
(setq normVal (vectorNorm crossed))
(setq unitVector (list (/ (car crossed) normVal)
(/ (cadr crossed) normVal)
(/ (caddr crossed) normVal)))
(eval 'unitVector)
)

; vector norm (length)
(defun vectorNorm (Point1)
(eval '(sqrt (+ (expt (car Point1) 2.0)
(expt (cadr Point1) 2.0)
(expt (caddr Point1) 2.0))))
)

; vector cross-product
; A x B = (Ay*Bz - Az*By) (Az*Bx - Ax*Bz) (Ax*By - Ay*Bx)
(defun cross-product (Point1 Point2)
(eval '(list (- (* (cadr Point1) (caddr Point2)) (* (caddr Point1) (cadr
Point2)))
(- (* (caddr Point1) (car Point2)) (* (car Point1) (caddr Point2)))
(- (* (car Point1) (cadr Point2)) (* (cadr Point1) (car Point2)))))
)

; subtract vector
; A - B = (Ax - Bx) (Ay - By) (Az - Bz)
(defun vectorDiff (Point1 Point2)
(eval '(list (- (car Point1) (car Point2))
(- (cadr Point1) (cadr Point2))
(- (caddr Point1) (caddr Point2)) ))
)
Message 3 of 5
Anonymous
in reply to: Anonymous

Hi James - thanks for the reply. I remember reading about the arbitrary axis algorithm but your explanation totally clarifies everything. the other routes you're mentioning is say for example, write a transformation matrix given p1 p2 p3? this would give me p1new p2new p3new - i would have to do this with every point i want to use in the new UCS right? how would i go about writing my own trans function so that i can actually _be_ in the UCS?
Message 4 of 5
Anonymous
in reply to: Anonymous

Yes, you write the matrix once and then use it to transform each point using
matrix multiplication. The trans function both derives the matrix and
applies it to the supplied point every time you use it, so you could
actually improve performance with your own if you are dealing with a
multiple points.

With the code you've already posted, you've nearly got the matrix in hand.
Then you just need code to multiply a point by a matrix. Let me know if you
are interested, and I will post a couple of my functions. In the meantime,
search the newsgroup for @PTrans and MWE:TransformBlocks for a lot of
related sample code already posted.



wrote in message news:5161652@discussion.autodesk.com...
Hi James - thanks for the reply. I remember reading about the arbitrary axis
algorithm but your explanation totally clarifies everything. the other
routes you're mentioning is say for example, write a transformation matrix
given p1 p2 p3? this would give me p1new p2new p3new - i would have to do
this with every point i want to use in the new UCS right? how would i go
about writing my own trans function so that i can actually _be_ in the UCS?
Message 5 of 5
Anonymous
in reply to: Anonymous

Did you get it working?
--
James Allen, EIT
Malicoat-Winslow Engineers, P.C.
Columbia, MO


wrote in message news:5161652@discussion.autodesk.com...
Hi James - thanks for the reply. I remember reading about the arbitrary axis
algorithm but your explanation totally clarifies everything. the other
routes you're mentioning is say for example, write a transformation matrix
given p1 p2 p3? this would give me p1new p2new p3new - i would have to do
this with every point i want to use in the new UCS right? how would i go
about writing my own trans function so that i can actually _be_ in the UCS?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost