Rotating with respect to axis
This example provides information on rotating targets about its Local reference.
This example expects targets are already created. You need to pass a Rs
Use this procedure to rotate targets:
Get transformation vector of target
Get the zAxis Vector of target
Get target's GlobalMatrix and rotate around zAxis
Set the GlobalMatrix of target to rotated matrix
Solution
Get transformation vector of target
Vector3 translation = new Vector3(target.Transform.GlobalMatrix.Translation.x, target.Transform.GlobalMatrix.Translation.y, target.Transform.GlobalMatrix.Translation.z);
Get the zAxis Vector of target
Vector3 zAxis = new Vector3(target.Transform.GlobalMatrix.z.x, target.Transform.GlobalMatrix.z.y, target.Transform.GlobalMatrix.z.z);
Get target's GlobalMatrix and rotate around zAxis
//Get the Matrix of target Matrix4 tMatrix = target.Transform.GlobalMatrix; //Rotate the matrix tMatrix.Rotate(translation, zAxis, rotationAngle);
Set the GlobalMatrix of target to rotated matrix
target.Transform.GlobalMatrix = tMatrix;
Example
This example provides information on rotating targets based on axis in RobotStudio.
private static void RSRotateBasedOnAxis(RsTargetCollection targetCollection)
{
//Begin UndoStep
Project.UndoContext.BeginUndoStep("RotateBasedOnAxis");
try
{
foreach (RsTarget target in targetCollection)
{
//Specify Rotation Angle
double rotationAngle = Globals.DegToRad(45);
//Get the Translation Vector of target
Vector3 translation = new Vector3(target.Transform.GlobalMatrix.Translation.x,
target.Transform.GlobalMatrix.Translation.y,
target.Transform.GlobalMatrix.Translation.z);
//Get the zAxis Vector of target
//To change the axis use target.Transform.GlobalMatrix.x.x
//or target.Transform.GlobalMatrix.y.x
//Similary change other paramters
//OR
//Use target.Transform.GlobalMatrix.GetAxisVector(Axis.X)
//or target.Transform.GlobalMatrix.GetAxisVector(Axis.Y)
Vector3 zAxis = new Vector3(target.Transform.GlobalMatrix.z.x,
target.Transform.GlobalMatrix.z.y,
target.Transform.GlobalMatrix.z.z);
//Get the Matrix of target
Matrix4 tMatrix = target.Transform.GlobalMatrix;
//Rotate the matrix
tMatrix.Rotate(translation, zAxis, rotationAngle);
//Set the new matrix to target matrix
target.Transform.GlobalMatrix = tMatrix;
}
}
catch (Exception execption)
{
//Cancel UndoStep
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
Logger.AddMessage(new LogMessage(execption.Message.ToString()));
}
finally
{
//End UndoStep
Project.UndoContext.EndUndoStep();
}
}
Required Namespaces
ABB.
ABB.
ABB.