.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Block rotation for XYZ

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
stefan.hofer
203 Views, 2 Replies

Block rotation for XYZ

How can i get the rotation for every axis?

the block rotation just give me one value.

 

BlockReference myBlock;
double rotation = myBlock.Rotation;

// Rotation for X Y and Z
Vector3d allRotations = ...?
2 REPLIES 2
Message 2 of 3
_gile
in reply to: stefan.hofer

Hi,

AutoCAD stores the rotations with only a vector:  the Normal of the block reference (used to define the block reference OCS with the Arbtrary Axis Algorithm) and an angle: the Rotation of the block reference in its OCS.

The rotations about X, Y and Z axis depends on the order of these rotations. It exists some conventions using Euler angles to describe these rotations (Yaw, Potch, Roll or Precession, Nutation, Spin), you can find an example with the EulerAngles class from GeometryExtensions library.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
stefan.hofer
in reply to: _gile

thanks for the example,

It seems for my example i get the block rotation with this values

 

 

 

BlockReference selectedBr = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead) as BlockReference;
BlockRotation blockRotation = GetBlockRotation(selectedBr.BlockTransform, false);
ed.WriteMessage("\nBlockname: " + sourceBlockName + " Pitch: " + blockRotation.Pitch.ToString() + " Yaw: " + blockRotation.Yaw.ToString() + " Roll: " + blockRotation.Roll.ToString()
    + " Nutation: " + blockRotation.Nutation.ToString() + " Precession: " + blockRotation.Precession.ToString() + " Spin: " + blockRotation.Spin.ToString());

// Roll = rotated around the X axis
// Pitch = rotated around the Y axis
// Spin = rotated around the Z axis
Vector3d blockRotationXYZ = new Vector3d(blockRotation.Roll, blockRotation.Pitch, blockRotation.Spin);

 

 

 

functions

 

public struct BlockRotation
{
    public double Nutation;
    public double Precession;
    public double Spin;
    public double Pitch;
    public double Yaw;
    public double Roll;
}

public BlockRotation GetBlockRotation(Matrix3d transform, bool degrees)
{
    if (!transform.IsScaledOrtho())
        throw new ArgumentException("Matrice non orthogonale.");

    var cs = transform.CoordinateSystem3d;
    var xAxis = cs.Xaxis.GetNormal();
    var yAxis = cs.Yaxis.GetNormal();
    var zAxis = cs.Zaxis.GetNormal();
    Matrix3d Transform = new Matrix3d(new[]
    {
        xAxis.X, yAxis.X, zAxis.X, 0.0,
        xAxis.Y, yAxis.Y, zAxis.Y, 0.0,
        xAxis.Z, yAxis.Z, zAxis.Z, 0.0,
        0.0, 0.0, 0.0, 1.0
    });
    Vector3d result1;
    Vector3d result2;

    // Z-X'-Z"
    double Nutation = Math.Acos(Transform[2, 2]);
    double Precession;
    double Spin;
    if (Math.Abs(Nutation) < 1e-7)
    {
        Nutation = 0.0;
        Precession = 0.0;
        Spin = Math.Atan2(Transform[1, 0], Transform[1, 1]);
    }
    else
    {
        Precession = Math.Atan2(Transform[0, 2], -Transform[1, 2]);
        Spin = Math.Atan2(Transform[2, 0], Transform[2, 1]);
    }
    result1 = degrees ? new Vector3d(ConvertToDegrees(Nutation), ConvertToDegrees(Precession), ConvertToDegrees(Spin)) : new Vector3d(Nutation, Precession, Spin);

    // Z-Y'-X"
    double Pitch = -Math.Asin(Transform[2, 0]);
    double Yaw;
    double Roll;
    if (Math.Abs(Pitch - Math.PI * 0.5) < 1e-7)
    {
        Pitch = Math.PI * 0.5;
        Yaw = Math.Atan2(Transform[1, 2], Transform[1, 1]);
        Roll = 0.0;
    }
    else if (Math.Abs(Pitch + Math.PI * 0.5) < 1e-7)
    {
        Pitch = -Math.PI * 0.5;
        Yaw = Math.Atan2(-Transform[1, 2], Transform[1, 1]);
        Roll = 0.0;
    }
    else
    {
        Yaw = Math.Atan2(Transform[1, 0], Transform[0, 0]);
        Roll = Math.Atan2(Transform[2, 1], Transform[2, 2]);
    }
    result2 = degrees ? new Vector3d(ConvertToDegrees(Pitch), ConvertToDegrees(Yaw), ConvertToDegrees(Roll)) : new Vector3d(Pitch, Yaw, Roll);

    return new BlockRotation() { Nutation = result1.X, Precession = result1.Y, Spin = result1.Z, Pitch = result2.X, Yaw = result2.Y, Roll = result2.Z };
}

public double ConvertToRadians(double degrees)
{
    return degrees * (Math.PI / 180);
}

public double ConvertToDegrees(double radians)
{
    return radians * (180 / Math.PI);
}

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report