Matrix2D: Difference between revisions

From SDK
Jump to navigation Jump to search
(Created page with "right|50px|link=Low Level Geometry Category:SDK This object represents a matrix which can be used to transform 2D points Note: translation, rotation scal...")
 
Line 21: Line 21:
::''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)
  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 StairSelection = Selection:GetBoundingBox();
  local StairNewLocatioin = Stair.Wpt0 - StairSelection.BLC
  local Txform2 = TranslationMatrix2D(StairNewLocatioin)
  Selection:Transform(Txform2)
  return true
end</nowiki>


===ScalingMatrix2D( Vector2D scale_vec)===
===ScalingMatrix2D( Vector2D scale_vec)===

Revision as of 15:37, 7 February 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


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 StairSelection = Selection:GetBoundingBox(); local StairNewLocatioin = Stair.Wpt0 - StairSelection.BLC local Txform2 = TranslationMatrix2D(StairNewLocatioin) 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

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