3D Threaded bolt
Previous Topic  Next Topic 

 

 

        3D Threaded bolt

 

 

 

 

               // Create a 3D polyline.

            sdPolyline poly = fDrawCtrl1.Document.CreatePolyline();

 

            // Create a helix polyline.

            double sudut, theta;

            double DUAPI = 2 * 22 / 7.0;

            int bil = 20;

            theta = DUAPI / (bil);

            double radius = 2;

 

            double h = 0;

            double speed = 0.2;

            for (int i = 0; i < 8; i++)

            {

                for (int j = 0; j < bil; j++)

                {

                    sudut = (j) * theta;

                    Point3D tmp = new Point3D(0, 0, 0);

                    tmp.X = radius * Math.Cos(sudut);

                    tmp.Y = radius * Math.Sin(sudut);

                    tmp.z = h;

                    poly.AddVertex(tmp);

                    h += speed;

                }

            }

 

            // Create a triangle profile

            sdLwPolyline po = fDrawCtrl1.Document.CreateLwPolyline();

            po.AddVertex(new Point3D(0, 0, 0));

            po.AddVertex(new Point3D(2, 1, 0));

            po.AddVertex(new Point3D(2, -1, 0));

            // Create an extruded solid along the helix path.

            sd3dSolid thread = fDrawCtrl1.Document.AddSolidExtruded(po, poly.VertexList);

            poly.Dispose();

 

            // Create a cylinder

            thread.Move(new Point3D(0, 0, 1));

            sd3dSolid cylin = fDrawCtrl1.Document.AddSolidCylinder(Point3D.Zero, 1.5, 34, 10);

            sd3dSolid cone = fDrawCtrl1.Document.AddSolidCone(new Point3D(0, 0, 34), 1.5, 2, 10);

 

            double h0 = 6;

            double h1 = 3;

            double angle = Math.Atan(h1 / 0.5);

 

            sdCircle cir = fDrawCtrl1.Document.CreateCircle(new Point3D(0, 0, 0), 2);

            sd3dSolid Cyn0 = fDrawCtrl1.Document.AddSolidCylinder(new Point3D(0, 0, -(h0 + h1)), 2, h0, 20);

            sd3dSolid Cyn1 = fDrawCtrl1.Document.AddSolidExtruded(cir, h1, sdMath.ToDegree(angle));

            Cyn1.Move(new Point3D(0, 0, -h1));

 

            // Create bolt head.

            sd3dSolid hexagon = fDrawCtrl1.Document.AddSolidCylinder(new Point3D(0, 0, 0), 4, 2, 6);

            cir = fDrawCtrl1.Document.CreateCircle(new Point3D(0, 0, 0), 4);

            sd3dSolid Cyn = fDrawCtrl1.Document.AddSolidExtruded(cir, 1, 80);

            Cyn.Move(new Point3D(0, 0, 2));

            sd3dSolid pA = fDrawCtrl1.Document.AddSolidOpUnion(hexagon, Cyn, falsefalse);

            sd3dSolid pB = fDrawCtrl1.Document.AddSolidCylinder(new Point3D(0, 0, 0), 4, 3, 6);

            sd3dSolid BoltHead = fDrawCtrl1.Document.AddSolidOpIntersect(pA, pB, falsefalse);

            // rotate the bolt head.

            BoltHead.Rotate(Point3D.Zero, Point3D.UnitX, 180);

            BoltHead.Move(new Point3D(0, 0, -(h0 + h1)));

 

            List<sd3dSolid> solids = new List<sd3dSolid>();

            solids.Add(thread);

            solids.Add(cylin);

            solids.Add(cone);

            solids.Add(Cyn0);

            solids.Add(Cyn1);

 

 

            for (int i = 0; i < solids.Count; i++)

            {

                // Apply Union operation on both of the solid and return the resulting solid to BoltHead

                BoltHead = fDrawCtrl1.Document.AddSolidOpUnion(BoltHead, solids[i], falsefalse);

            }

 

            BoltHead.EdgeAngle = 80;

            fDrawCtrl1.Document.ZoomAll();

            fDrawCtrl1.Refresh();

 

            fDrawCtrl1.Document.SetShade(falsefalsefalsetrue);