Example #1
0
        /// <summary>
        /// Creates a new user coordinate system from the XY plane normal (z-axis).
        /// </summary>
        /// <param name="name">User coordinate system name.</param>
        /// <param name="origin">Origin in WCS.</param>
        /// <param name="normal">XY plane normal (z-axis).</param>
        /// <returns>A new user coordinate system.</returns>
        /// <remarks>This method uses the ArbitraryAxis algorithm to obtain the user coordinate system x-axis and y-axis.</remarks>
        public static UCS FromNormal(string name, Vector3 origin, Vector3 normal)
        {
            Matrix3 mat = MathHelper.ArbitraryAxis(normal);
            UCS     ucs = new UCS(name);

            ucs.origin = origin;
            ucs.xAxis  = new Vector3(mat.M11, mat.M21, mat.M31);
            ucs.yAxis  = new Vector3(mat.M12, mat.M22, mat.M32);
            ucs.zAxis  = new Vector3(mat.M13, mat.M23, mat.M33);
            return(ucs);
        }
Example #2
0
        /// <summary>
        /// Creates a new user coordinate system from the x-axis and a point on XY plane.
        /// </summary>
        /// <param name="name">User coordinate system name.</param>
        /// <param name="origin">Origin in WCS.</param>
        /// <param name="xDirection">X-axis direction in WCS.</param>
        /// <param name="pointOnPlaneXY">Point on the XYplane.</param>
        /// <returns>A new user coordinate system.</returns>
        public static UCS FromXAxisAndPointOnXYplane(string name, Vector3 origin, Vector3 xDirection, Vector3 pointOnPlaneXY)
        {
            UCS ucs = new UCS(name);

            ucs.origin = origin;
            ucs.xAxis  = xDirection;
            ucs.xAxis.Normalize();
            ucs.zAxis = Vector3.CrossProduct(xDirection, pointOnPlaneXY);
            ucs.zAxis.Normalize();
            ucs.yAxis = Vector3.CrossProduct(ucs.zAxis, ucs.xAxis);
            return(ucs);
        }
Example #3
0
        /// <summary>
        /// Creates a new UCS that is a copy of the current instance.
        /// </summary>
        /// <param name="newName">UCS name of the copy.</param>
        /// <returns>A new UCS that is a copy of this instance.</returns>
        public override TableObject Clone(string newName)
        {
            UCS copy = new UCS(newName)
            {
                Origin = this.origin,
                xAxis  = this.xAxis,
                yAxis  = this.yAxis,
                zAxis  = this.zAxis,
            };

            foreach (XData data in this.XData.Values)
            {
                copy.XData.Add((XData)data.Clone());
            }

            return(copy);
        }
Example #4
0
        /// <summary>
        /// Creates a new UCS that is a copy of the current instance.
        /// </summary>
        /// <param name="newName">UCS name of the copy.</param>
        /// <returns>A new UCS that is a copy of this instance.</returns>
        public override TableObject Clone(string newName)
        {
            UCS copy = new UCS(newName)
            {
                Origin    = origin,
                xAxis     = xAxis,
                yAxis     = yAxis,
                zAxis     = zAxis,
                Elevation = elevation
            };

            foreach (XData data in XData.Values)
            {
                copy.XData.Add((XData)data.Clone());
            }

            return(copy);
        }
Example #5
0
 /// <summary>
 /// Creates a new user coordinate system from the XY plane normal (z-axis).
 /// </summary>
 /// <param name="name">User coordinate system name.</param>
 /// <param name="origin">Origin in WCS.</param>
 /// <param name="normal">XY plane normal (z-axis).</param>
 /// <param name="rotation">The counter-clockwise angle in radians along the normal (z-axis).</param>
 /// <returns>A new user coordinate system.</returns>
 /// <remarks>This method uses the ArbitraryAxis algorithm to obtain the user coordinate system x-axis and y-axis.</remarks>
 public static UCS FromNormal(string name, Vector3 origin, Vector3 normal, double rotation)
 {
     Matrix3 mat = MathHelper.ArbitraryAxis(normal);
     Matrix3 rot = Matrix3.RotationZ(rotation);
     mat *= rot;
     UCS ucs = new UCS(name);
     ucs.origin = origin;
     ucs.xAxis = new Vector3(mat.M11, mat.M21, mat.M31);
     ucs.yAxis = new Vector3(mat.M12, mat.M22, mat.M32);
     ucs.zAxis = new Vector3(mat.M13, mat.M23, mat.M33);
     return ucs;
 }
Example #6
0
 /// <summary>
 /// Creates a new user coordinate system from the x-axis and a point on XY plane.
 /// </summary>
 /// <param name="name">User coordinate system name.</param>
 /// <param name="origin">Origin in WCS.</param>
 /// <param name="xDirection">X-axis direction in WCS.</param>
 /// <param name="pointOnPlaneXY">Point on the XYplane.</param>
 /// <returns>A new user coordinate system.</returns>
 public static UCS FromXAxisAndPointOnXYplane(string name, Vector3 origin, Vector3 xDirection, Vector3 pointOnPlaneXY)
 {
     UCS ucs = new UCS(name);
     ucs.origin = origin;
     ucs.xAxis = xDirection;
     ucs.xAxis.Normalize();
     ucs.zAxis = Vector3.CrossProduct(xDirection, pointOnPlaneXY);
     ucs.zAxis.Normalize();
     ucs.yAxis = Vector3.CrossProduct(ucs.zAxis, ucs.xAxis);
     return ucs;
 }
        /// <summary>
        /// Writes a new user coordinate system to the table section.
        /// </summary>
        /// <param name="ucs">UCS.</param>
        private void WriteUCS(UCS ucs)
        {
            Debug.Assert(this.activeTable == DxfObjectCode.UcsTable);

            this.chunk.Write(0, ucs.CodeName);
            this.chunk.Write(5, ucs.Handle);
            this.chunk.Write(330, ucs.Owner.Handle);

            this.chunk.Write(100, SubclassMarker.TableRecord);

            this.chunk.Write(100, SubclassMarker.Ucs);

            this.chunk.Write(2, this.EncodeNonAsciiCharacters(ucs.Name));

            this.chunk.Write(70, (short) 0);

            this.chunk.Write(10, ucs.Origin.X);
            this.chunk.Write(20, ucs.Origin.Y);
            this.chunk.Write(30, ucs.Origin.Z);

            this.chunk.Write(11, ucs.XAxis.X);
            this.chunk.Write(21, ucs.XAxis.Y);
            this.chunk.Write(31, ucs.XAxis.Z);

            this.chunk.Write(12, ucs.YAxis.X);
            this.chunk.Write(22, ucs.YAxis.Y);
            this.chunk.Write(32, ucs.YAxis.Z);

            this.chunk.Write(79, (short) 0);

            this.chunk.Write(146, ucs.Elevation);
        }
        private static void UserCoordinateSystems()
        {
            DxfDocument dxf = new DxfDocument();
            UCS ucs1 = new UCS("user1", Vector3.Zero, Vector3.UnitX, Vector3.UnitZ);
            UCS ucs2 = UCS.FromXAxisAndPointOnXYplane("user2", Vector3.Zero, new Vector3(1,1,0), new Vector3(1,1,1));
            UCS ucs3 = UCS.FromNormal("user3", Vector3.Zero, new Vector3(1, 1, 1), 0);
            dxf.UCSs.Add(ucs1);
            dxf.UCSs.Add(ucs2);
            dxf.UCSs.Add(ucs3);

            dxf.Save("ucs.dxf");

            dxf = DxfDocument.Load("ucs.dxf");

        }