VectorDraw FAQ finishing: how to rotate around a point vertex polyline?

    VectorDraw Developer Framework (VDF) is an application for the visualization of graphics engine library. With VDF provides functionality that you can easily create, edit, manage, export, import and print 2D and 3D graphics files.   

    VectorDraw web library (javascript) not only can open CAD drawings, and can be displayed on any common vector object support HTML5 standard platforms such as Windows, Android, iOS and Linux. No installation, VectorDraw web library (javascript) can be run on any support the canvas tag and Javascript major browsers (Chrome, Firefox, Safari, Opera , Dolphin, Boat , etc.). This means you can use a variety of formats DXF, DWG, DGN, SKP ( Google 's Sketchup), VDML and so show your business on any desktop, tablet PCs, smart phones and portable notebook.


ask:

    How can rotate around a point in some of the vertices of the polyline (through code), the other vertices remain the same?    

answer:

This problem is very simple, you can try the following code:

      private void MyButton_Click(object sender, EventArgs e)
        {
            vdDocument doc = vdFramedControl1.BaseControl.ActiveDocument; doc.New();
            Vertexes vrts = new Vertexes();
            vrts.Add(1,1,0,0);vrts.Add(1,4,0,0);vrts.Add(4,4,0,0);vrts.Add(5,3,0,0);
            vdPolyline pl = new vdPolyline(doc, vrts);
            doc.Model.Entities.AddItem(pl);
            pl.Invalidate();
            //--------------- created the polyline ---------
           
            
            // rotate it for 45 degrees anti-clockwise around vertex[1]
            
            Vertexes orig_vert = new Vertexes(pl.VertexList);//get the vertex list of the polyline that will be changed
            gPoint pt1 = new gPoint(orig_vert[1] as gPoint);
       
            // Vertexes from Item 2 and above will change
            Vertexes keep = new Vertexes();
            keep.Add(new Vertex(orig_vert[0]));
            keep.Add(new Vertex(orig_vert[1]));

            double orig_angle = pt1.GetAngle( orig_vert[2] as gPoint); // new angle
            orig_angle += VectorDraw.Geometry.Globals.DegreesToRadians(45.0d);

            Matrix mat = new Matrix();
            mat.TranslateMatrix(-1.0d * pt1);
            mat.RotateZMatrix(orig_angle);
            mat.TranslateMatrix(pt1);
            mat.Transform(orig_vert); // this will produce the new vertexes

            for (int i = 0; i < 2; i++)
            {
                orig_vert[i] = keep[i]; // restore the vertexes that didn't changed
            }

            pl.VertexList = orig_vert;
            pl.Update();
            pl.Invalidate();

        }


Guess you like

Origin blog.51cto.com/14477114/2437165