Author Topic: vector/matrix functions for acad  (Read 6033 times)

0 Members and 1 Guest are viewing this topic.

Dnereb

  • Guest
Re: vector/matrix functions for acad
« Reply #15 on: December 07, 2007, 01:38:16 PM »
@Ml

I agree your option to use a double array in an UDT is very elegant.
and for compatibility I don't worry aboout RtlMoveMemory it's an windows Api and i've never heard of a
officially documented api that was made redundant.
So i was in doubt... do i prefer the oopy UDT (I prefer OOP in general) or is an array better in this case.

@All Readers
I saw Bryco's post and it made me think... I've expanded his test a bit to see about other techniques...
Option Explicit

Code: [Select]
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, Source As Any, ByVal numBytes As Long)


Type Point3d
    Coord(0 To 3) As Double
End Type

Sub PassTheDoubly()

    Dim P1(2) As Double
    Dim P2(2) As Double
    Dim P3() As Double
    Dim Udt1 As Point3d
    Dim Udt2 As Point3d
   
   
    Dim V As Variant
    Dim i As Long, j As Integer
    Dim T As Single
   
    'Walking through the items one by one
    T = Timer
    P1(0) = 223: P1(1) = 123: P1(2) = 323
    Udt1.Coord(0) = 223: Udt1.Coord(1) = 123: Udt1.Coord(2) = 323
    For i = 0 To 10000000
        For j = 0 To 2
            P2(j) = P1(j)
        Next j
    Next i
    Debug.Print "double time by element = " & Timer - T
   
    'Using a variant
    T = Timer
    For i = 0 To 10000000
      V = P1
    Next i
    Debug.Print "Var time = " & Timer - T
   
    'Using UDT's
    T = Timer
    For i = 0 To 10000000
      Udt2 = Udt1
    Next i
    Debug.Print "Udt time = " & Timer - T
     
    'Using Arrays and rtlmovememory api
   
    T = Timer
    For i = 0 To 10000000
      CopyMemory P1(0), P2(0), 24
    Next i
    Debug.Print "Rtlmovememory time = " & Timer - T
   
    'Using non dimensioned array and pass ditrectly
   
    T = Timer
    For i = 0 To 10000000
      P3() = P1()
    Next i
    Debug.Print "Direct Array passing = " & Timer - T
 
End Sub

I was aqmazed by the results:
double time by element = 5,125
Var Time = 14, 9375
Udt Time = 0, 96875
Rtlmovememory Time = 2
Direct Array passing = 13,9375

So UDT is the way to go in general.

BTW this is the first example I know of that OOPY coding is faster then straight forward coding.

edit: replaced Code Tag

MP

  • Seagull
  • Posts: 17439
Re: vector/matrix functions for acad
« Reply #16 on: December 07, 2007, 02:02:59 PM »
Cool stuff Berend, thanks for sharing your test results.

Small AR clarification, using UDTs is not OOPY. UDT vars are not objects in VBA/VB6 (they are in VB.NET merely because everything is an object, but are value types, not reference types).

Sorry, really can't help myself.

:)



Regarding variants --

My stance on variants is "Use 'em when it's the only way you can communicate to the outside world"; otherwise avoid them, especially in implementation code.



I made reference to this earlier, but I think it bears mentioning on it's own --

One needs to consider the implications techniques / data type have with regards to migration and upgrading. Variants are not supported by VB.NET. User Defined Types (UDFs) are and can be used natively, albeit the syntax has slightly changed:

Whereas VBA / VB6 and predecessors used --

Code: [Select]
Type MyContainer

    element as [DataType]

End Type

They're now (properly) referred to as Structures, and defined thusly --

Code: [Select]
Structure MyContainer

    Dim | Public | Friend | Private element As [DataType]

End Structure

Functionally, at least in cursory testing, they work similarly (i.e. once instanced), complete with element by element data copying.

:)
« Last Edit: December 07, 2007, 02:11:34 PM by MP »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Bryco

  • Water Moccasin
  • Posts: 1849
