Sunday, August 12, 2012

Skew Angles

Sometimes calculating values in AutoCAD can be difficult if you aren’t quite sure where to look. For instance if you want to calculate the skew between two crossing alignments it might seem difficult. Thankfully there is some useful tools in the API to help calculate it.

The first helpful tool is the GetFirstDerivative method. This method calculates a vector value which provides you with the instantaneous direction of the alignment at the point provided. Using this method on the main alignment (riverAlign) and rotating the resulting value by pi / 2 (or 90 degrees) we can get the direction perpendicular to the alignment. We can then calculate the instantaneous direction of the crossing alignment (align). Depending on how we want to calculate the skew, we may want to rotate the vector by pi (180 degrees). We can then use the vectors calculated to get the angle between the two vectors.

Vector3d vector3DRiver = riverAlign.GetFirstDerivative(pt3DcollTempLine[0]);
Vector3d vector3DSection = align.GetFirstDerivative(pt3DcollTempLine[0]);
Matrix3d curUCSMatrix =

CoordinateSystem3d curUCS = curUCSMatrix.CoordinateSystem3d;
vector3DRiver = vector3DRiver.TransformBy(Matrix3d.Rotation(Math.PI / 2,
new Point3d(pt3DcollTempLine[0].X, pt3DcollTempLine[0].Y, 0)));
vector3DSection = vector3DSection.TransformBy(Matrix3d.Rotation(Math.PI,
new Point3d(pt3DcollTempLine[0].X,
pt3DcollTempLine[0].Y, 0)));
skew = vector3DRiver.GetAngleTo(vector3DSection) * 180 / Math.PI;

The above is small snipped of code to accomplish the calculation. The calculations may also be done with polylines and other AutoCAD objects that are derived from curves.

No comments:


Blog Widget by LinkWithin