2D vss 3D vss nD...

Discussion in 'AutoCAD' started by David Kozina, Feb 18, 2004.

  1. David Kozina

    David Kozina Guest

    I found out yesterday that trying to make a variant with set of 3D points
    (unwittingly) that should have been 2D and then use that variant to create a
    LightweightPolyline object didn't have the outcome I quite expected.

    "What the...?!" :-@

    I tracked down the trouble in a 'Point/Vector addition' subroutine, which
    automatically converted and then later output my 2D point list to a 3D point
    list - which wasn't what I wanted to do in this case. I fixed it for this
    particular problem, but I think it could be better.

    So I was wondering what you people do to keep the dimensions correct - and
    *especially* if you may be working with 'mixed dimension types', such as
    adding a 2D xy vector to a set of 3D xyz points. If you use mapcar '+ for
    this, you end up with a 2D pointlist when perhaps you really need those z
    values.

    When doing this type of point manipulation, have you found it best to
    define/use a series of routines, like '1dVectorAdd', '2dVectorAdd',
    '3dVectorAdd', etc. - OR - would it be better to create and use one routine
    'VectorAdd', along with a desired output 'dimension' argument, perhaps like
    (VectorAdd _vec _pts 2) - so that no matter *what* the input vector or point
    list dimension happens to be, the output will be as indicated?

    I'm leaning toward the second, since it seems to be a more 'all-encompasing'
    solution (and fewer routines to keep track of), but I don't know if that
    neccessarily results in better - faster/more readable/etc. - or worse code.

    If this seems like a silly question or just a rehash of old topics, forgive
    me, I've been gone awhile and feel a bit out of practice.

    Mind you, I'm not necessarily looking for actual code, just some
    opinions/reasons on what you consider to be good coding practice for this
    sort of thing.

    Many thanks,
    David Kozina
     
    David Kozina, Feb 18, 2004
    #1
  2. David Kozina

    BillZ Guest

    BillZ, Feb 18, 2004
    #2
  3. I keep my points as lists until I get to the point where I *need* the array.
    At that point (groan!) I create the array for the subsequent statement and
    then forget about the array.

    --
    R. Robert Bell, MCSE
    www.AcadX.com


    I found out yesterday that trying to make a variant with set of 3D points
    (unwittingly) that should have been 2D and then use that variant to create a
    LightweightPolyline object didn't have the outcome I quite expected.

    "What the...?!" :-@

    I tracked down the trouble in a 'Point/Vector addition' subroutine, which
    automatically converted and then later output my 2D point list to a 3D point
    list - which wasn't what I wanted to do in this case. I fixed it for this
    particular problem, but I think it could be better.

    So I was wondering what you people do to keep the dimensions correct - and
    *especially* if you may be working with 'mixed dimension types', such as
    adding a 2D xy vector to a set of 3D xyz points. If you use mapcar '+ for
    this, you end up with a 2D pointlist when perhaps you really need those z
    values.

    When doing this type of point manipulation, have you found it best to
    define/use a series of routines, like '1dVectorAdd', '2dVectorAdd',
    '3dVectorAdd', etc. - OR - would it be better to create and use one routine
    'VectorAdd', along with a desired output 'dimension' argument, perhaps like
    (VectorAdd _vec _pts 2) - so that no matter *what* the input vector or point
    list dimension happens to be, the output will be as indicated?

    I'm leaning toward the second, since it seems to be a more 'all-encompasing'
    solution (and fewer routines to keep track of), but I don't know if that
    neccessarily results in better - faster/more readable/etc. - or worse code.

    If this seems like a silly question or just a rehash of old topics, forgive
    me, I've been gone awhile and feel a bit out of practice.

    Mind you, I'm not necessarily looking for actual code, just some
    opinions/reasons on what you consider to be good coding practice for this
    sort of thing.

    Many thanks,
    David Kozina
     
    R. Robert Bell, Feb 18, 2004
    #3
  4. David Kozina

    David Kozina Guest

    Bill,

    Thanks for the reference - much appreciated.

    This is what I came up with for 2D<>3D point conversion, which should help
    when mapcar'd to point lists and so forth BEFORE making other arithmetic
    manipulations, like adding a 2d vector to a 3d point list, or before
    creating an array function.

    Does anyone/everyone have other suggestions for improvement?

    ; force a 2D or 3D point to a specific dimension
    (defun ForceDPt
    (_pt ; xy or xyz point
    dims ; number of dimensions (2 or 3) for output
    /
    )
    ; begin
    ; ...determine dimension
    (if (eq dims 3)
    ; then
    ; ...is point 3D?
    (if (caddr _pt)
    ; then return it as is
    _pt
    ; else add z=0 value
    (reverse (cons 0 (reverse _pt)))
    );_end if
    ; else
    ; ...is point 3D?
    (if (caddr _pt)
    ; then return xy portion
    (list (car _pt) (cadr _pt))
    ; else return it as is
    _pt
    );_end if
    );_end if
    ; end
    );_end defun
     
    David Kozina, Feb 18, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.