Re: vector/matrix functions for acad
« Reply #17 on: December 07, 2007, 03:57:22 PM »
Definately a cool test.
The copymemory  actually fairs worse than posted as it is only swapping one of the 3 doubles.
CopyMemory P1(0), P2(0), 24
Even though it says any in the api I couldn't get it to CopyMemory V(0), V2(0), 24

MickD

  • Gator
  • Posts: 3308
  • (x-in)->[process]->(y-out)
Re: vector/matrix functions for acad
« Reply #18 on: December 07, 2007, 04:56:16 PM »
As Michael said, I think udt's would be good for under the covers work but when I have to pass say a matrix to acad I  am still going to have to pass a double array as it seems a variant doesn't work.
I think I'll either have to make my returns from functions double arrays (but I'm not sure if even that worked, will experiment) or use Variants and write a quite assign to array function or similar. Either way I only need to write it once even if it is tedious, I didn't think the speed between Variants and other types would differ by so much also, something to consider.

I was almost going to write classes for vecs and matrices but really, they are just arrays at the end of the day and I just need functions to work on them so why complicate things.

This is another place where Python excels, it works out the details such as these for you on the fly which is exactly what you need when scripting like this.
Beleive it or not, I was going to write some base functions in arx and write python wrappers for them and embed the interpretor in acad...but then I woke up :)

thanks All for your input.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

Dnereb

  • Guest
Re: vector/matrix functions for acad
« Reply #19 on: December 07, 2007, 05:13:03 PM »
@Mp

Granted an UDT isn't an object. It's just more structured then an array. I've used OOPY to indicate I'm aware VBA nor VB6 is a full OOP language. I'm writting or better trying to write VB.Net myself.

On the matter of using variant I agree, use them only if you have to.... something the acad object does way to often due to sloppy codding of functions.

@Bryco

