CAD Practice Drawings 132

This article explains the fundamentals of 2D drawing and 1:1 scale paper printing.

 

private const string Dim = "Dimension", Lw05 = "Lw05";
private const string DashDot = "DashDot";

protected override void OnLoad(EventArgs e)
{
    // set layers and linetype
    viewportLayout1.Layers[0].LineWeight = 2;
    viewportLayout1.Layers.Add(new Layer(Dim, Color.CornflowerBlue));
    viewportLayout1.Layers.Add(new Layer(Lw05));

    viewportLayout1.LineTypes.Add("DashDot", new float[] { 30, -5, 5, -5 });

    // X and Y axes
    Line axisX = new Line(-170, 0, 150, 0);
    axisX.LineTypeMethod = colorMethodType.byEntity;
    axisX.LineTypeName = DashDot;
    viewportLayout1.Entities.Add(axisX, Dim);

    Line axisY = new Line(0, -150, 0, 170);
    axisY.LineTypeMethod = colorMethodType.byEntity;
    axisY.LineTypeName = DashDot;
    viewportLayout1.Entities.Add(axisY, Dim);

    // center circle
    Circle centerCircle = new Circle(0, 0, 0, 40);
    viewportLayout1.Entities.Add(centerCircle);
    DiametricDim diamDimCC = new DiametricDim(centerCircle, new Point2D(20, 20), 8);
    viewportLayout1.Entities.Add(diamDimCC, Dim);

    // screw holes circles
    Circle shCircle = new Circle(0, 0, 0, 52);
    shCircle.LineTypeMethod = colorMethodType.byEntity;
    shCircle.LineTypeName = DashDot;
    viewportLayout1.Entities.Add(shCircle, Dim);
    DiametricDim diamDimSC = new DiametricDim(shCircle, new Point2D(-160, -40), 8);
    viewportLayout1.Entities.Add(diamDimSC, Dim);

    Circle smallCircle = new Circle(0, 52, 0, 5);
    for (int i = 0; i < 6; i++)
    {
        Circle circle = (Circle)smallCircle.Clone();
        circle.Rotate((Math.PI / 3) * i, Vector3D.AxisZ);
        viewportLayout1.Entities.Add(circle);
    }

    DiametricDim diamDimSmallCircle = new DiametricDim(new Circle(0, -52, 0, 5), new Point2D(-10, 20), 8);
    viewportLayout1.Entities.Add(diamDimSmallCircle, Dim);

    //six composite curve
    Arc arc = new Arc(0, 0, 0, 113, (Math.PI / 3), (Math.PI * 2 / 3));
    viewportLayout1.Entities.Add(new Arc(arc.Center, 113, Utility.DegToRad(45), Utility.DegToRad(70)), Dim);

    Line line1 = new Line(-45, 113, -45, 0);
    Line line2 = new Line(-45, 49, 55, 49);
    line2.Rotate(Utility.DegToRad(30), Vector3D.AxisZ, new Point3D(-45, 49));
    viewportLayout1.Entities.Add((Line)line2.Clone(), Dim);

    Arc arcFillet1, arcFillet2, arcFillet3;
    Curve.Fillet(arc, line1, 9.5, false, false, true, true, out arcFillet1);
    Curve.Fillet(arc, line2, 9.5, false, false, true, true, out arcFillet2);
    Curve.Fillet(line1, line2, 9.5, false, false, true, true, out arcFillet3);

    CompositeCurve compositeCurve = new CompositeCurve(arc, line1, line2, arcFillet1, arcFillet2, arcFillet3);

    for (int i = 0; i < 6; i++)
    {
        CompositeCurve compCurve = (CompositeCurve)compositeCurve.Clone();
        compCurve.Rotate((Math.PI / 3) * i, Vector3D.AxisZ);
        viewportLayout1.Entities.Add(compCurve);
    }

    RadialDim rDim = new RadialDim(arc, new Point2D(65, 145), 8)
    {
        ArrowsLocation = elementPositionType.Outside,
        TrimLeader = true,
        ShowCenterMark = false
    };
    viewportLayout1.Entities.Add(rDim, Dim);

    AngularDim angDim = new AngularDim(Plane.XY, axisX, line2, new Point3D(160, 60, 0), new Point3D(140, 80, 0), 8);
    angDim.TextSuffix = "°";
    viewportLayout1.Entities.Add(angDim, Dim);            

    // arcFillet dimension
    Arc copy = (Arc)arcFillet1.Clone();
    copy.Rotate(Utility.DegToRad(250), Vector3D.AxisZ, copy.Plane.Origin);
    rDim = new RadialDim(copy, new Point2D(-40, 40), 8)
    {
        ArrowsLocation = elementPositionType.Outside,
        TrimLeader = true,
        ShowCenterMark = false
    };
    viewportLayout1.Entities.Add(rDim, Dim);

    copy = (Arc)arcFillet2.Clone();
    copy.Rotate(Utility.DegToRad(280), Vector3D.AxisZ, copy.Plane.Origin);
    rDim = new RadialDim(copy, new Point2D(15, 50), 8)
    {
        ArrowsLocation = elementPositionType.Outside,
        TrimLeader = true,
        ShowCenterMark = false
    };
    viewportLayout1.Entities.Add(rDim, Dim);

    copy = (Arc)arcFillet3.Clone();
    copy.Rotate(Utility.DegToRad(180), Vector3D.AxisZ, copy.Plane.Origin);
    rDim = new RadialDim(copy, new Point2D(10, 10), 8)
    {
        ArrowsLocation = elementPositionType.Outside,
        TrimLeader = true
    };
    viewportLayout1.Entities.Add(rDim, Dim);
    viewportLayout1.Entities.Add(new Arc(copy.Center, 9.5, Math.PI / 2), Dim);

    // Teeth
    DrawTeeth();

    // Linear Dimension
    Plane dim1Plane = new Plane(Point3D.Origin,Vector3D.AxisY, -1*Vector3D.AxisX);//Plane.XY;
    viewportLayout1.Entities.Add(new LinearDim(dim1Plane, new Point2D(0, 160), new Point2D(49, 45), new Point2D(25, 170), 8), Dim);
    viewportLayout1.Entities.Add(new LinearDim(Plane.XY, new Point2D(-45, 49), new Point2D(0, 160), new Point2D(-22, 170), 8), Dim);

    // Drawing frame
    int halfWidth = 200;
    int halfHeight = 260;
    LinearPath lp = new LinearPath(-halfWidth, -halfHeight, 2 * halfWidth, 2 * halfHeight);
    viewportLayout1.Entities.Add(lp);

    Line line = new Line(-halfWidth/4, -halfHeight + 30, halfWidth, -halfHeight + 30);
    viewportLayout1.Entities.Add(line);
    line = new Line(-halfWidth/4, -halfHeight + 30, -halfWidth/4, -halfHeight);
    viewportLayout1.Entities.Add(line);
    line = new Line(-halfWidth/4, -halfHeight + 20, halfWidth, -halfHeight + 20);
    viewportLayout1.Entities.Add(line, Lw05);
    line = new Line(100, -halfHeight + 30, 100, -halfHeight);
    viewportLayout1.Entities.Add(line, Lw05);
    line = new Line(130, -halfHeight + 30, 130, -halfHeight);
    viewportLayout1.Entities.Add(line, Lw05);
    line = new Line(160, -halfHeight + 30, 160, -halfHeight);
    viewportLayout1.Entities.Add(line, Lw05);
    line = new Line(100, -halfHeight + 10, 160, -halfHeight + 10);
    viewportLayout1.Entities.Add(line, Lw05);

    Text text = new Text(25, -halfHeight + 25, 0, "Title", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
    viewportLayout1.Entities.Add(text);
    text = new Text(25, -halfHeight + 10, 0, "CAD Practice Drawings 132", 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
    viewportLayout1.Entities.Add(text);
    text = new Text(115, -halfHeight + 25, 0, "Date", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
    viewportLayout1.Entities.Add(text);
    text = new Text(115, -halfHeight + 15, 0, "Design", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
    viewportLayout1.Entities.Add(text);
    text = new Text(115, -halfHeight + 5, 0, "Check", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
    viewportLayout1.Entities.Add(text);
    text = new Text(180, -halfHeight + 25, 0, "Approve", 4, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
    viewportLayout1.Entities.Add(text);

    line = new Line(170, 245, 200, 245);
    viewportLayout1.Entities.Add(line);
    line = new Line(170, 245, 170, 260);
    viewportLayout1.Entities.Add(line);
    text = new Text(185, 252.5, 0, "132", 8, devDept.Eyeshot.Entities.Text.alignmentType.MiddleCenter);
    viewportLayout1.Entities.Add(text);

    viewportLayout1.OriginSymbol.Visible = false;
    viewportLayout1.Grid.Visible = false;
    viewportLayout1.ZoomFit();
    base.OnLoad(e);
}

private void DrawTeeth()
{
    const int teethNumber = 52;
    const int re = 40;

    Circle df = new Circle(0, 0, 0, 128);
    RadialDim rDim = new RadialDim(df, new Point2D(180, -20), 8)
    {
        ArrowsLocation = elementPositionType.Outside,
        TrimLeader = true
    };
    viewportLayout1.Entities.Add(rDim, Dim);
    viewportLayout1.Entities.Add(new Arc(df.Center, 128, -0.15, -0.1), Dim);

    Circle d = new Circle(0, 0, 0, 131.5);
    rDim = new RadialDim(d, new Point2D(145, -100), 8)
    {
        ArrowsLocation = elementPositionType.Outside,
        TrimLeader = true
    };
    viewportLayout1.Entities.Add(rDim, Dim);
    viewportLayout1.Entities.Add(new Arc(d.Center, 131.5, -1, -0.6), Dim);

    Circle MR = new Circle(0, 0, 0, 136);
    rDim = new RadialDim(MR, new Point2D(-160, -70), 8)
    {
        ArrowsLocation = elementPositionType.Outside,
        TrimLeader = true
    };
    viewportLayout1.Entities.Add(rDim, Dim);
    viewportLayout1.Entities.Add(new Arc(MR.Center, 136, -2.75, -0.05), Dim);

    // Tooth composed by line1, internalArc, line2, extArc
    // calculation of extArc
    double rad = Utility.DegToRad(180 - 47.5);
    Arc internalArc = new Arc(0, -131.5, 0, 5, Utility.PI_2 - rad/2, Utility.PI_2 + rad/2);
    rDim = new RadialDim(internalArc, new Point2D(60, -40), 8)
    {
        ArrowsLocation = elementPositionType.Outside,
        TrimLeader = true
    };
    viewportLayout1.Entities.Add(rDim, Dim);
    viewportLayout1.Entities.Add(new Arc(internalArc.Center, 5, Utility.DegToRad(-80), Utility.DegToRad(-10)), Dim);
            
    // calculatation of line 1 and 2
    Line line1 = new Line(internalArc.StartPoint, internalArc.StartPoint + internalArc.StartTangent * -20);
    Line line2 = new Line(internalArc.EndPoint, internalArc.EndPoint + internalArc.EndTangent * 20);
            
    AngularDim angDim = new AngularDim(Plane.XY, line1, line2, new Point3D(0, -180, 0), new Point3D(0, -180, 0), 8);
    angDim.TextSuffix = "°";
    viewportLayout1.Entities.Add(angDim, Dim);

    line1.Reverse();
    line1.TrimBy(Curve.Intersection(MR, line1)[0], true);
    line2.TrimBy(Curve.Intersection(MR, line2)[0], false);

    // calculation of extArc
    var nextl1 = (Line) line1.Clone();
    nextl1.Rotate(-Utility.TWO_PI/teethNumber, Vector3D.AxisZ);

    var seg = new Segment2D(line2.EndPoint, nextl1.StartPoint);
    var radius = 8;
    var h = Math.Sqrt((radius*radius) - ((seg.Length/2) * (seg.Length/2)));

    var midPoint = seg.MidPoint;
    Vector3D vector = Vector3D.Cross(new Vector3D(line2.EndPoint, nextl1.StartPoint), Vector3D.AxisZ); // vector perpendicular to the segment
    vector.Length = h;
    var center = midPoint + vector;

    Arc extArc = new Arc(Plane.XY, center,nextl1.StartPoint, line2.EndPoint);
            
    Arc copy = (Arc) extArc.Clone();
    copy.Rotate(Utility.TWO_PI/teethNumber*6, Vector3D.AxisZ);
    rDim = new RadialDim(copy, new Point2D(0.1, -10), 8)
    {
        ArrowsLocation = elementPositionType.Outside,
        TrimLeader = true
    };
    viewportLayout1.Entities.Add(rDim, Dim);
    extArc.Reverse();

    CompositeCurve cc = new CompositeCurve(internalArc, line1, line2, extArc);
    CompositeCurve nextCC = (CompositeCurve)cc.Clone();
    nextCC.Rotate((2 * Math.PI / teethNumber), Vector3D.AxisZ);
    Arc arcdf = new Arc(new Point3D(0, 0, 0), Curve.Intersection(cc, df)[1], Curve.Intersection(nextCC, df)[0]);

    for (int i = 0; i < teethNumber; i++)
    {
        CompositeCurve compCurve = (CompositeCurve)cc.Clone();
        Arc arcdfi = (Arc) arcdf.Clone();

        compCurve.Rotate((2 * Math.PI / teethNumber) * i, Vector3D.AxisZ);
        arcdfi.Rotate((2 * Math.PI / teethNumber) * i, Vector3D.AxisZ);

        viewportLayout1.Entities.Add(compCurve);
        viewportLayout1.Entities.Add(arcdfi);
    }
            
}
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.