Matrix2D: Difference between revisions

From SDK
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 59: Line 59:
   Selection:Transform(Txform)
   Selection:Transform(Txform)
   local MySelection = Selection:GetBoundingBox();
   local MySelection = Selection:GetBoundingBox();
   local MyNewLocatioin = Item.Wpt0 - MySelection.BLC
   local MyNewLocatioin = NewBasePoint - MySelection.BLC
   local Txform2 = TranslationMatrix2D(MyNewLocatioin)
   local Txform2 = TranslationMatrix2D(MyNewLocatioin)
   Selection:Transform(Txform2)
   Selection:Transform(Txform2)
   return true
   return true
end </nowiki>
end </nowiki>


===ScalingMatrix2D( Vector2D scale_vec)===
===ScalingMatrix2D( Vector2D scale_vec)===
Line 91: Line 90:
       NewBasePoint = Point2D(0,0)
       NewBasePoint = Point2D(0,0)
     end -- if end
     end -- if end
     local MyNewLocatioin = BasePoint - MySelection.BLC
     local MyNewLocatioin = NewBasePoint - MySelection.BLC
     local Txform = TranslationMatrix2D(MyNewLocatioin)
     local Txform = TranslationMatrix2D(MyNewLocatioin)
     Selection:Transform(Txform)
     Selection:Transform(Txform)

Latest revision as of 13:18, 27 July 2024

Back.jpg

This object represents a matrix which can be used to transform 2D points Note: translation, rotation scaling etc.

Constructor

Matrix2D objects are usually constructed by the utility methods listed below.


IdentityMatrix2D()

Returns: a Matrix2D which is an identity matrix.


ReflectionMatrix2D( Point2D p1, Point2D p1)

Returns: a Matrix2D which is performs reflection about a line between the passed points.

P1 (Point2D) the start point of the line about which reflection will take place
P2 (Point2D) the end point of the line about which reflection will take place

Example Code:

 function MirrorSetectedVectors(job, Pt1, Pt2)
  local Selection = job.Selection
  if not Pt1 then
    MessageBox("Error: No PT1 point provided!")
    return false
  end -- if end
  if not Pt2 then
    MessageBox("Error: No PT2 point provided!")
    return false
  end -- if end
  if Selection.IsEmpty then
    MessageBox("Error: Rotation function: No vectors selected!")
    return false
  end -- if end
  local Txform = ReflectionMatrix2D(Pt1, Pt2)
  Selection:Transform(Txform)
  return true
end 

RotationMatrix2D( Point2D rotation_pt, double angle)

Returns: a Matrix2D which is performs the rotation about the specified point by the specified amount.

rotation_pt (Point2D) the point about which rotation will take place
angle(double) the angle to rotate by in degrees, positive values are CCW.

Example Code:

 function RotateSetectedVectors(job, NewBasePoint, NewAngle)
  local Selection = job.Selection
  if not NewBasePoint then
    NewBasePoint = Point2D(0,0)
  end -- if end
  if not NewAngle then
    NewAngle = 0.0
  end -- if end
  if Selection.IsEmpty then
    MessageBox("Error: Rotation function: No vectors selected!")
    return false
  end -- if end
  local Txform = RotationMatrix2D(NewBasePoint, NewAngle)
  Selection:Transform(Txform)
  local MySelection = Selection:GetBoundingBox();
  local MyNewLocatioin = NewBasePoint - MySelection.BLC
  local Txform2 = TranslationMatrix2D(MyNewLocatioin)
  Selection:Transform(Txform2)
  return true
end 

ScalingMatrix2D( Vector2D scale_vec)

Returns: a Matrix2D which performs the scaling around the origin (0,0) by the specified amount. scale_vec (Vector2D) the X and Y values of the vector specify the amount to scale in X and Y


ScalingMatrix2D( Point2D scale_pt, Vector2D scale_vec)

Returns: a Matrix2D which is performs the scaling about the specified point by the specified amount.

scaling_pt (Point2D) the point about which scaling will take place
scale_vec (Vector2D) the X and Y values of the vector specify the amount to scale in X and Y


TranslationMatrix2D( Vector2D vec)

Returns: a Matrix2D which is performs the translation specified by the vector.

vec (Vector2D) the X and Y values of the vector specify the distances to translate in X and Y

Example Code:

  function MoveSetectedVectors(job, NewBasePoint)
    local Selection = job.Selection
    if Selection.IsEmpty then
      MessageBox("Error Move Function: No vectors selected!")
      return false
    end -- if end
    local MySelection = Selection:GetBoundingBox();
    if not NewBasePoint then
      NewBasePoint = Point2D(0,0)
    end -- if end
    local MyNewLocatioin = NewBasePoint - MySelection.BLC
    local Txform = TranslationMatrix2D(MyNewLocatioin)
    Selection:Transform(Txform)
    return true
  end 

Operations

Matrix2D * Matrix2D Multiplying a matrix by a matrix returns a new matrix


Example Code:

 local p1 = Point2D(10 ,10)
 local xform = RotationMatrix2D(Point2D(0,0) 90)
 local p3 = xform * p1
 DisplayMessageBox("Transformed p1 = "   p3.X   " , "   p3.Y) 


Back.jpg

References

Please Note: The base material for the contents found in this WiKi was sourced from Vectric Lua Interface for Gadgets, version 2.05, published September 12, 2018. by Vectric Ltd. Most current document from Vertric can be downloaded at Vertric Developer Information