Rotating Objects

Use the Rotate method to rotate a drawing object around a given point in the User Coordinate

System's (UCS) XY plane. This method has the following syntax:

DrawingObject.Rotate BasePoint, RotationAngle Table 10-5 explains this method's parameters.

Table 10-5. Rotate Method Parameters

Name_Data Type Description_

BasePoint Variant A three-element array of doubles that specifies the 3-D WCS

coordinates of the point through which the axis of rotation, parallel to the Z-axis of the UCS, passes.

RotationAngle Double The angle of rotation given in radians and measured counter clockwise from the UCS's X-axis.

Figure 10-5 shows a rotated object.

Object's Original Position

RotationAngle Object's New

BasePoint

Figure 10-5. A rotated object

The following sample rotates an object based on user input.

Public Sub RotateObject()

Dim objDrawingObject As AcadEntity Dim varEntityPickedPoint As Variant Dim varBasePoint As Variant Dim dblRotationAngle As Double

On Error Resume Next

ThisDrawing.Utility.GetEntity objDrawingObject, varEntityPickedPoint, _

"Please pick an entity to rotate: " If objDrawingObject Is Nothing Then

MsgBox "You did not choose an object." Exit Sub End If varBasePoint = ThisDrawing.Utility.GetPoint(, _

"Enter a base point for the rotation.") dblRotationAngle = ThisDrawing.Utility.GetReal( _

"Enter the rotation angle in degrees: ")

'convert to radians dblRotationAngle = ThisDrawing.Utility. _

AngleToReal(CStr(dblRotationAngle), acDegrees)

'Rotate the object objDrawingObject.Rotate varBasePoint, dblRotationAngle objDrawingObject.Update

End Sub

Use the Rotate3D method to perform a three-dimensional rotation of an object around an axis. This method has the following syntax:

DrawingObject.Rotate3D AxisPoint1, AxisPoint2, RotationAngle Table 10-6 explains this method's parameters.

Table 10-6. Rotate3D Method Parameters

Name

Data Type

Description

AxisPoint1

Variant

A three-element array of doubles that specifies the 3-D WCS coordinates of a point through which the axis of rotation passes.

AxisPoint2

Variant

A three-element array of doubles that specifies the 3-D WCS coordinates of a second point through which the axis of rotation passes.

RotationAngle

Double

The angle of rotation given in radians and measured counterclockwise about the specified axis.

Figure 10-6 shows an object rotated around an axis.

Figure 10-6 shows an object rotated around an axis.

? AxisPoint2

RotationAngle

Object's New Position

AxisPointi

Figure 10-6. An object rotated in 3-D

The following code example lets the user choose an object to rotate, and the points that define the axis of rotation. It then rotates the object around that axis at an angle the user chooses.

Public Sub Rotate3DObject()

Dim objDrawingObject As AcadEntity

Dim varEntityPickedPoint As Variant

Dim objMirroredObject As AcadEntity

Dim varAxisPoint1 As Variant

Dim varAxisPoint2 As Variant

Dim dblRotationAxis As Double

On Error Resume Next

ThisDrawing.Utility.GetEntity objDrawingObject, _

varEntityPickedPoint, "Please select an entity to rotate: " If objDrawingObject Is Nothing Then

MsgBox "You did not choose an object" Exit Sub End If

'ask user for axis points and angle of rotation varAxisPoint1 = ThisDrawing.Utility.GetPoint(, _

"Enter first point of axis of rotation: ") varAxisPoint2 = ThisDrawing.Utility.GetPoint(, _

"Enter second point of axis of rotation: ") dblRotationAxis = ThisDrawing.Utility.GetReal( _

"Enter angle of rotation in degrees")

'convert to radians dblRotationAxis = ThisDrawing.Utility.AngleToReal(CStr(dblRotationAxis), _

acDegrees)

objDrawingObject.Rotate3D varAxisPoint1, varAxisPoint2, dblRotationAxis End Sub

Was this article helpful?

0 -1

Responses

Post a comment