A variant is a bit of a tricky thing... It can be in several states. Containing a native type, containing an array (in VB6 even arrays... Yes it's the way to make jagged arrays) Containing an object, and perhaps even diffrent on containing fixed types or variable length types. I Know for sure that the first two Bytes are used to contain the vartype the variant contains (Programming visual basic 6.0 by Francesco Balena)  Normally only bytes 7 to 15 are used to store data or pointer to data.
1 exeption it uses byte 3 to 15 to store a decimal

And no... it did copy 3 Doubles, A double is 8 Bytes... 3*8 = 24


@MickD

Writing classes does have some benefits in being able to store an double array and add some extra functionallity on the side like maxvalue, minvalue, average, some transposing functionality... etc.
And nice to read you again... it's been a while.





MickD

  • Gator
  • Posts: 3308
  • (x-in)->[process]->(y-out)
Re: vector/matrix functions for acad
« Reply #20 on: December 07, 2007, 06:12:59 PM »
You too Berend, yes it has been a while, it's like starting from scratch although these days I have a bit better idea what I want to do and how to do it...I think :)

I was thinking "this passing things back and forth, creating temp var's and assinging things twice is just crazy talk", then it dawned on me, what I need is a pointer. I then remembered the ByRef keyword and give it a fling. I think this is what I need, back to the drawing board...

Code: [Select]
Public Function initarray(ByRef arr() As Double)
arr(0) = 1: arr(1) = 3
End Function

Public Sub test()
Dim a(0 To 1) As Double
initarray a
Debug.Print a(0) & "," & a(1)
End Sub
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

MickD

  • Gator
  • Posts: 3308
  • (x-in)->[process]->(y-out)
Re: vector/matrix functions for acad
« Reply #21 on: December 07, 2007, 07:07:24 PM »
Ok, that was a lot easier and cleaner too, here's the revised functions, any thought's, am I overusing ByRef and does it have any drawbacks I should be aware of??
As I understand it I'm working on the actual data rather than copies so it should even be a bit faster, obviously though one must be careful when passing arg's that should not be changed by the function (is there a keyword to use for this?).

Code: [Select]
''''''''------- Vector Methods --------------'''''''''''
Public Function VecNorm(ByRef vec() As Double)
'Normalises the incoming vector.
Dim unit As Double
unit = Sqr(vec(0) * vec(0) + vec(1) * vec(1) + vec(2) * vec(2))
vec(0) = vec(0) / unit: vec(1) = vec(1) / unit: vec(2) = vec(2) / unit
End Function

Function VecCross(ByRef retvec() As Double, ByRef v1() As Double, ByRef v2() As Double)
    retvec(0) = v1(1) * v2(2) - v2(1) * v1(2)
    retvec(1) = v1(2) * v2(0) - v2(2) * v1(0)
    retvec(2) = v1(0) * v2(1) - v2(0) * v1(1)
End Function

'''''''''--------- Matrix Methods ------------'''''''''''
Public Function BuildMat(ByRef mat() As Double, ByRef vx() As Double, _
                            ByRef vy() As Double, ByRef vz() As Double)
'Uses the incoming vectors to transform the entity being passed in

mat(0, 0) = vx(0): mat(0, 1) = vy(0): mat(0, 2) = vz(0): mat(0, 3) = 0#
mat(1, 0) = vx(1): mat(1, 1) = vy(1): mat(1, 2) = vz(1): mat(1, 3) = 0#
mat(2, 0) = vx(2): mat(2, 1) = vy(2): mat(2, 2) = vz(2): mat(2, 3) = 0#
mat(3, 0) = 0#: mat(3, 1) = 0#: mat(3, 2) = 0#: mat(3, 3) = 1#

End Function

Public Function MatFromLine(line As AcadLine, ByRef mat() As Double)
'builds the matrix passed in based on the line's sp, ep and normal
Dim vx(2) As Double, vy(2) As Double, vz(2) As Double

'get the lines ep-sp vector to create the z axis:
vz(0) = line.EndPoint(0) - line.StartPoint(0)
vz(1) = line.EndPoint(1) - line.StartPoint(1)
vz(2) = line.EndPoint(2) - line.StartPoint(2)
'normalise it:
VecNorm vz

'get the line's normal for the x vector:
vx(0) = line.Normal(0)
vx(1) = line.Normal(1)
vx(2) = line.Normal(2)

'create the y vector by xproduct of z over x:
VecCross vy, vz, vx
'normalise it:
VecNorm vy

'plug 'em into the matrix:
BuildMat mat, vx, vy, vz

End Function

BTW, this code has not been tested in the feild yet and is subject to strange things happening to your drawing ent's :)
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

MP

  • Seagull
  • Posts: 17439
Re: vector/matrix functions for acad
« Reply #22 on: December 07, 2007, 07:57:17 PM »
Quick observations Mick, offered in the remote chance they may be helpful.

Do all those functions want to be subs since they have no return values? Or are you thinking down the road they'll return values?

Do all the functions / subs need to be public? Viewed thru my goggles I get the impression the only one that need be public is MatFromLine.

In MatFromLine array vy() ins not initialized to any values. Not knowing vector / matric math, is assuming all 0's ok? Would it be better if it's explicitly initialized to 0's, in particular if this library heads at some point to VB.NET where, correct me if I'm wrong, non initialized variables might chuck a compiler caution?

Things that make me go hmmmm.

:)
« Last Edit: December 07, 2007, 08:00:25 PM by MP »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MickD

  • Gator
  • Posts: 3308
  • (x-in)->[process]->(y-out)
Re: vector/matrix functions for acad
« Reply #23 on: December 07, 2007, 08:35:43 PM »
Quick observations Mick, offered in the remote chance they may be helpful.

Do all those functions want to be subs since they have no return values? Or are you thinking down the road they'll return values?

So, as a rule of thumb, use subs if not returning a value else use functions. Check ;)

Quote
Do all the functions / subs need to be public? Viewed thru my goggles I get the impression the only one that need be public is MatFromLine.

True, but I will never know when I could use the others, such as the dot product to determine which way two vec's or lines are pointing for instance, have have been pondering this also but for now I'll leave them public.

Quote
In MatFromLine array vy() ins not initialized to any values. Not knowing vector / matric math, is assuming all 0's ok? Would it be better if it's explicitly initialized to 0's, in particular if this library heads at some point to VB.NET where, correct me if I'm wrong, non initialized variables might chuck a compiler caution?

true, but I do initialise it in the method with the xproduct of the other two vec's. I doubt that I would port it to .net, this will do me for a couple of years, by then I may be doing something else I hope :)
It's still food for thought though, all good points, thanks MP.

Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

MickD

  • Gator
  • Posts: 3308
  • (x-in)->[process]->(y-out)
Re: vector/matrix functions for acad
« Reply #24 on: December 07, 2007, 08:43:20 PM »
Here's a sub ('test' at the bottom) using the methods above, it xforms an object to the same direction of a given line, it will later be modified for my 3dsolid section creator that creates the section, transforms and translates the object to the 'construction line' or wire frame line in steel modeling terms if you like.

There is no error checking so it will fail if you do the wrong thing, error checking is next on my hit list before going too much further.

Here's the code, I have altered the MatFrom line function also to cater for strange lines like these (it didn't build an orthoganal matrix).
There's a dwg attached with a cylinder and a line at a strange angle in space if you like but it should work with any object, run the sub, follow the prompts and it should xform the cylinder to the same direction as the line.
Code: [Select]

''''''''------- Vector Methods --------------'''''''''''
Public Function VecNorm(ByRef vec() As Double)
'Normalises the incoming vector.
Dim unit As Double
unit = Sqr(vec(0) * vec(0) + vec(1) * vec(1) + vec(2) * vec(2))
vec(0) = vec(0) / unit: vec(1) = vec(1) / unit: vec(2) = vec(2) / unit
End Function

Function VecCross(ByRef retvec() As Double, ByRef v1() As Double, ByRef v2() As Double)
    retvec(0) = v1(1) * v2(2) - v2(1) * v1(2)
    retvec(1) = v1(2) * v2(0) - v2(2) * v1(0)
    retvec(2) = v1(0) * v2(1) - v2(0) * v1(1)
End Function

'''''''''--------- Matrix Methods ------------'''''''''''
Public Function BuildMat(ByRef mat() As Double, ByRef vx() As Double, _
                            ByRef vy() As Double, ByRef vz() As Double)
'Uses the incoming vectors to transform the entity being passed in

mat(0, 0) = vx(0): mat(0, 1) = vy(0): mat(0, 2) = vz(0): mat(0, 3) = 0#
mat(1, 0) = vx(1): mat(1, 1) = vy(1): mat(1, 2) = vz(1): mat(1, 3) = 0#
mat(2, 0) = vx(2): mat(2, 1) = vy(2): mat(2, 2) = vz(2): mat(2, 3) = 0#
mat(3, 0) = 0#: mat(3, 1) = 0#: mat(3, 2) = 0#: mat(3, 3) = 1#

End Function

Public Function MatFromLine(line As AcadLine, ByRef mat() As Double)
'builds the matrix passed in based on the line's sp, ep and normal
Dim vx(2) As Double, vy(2) As Double, vz(2) As Double

'get the lines ep-sp vector to create the z axis:
vz(0) = line.EndPoint(0) - line.StartPoint(0)
vz(1) = line.EndPoint(1) - line.StartPoint(1)
vz(2) = line.EndPoint(2) - line.StartPoint(2)
'normalise it:
VecNorm vz

'get the line's normal for the x vector:
vx(0) = line.Normal(0)
vx(1) = line.Normal(1)
vx(2) = line.Normal(2)

'create the y vector by xproduct of z over x:
VecCross vy, vz, vx
'normalise it:
VecNorm vy

'we need an extra step here as the line may not
'have been drawn in the same plane as it's ucs when drawn
'so we have to 'square up' the x axis, the order of the
'2 vars to cross is important here!
VecCross vx, vy, vz

'now plug 'em into the matrix:
BuildMat mat, vx, vy, vz

End Function

Public Sub test()
'transforms an ent to the same ucs as a given line
'needs error checking so be careful! ;)
Dim line As AcadEntity, obj As AcadEntity
Dim pnt As Variant
Dim transmat(3, 3) As Double

'get the obj and line from user:
ThisDrawing.Utility.GetEntity obj, pnt, "Pick object to xform: "
ThisDrawing.Utility.GetEntity line, pnt, "Pick line to xform to: "

'get the xform matrix from the line:
MatFromLine line, transmat
'xform the obj:
obj.TransformBy (transmat)
obj.Update
End Sub

<edit> Just a quick note, if you use the function again and pick another line, or even the same line again you will get unexpected results.
The reason for this is that the transformations are cumulative. The way around this is to add a user 'ocs' to the solid, retrieve it and for the sake fo simplicity, invert the matrix of the object to transform it back to world then transform it with the given line ocs...hope that makes sense.
« Last Edit: December 07, 2007, 09:11:58 PM by MickD »
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

MP

  • Seagull
  • Posts: 17439
Re: vector/matrix functions for acad
« Reply #25 on: December 07, 2007, 09:09:07 PM »
Thanks for posting your works so far Mick, I'll have a go at it this evening.

:)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MickD

  • Gator
  • Posts: 3308
  • (x-in)->[process]->(y-out)
