Delphi - Two dimensional array - VarArrayCreate?

Discussion in 'AutoCAD' started by Jack Houben, Jun 28, 2004.

  1. Jack Houben

    Jack Houben Guest

    Hello all,

    Is it possible to create a transformation matrix. This matrix is a Variant
    (4x4 array of doubles)
    Now I use
    TransMatrix: OleVariant;
    ...
    TransMatrix:=Drawing.ActiveUCS.GetUCSMatrix to create one and then clear
    all the entries.

    Thanks in advance,

    Jack
     
    Jack Houben, Jun 28, 2004
    #1
  2. How to do this depends on whether you're creating the
    matrix (2D array) to pass back to AutoCAD (e.g., to
    the TransformBy() method), or just to manipulate it in
    Object Pascal.

    For a matrix that you need to pass to AutoCAD, as a
    variant, you would create a 2D variant array with 4
    rows and 4 columns:

    VarArrayCreate([0, 3, 0, 3], varDouble);

    To represent a 4x4 matrix using a native language
    array:

    var
    AMatrix : Array[0..3, 0..3] of Double;

    To convert from one to the other, you define a type
    for the array:

    type
    TMatrix4x4: Array[0..3, 0..3] of Double;

    And then use these:

    Function Matrix4x4ToVariant(const AMatrix: TMatrix4x4): OleVariant;
    var
    i, j: Integer;
    begin
    Result := VarArrayCreate([0, 3, 0, 3], varDouble);
    For i := 0 to 3 do
    For j := 0 to 3 do
    Result[i, j] := AMatrix[i, j];
    end;

    Function VariantToMatrix4x4(const AMatrix: OleVariant): TMatrix4x4;
    var
    i, j: Integer;
    begin
    For i := 0 to 3 do
    For j := 0 to 3 do
    Result[i, j] := AMatrix[i, j];
    end;




    AutoCAD based Security Planning Solutions:
    http://www.caddzone.com/securityplanning
     
    Tony Tanzillo, Jun 28, 2004
    #2
  3. Jack Houben

    Jack Houben Guest

    Thanks Tony,

    Your post was very educational again!
    I missed the part [0,3,0,3]....

    Kind regards,
    Jack

     
    Jack Houben, Jun 29, 2004
    #3
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.