DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

More efficient way of calculating rotation matrices?

Hi,

Right now I'm brute force scripting to calculate rotation matrices with the following code. I was wondering if there is more efficient way of doing this with the matrix functions in diadem? As you can see I'm calculating each individual value in the channel. It would be a lot quciker if I could do the same thing at the channel level.

Thanx,

Bill.

 

 

 

'create displacement component vectors    
  VectI1(0,0)=dblI1:VectI1(1,0)=0:VectI1(2,0)=0
  VectI2(0,0)=dblI2:VectI2(1,0)=0:VectI2(2,0)=0
  VectIa(0,0)=0    :VectIa(1,0)=0:VectIa(2,0)=dblIa
  VectIb(0,0)=0    :VectIb(1,0)=0:VectIb(2,0)=dblIb
        
  dim DisplacementVector
  'transform components into cartesian vectors
  for inti=1 to cl(intBase)
    Rot1Rad=ConvertUnits(dblCalBase*(chd(inti,intBase)-dblSetBase),chndim(intBase),"rad",false)
    Rot1Matrix(0, 0) = Cos(Rot1Rad) :Rot1Matrix(0, 1) = 0           :Rot1Matrix(0, 2) = Sin(Rot1Rad)
    Rot1Matrix(1, 0) = 0            :Rot1Matrix(1, 1) = 1           :Rot1Matrix(1, 2) = 0
    Rot1Matrix(2, 0) = -Sin(Rot1Rad):Rot1Matrix(2, 1) = 0           :Rot1Matrix(2, 2) = Cos(Rot1Rad)
            
    Rot2Rad=ConvertUnits(dblCalMiddle*(chd(inti,intMiddle)-dblSetMiddle),chndim(intMiddle),"rad",false)
    Rot2Matrix(0, 0) = Cos(Rot2Rad) :Rot2Matrix(0, 1) =-Sin(Rot2Rad):Rot2Matrix(0, 2) = 0
    Rot2Matrix(1, 0) = Sin(Rot2Rad) :Rot2Matrix(1, 1) = Cos(Rot2Rad):Rot2Matrix(1, 2) = 0
    Rot2Matrix(2, 0) = 0            :Rot2Matrix(2, 1) = 0           :Rot2Matrix(2, 2) = 1
            
    Rot3Rad=ConvertUnits(dblCalElbow*(chd(inti,intElbow)-dblSetElbow),chndim(intElbow),"rad",false)
    Rot3Matrix(0, 0) = Cos(Rot3Rad) :Rot3Matrix(0, 1) =-Sin(Rot3Rad):Rot3Matrix(0, 2) = 0
    Rot3Matrix(1, 0) = Sin(Rot3Rad) :Rot3Matrix(1, 1) = Cos(Rot3Rad):Rot3Matrix(1, 2) = 0
    Rot3Matrix(2, 0) = 0            :Rot3Matrix(2, 1) = 0           :Rot3Matrix(2, 2) = 1
    '=R1(Ia+R2(I1+(Ib+R3*I2)))         
    DisplacementVector = MatMultiply(Rot1Matrix, MatAddition(VectIa, MatMultiply(Rot2Matrix, MatAddition(VectI1, MatAddition(VectIb, MatMultiply(Rot3Matrix, VectI2)))))) 
    Select case mid(chnname(intBase),7,2)
      case "LL"
        chd(inti,intX)=DisplacementVector(0,0)
        chd(inti,intY)=DisplacementVector(2,0)
        chd(inti,intZ)=-DisplacementVector(1,0)
      case "RL"
        chd(inti,intX)=DisplacementVector(0,0)
        chd(inti,intY)=-DisplacementVector(2,0)
        chd(inti,intZ)=DisplacementVector(1,0)
      case else
        chd(inti,intX)=DisplacementVector(0,0)
        chd(inti,intY)=DisplacementVector(1,0)
        chd(inti,intZ)=DisplacementVector(2,0)
    end select
  next 

 

 

0 Kudos
Message 1 of 1
(3,689 Views)