Re: vector/matrix functions for acad
« Reply #26 on: December 07, 2007, 09:15:59 PM »
My pleasure, thanks for the help, you'll be seeing a fair bit of me around here for a while, hope I don't annoy you guys too much with trivial stuff, I don't have time to re-learn everything about vba so some things I ask may be no-brainers, by the time I'm finished though I should have some good routines to contribute.

I better go too, I'm getting those 'looks' from the family  I always get when I've been engrossed at the screen for too long :D
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

MP

  • Seagull
  • Posts: 17439
Re: vector/matrix functions for acad
« Reply #27 on: December 08, 2007, 12:03:46 AM »
... thanks for the help, you'll be seeing a fair bit of me around here for a while, hope I don't annoy you guys too much with trivial stuff, I don't have time to re-learn everything about vba so some things I ask may be no-brainers, by the time I'm finished though I should have some good routines to contribute.

Hey, my pleasure. It's not annoying or trivial to me, just good ol' propeller head fun. Looking forward to your final libraries.

Food for thought --

Code: [Select]
[color=green]''''''''------- Vector Methods --------------'''''''''''[/color]

Function VecNorm (vec() As Double) As Double()

    [color=green]'Normalises the incoming vector.[/color]
   
    Dim result(2) As Double, _
        unit      As Double
       
    unit = Sqr(vec(0) * vec(0) + _
               vec(1) * vec(1) + _
               vec(2) * vec(2))
               
    result(0) = vec(0) / unit
    result(1) = vec(1) / unit
    result(2) = vec(2) / unit
   
    [color=red]VecNorm = result[/color]
   
End Function

Function VecCross(v1() As Double, _
                  v2() As Double) _
                       As Double()
                         
    Dim result(2) As Double
   
    result(0) = v1(1) * v2(2) - v2(1) * v1(2)
    result(1) = v1(2) * v2(0) - v2(2) * v1(0)
    result(2) = v1(0) * v2(1) - v2(0) * v1(1)
   
    [color=red]VecCross = result[/color]

End Function

[color=green]'''''''''--------- Matrix Methods ------------'''''''''''[/color]

Function BuildMat(vx() As Double, _
                  vy() As Double, _
                  vz() As Double) _
                       As Double()
                         
    [color=green]'Uses the incoming vectors to transform the result matrix[/color]
   
    Dim result(3, 3) As Double
   
    result(0, 0) = vx(0)
    result(0, 1) = vy(0)
    result(0, 2) = vz(0)
    result(0, 3) = 0#
   
    result(1, 0) = vx(1)
    result(1, 1) = vy(1)
    result(1, 2) = vz(1)
    result(1, 3) = 0#
   
    result(2, 0) = vx(2)
    result(2, 1) = vy(2)
    result(2, 2) = vz(2)
    result(2, 3) = 0#
   
    result(3, 0) = 0#
    result(3, 1) = 0#
    result(3, 2) = 0#
    result(3, 3) = 1#
   
    [color=red]BuildMat = result[/color]

End Function

Function MatFromLine(line As AcadLine) As Double()
   
    [color=green]'builds the matrix passed in based on the line's sp, ep and normal
   
    'first declare 'em dynamic[/color]
   
    Dim vx() As Double, _
        vy() As Double, _
        vz() As Double
       
    [color=green]'now give 'em dimensions (this slight of hand allows
    'us to assign values to them from functions)[/color]
   
    ReDim vx(2), _
          vy(2), _
          vz(2)
   
    [color=green]'get the lines ep-sp vector to create the z axis:[/color]
   
    With line
   
        vz(0) = .EndPoint(0) - .StartPoint(0)
        vz(1) = .EndPoint(1) - .StartPoint(1)
        vz(2) = .EndPoint(2) - .StartPoint(2)
   
        [color=green]'normalise it:[/color]
       
        vz = VecNorm(vz)
       
        [color=green]'get the line's normal for the x vector:[/color]
       
        vx(0) = .Normal(0)
        vx(1) = .Normal(1)
        vx(2) = .Normal(2)
   
    End With
   
    [color=green]'create the y vector by xproduct of z over x:[/color]
   
    vy = VecCross(vz, vx)
   
    [color=green]'normalise it:[/color]
   
    vy = VecNorm(vy)
   
    [color=green]'we need an extra step here as the line may not
    'have been drawn in the same plane as it's ucs when drawn
    'so we have to 'square up' the x axis, the order of the
    '2 vars to cross is important here![/color]
   
    vx = VecCross(vy, vz)
   
    [color=green]'now build the matrix:[/color]
   
    [color=red]MatFromLine = BuildMat(vx, vy, vz)[/color]

End Function

Sub Demo( )

    [color=green]'transforms an ent to the same ucs as a given line
    'needs error checking so be careful! ;)[/color]
   
    Dim line       As AcadEntity, _
        obj        As AcadEntity, _
        pnt        As Variant, _
        transmat() As Double [color=green]'dynamic, rather than static array[/color]
   
    [color=green]'get the obj and line from user:[/color]
   
    With ThisDrawing.Utility
        .GetEntity  obj, pnt, "Pick object to xform: "
        .GetEntity line, pnt, "Pick line to xform to: "
    End With
   
    [color=green]'get the xform matrix from the line:[/color]
   
    transmat = MatFromLine(line)
   
    [color=green]'xform the obj:[/color]
   
    With obj
        .TransformBy (transmat)
        .Update
    End With

End Sub

Look ma, only one sub!

(The fruit of the labors is most visible by examining function MatFromLine, though there are at least 2 things to observe in sub Demo).

Later man.

:)
« Last Edit: December 08, 2007, 05:26:57 AM by MP »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

SEANT

  • Bull Frog
  • Posts: 324
Re: vector/matrix functions for acad
« Reply #28 on: December 08, 2007, 03:35:24 AM »
Ok, that was a lot easier and cleaner too, here's the revised functions, any thought's, am I overusing ByRef and does it have any drawbacks I should be aware of??
As I understand it I'm working on the actual data rather than copies so it should even be a bit faster, obviously though one must be careful when passing arg's that should not be changed by the function (is there a keyword to use for this?).

I believe "ByRef" is the default method of passing variables so would not require explicit declaration (i.e., Public Function VecNorm(ByRef vec() As Double) is the same as Public Function VecNorm(vec() As Double).  The other option you alluded to is "ByVal", which passes a copy of the variable, the original is immune to any operations of the called routine.

Note that array arguments and user-defined type arguments cannot be passed ByVal
« Last Edit: December 08, 2007, 03:57:36 AM by SEANT »
Sean Tessier
AutoCAD 2016 Mechanical

SEANT

  • Bull Frog
  • Posts: 324
Re: vector/matrix functions for acad
« Reply #29 on: December 08, 2007, 10:26:13 AM »
Mick, as a point of possible interest:

Because a line’s normal could be pointing anywhere, it’s possibly aligned with the line direction.  If that were the case then a “Zero” vector would result from a cross product.

In lieu of additional error checking, could a temporary assignment such as:

Vx(0) = -Vz(1)
Vx(1) = Vz(2)
Vx(2) = Vx(0)

Essentially, something to guarantee non-collinear.

A subsequent VecNorm and VecCross Vy, Vz, Vx  (then another go round to square up Vx )  should preserve the primary bit of information, i.e., line’s direction.
Sean Tessier
AutoCAD 2016 Mechanical