Matrix2D: Difference between revisions
(9 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
[[Category:SDK]] | [[Category:SDK]] | ||
This object represents a matrix which can be used to transform 2D points Note: translation, rotation scaling etc. | This object represents a matrix which can be used to transform 2D points Note: translation, rotation scaling etc. | ||
==Constructor== | ==Constructor== | ||
Matrix2D objects are usually constructed by the utility methods listed below. | Matrix2D objects are usually constructed by the utility methods listed below. | ||
Line 15: | Line 17: | ||
::''P2 (Point2D) the end 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:''' | |||
<nowiki>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 </nowiki> | |||
===RotationMatrix2D( Point2D rotation_pt, double angle)=== | ===RotationMatrix2D( Point2D rotation_pt, double angle)=== | ||
Line 21: | Line 42: | ||
::''angle(double) the angle to rotate by in degrees, positive values are CCW.'' | ::''angle(double) the angle to rotate by in degrees, positive values are CCW.'' | ||
'''Example Code:''' | |||
<nowiki> function RotateSetectedVectors(job, NewBasePoint, NewAngle) | |||
<nowiki> function RotateSetectedVectors(job, NewBasePoint, NewAngle) | |||
local Selection = job.Selection | local Selection = job.Selection | ||
if not NewBasePoint then | if not NewBasePoint then | ||
Line 36: | Line 58: | ||
local Txform = RotationMatrix2D(NewBasePoint, NewAngle) | local Txform = RotationMatrix2D(NewBasePoint, NewAngle) | ||
Selection:Transform(Txform) | Selection:Transform(Txform) | ||
local | local MySelection = Selection:GetBoundingBox(); | ||
local | local MyNewLocatioin = NewBasePoint - MySelection.BLC | ||
local Txform2 = TranslationMatrix2D( | 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 51: | Line 73: | ||
::''scaling_pt (Point2D) the point about which scaling will take place'' | ::''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'' | ::''scale_vec (Vector2D) the X and Y values of the vector specify the amount to scale in X and Y'' | ||
===TranslationMatrix2D( Vector2D vec)=== | ===TranslationMatrix2D( Vector2D vec)=== | ||
'''Returns:''' a Matrix2D which is performs the translation specified by the vector. | '''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'' | ::''vec (Vector2D) the X and Y values of the vector specify the distances to translate in X and Y'' | ||
'''Example Code:''' | |||
<nowiki> 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 </nowiki> | |||
==Operations== | ==Operations== | ||
Line 62: | Line 102: | ||
'''Example Code:''' | |||
<nowiki>local p1 = Point2D(10 ,10) | <nowiki>local p1 = Point2D(10 ,10) | ||
local xform = RotationMatrix2D(Point2D(0,0) 90) | local xform = RotationMatrix2D(Point2D(0,0) 90) |
Latest revision as of 13:18, 27 July 2024
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)
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