コード例 #1
0
ファイル: JointsVDANew.cs プロジェクト: petrasvestartas/NGon
        public void CreateCut(int segmentID, Plane jointPlane0, Plane jointPlane1, double length_, ref Panel jointPanel, bool bake = false)  //, ref Panel neiPanel,) {
        //jointPlane0.Bake(40);

        //jointPlane1.Bake(40);

        {
            double e = 0;


            Polyline cut = new Polyline();

            Line segment0 = contourNoJoints[0].SegmentAt(segmentID);
            Line segment1 = contourNoJoints[1].SegmentAt(segmentID);

            double dist   = this.plane.Origin.DistanceTo(segment0.PointAt(0.5));
            double length = length_;// * dist * 0.01;


            //Rhino.RhinoApp.WriteLine(dist.ToString());

            //Intersect plate edge line and joint plane offsets
            Point3d edgePoint00 = PlaneUtil.LinePlane(segment0, jointPlane0);
            Point3d edgePoint01 = PlaneUtil.LinePlane(segment0, jointPlane1);
            Point3d edgePoint10 = PlaneUtil.LinePlane(segment1, jointPlane0);
            Point3d edgePoint11 = PlaneUtil.LinePlane(segment1, jointPlane1);

            //Get direction of a cut
            Vector3d v00 = PlaneUtil.PlanePlaneVec(planeOffset0, jointPlane0).Unit();
            Vector3d v01 = PlaneUtil.PlanePlaneVec(planeOffset0, jointPlane1).Unit();
            Vector3d v10 = PlaneUtil.PlanePlaneVec(planeOffset1, jointPlane0).Unit();
            Vector3d v11 = PlaneUtil.PlanePlaneVec(planeOffset1, jointPlane1).Unit();


            //Really f****d up way of checking which direction plane must be offseted for correct cut direction
            Point3d p0 = mesh.ClosestPoint((segment0.PointAt(0.5) + v00 * 10));
            Point3d p1 = mesh.ClosestPoint((segment0.PointAt(0.5) - v00 * 10));
            //bool moveFlag = (segment0.PointAt(0.5) + v00*10).DistanceTo(planeOffset0.Origin) < (segment0.PointAt(0.5) - v00*10).DistanceTo(planeOffset0.Origin);
            bool moveFlag = p0.DistanceToSquared((segment0.PointAt(0.5) + v00 * 10)) < p1.DistanceToSquared((segment0.PointAt(0.5) - v00 * 10));


            //if (bake) {


            //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(planeOffset0.Origin);
            //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(segment0.PointAt(0.5) + v00*100);
            //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(segment0.PointAt(0.5) - v00*100);

            //}

            //Moved Points
            Point3d innerPoint00     = (moveFlag) ? edgePoint00 + (v00 * length) : edgePoint00 - (v00 * length);
            Point3d innerPoint01     = (moveFlag) ? edgePoint01 + (v01 * length) : edgePoint01 - (v01 * length);
            Point3d innerPoint10     = (moveFlag) ? edgePoint10 + (v10 * length) : edgePoint10 - (v10 * length);
            Point3d innerPoint11     = (moveFlag) ? edgePoint11 + (v11 * length) : edgePoint11 - (v11 * length);
            Point3d innerPointCenter = (innerPoint00 + innerPoint01 + innerPoint10 + innerPoint11) * 0.25;
            //Plane perpPlane = new Plane(innerPointCenter, jointPlane0.Normal, Vector3d.CrossProduct(planeOffset0.Normal, v00));
            Plane perpPlane = new Plane(innerPointCenter, jointPlane0.Normal, planeOffset0.Normal);

            //perpPlane = perpPlane.Switch("XZ");

            //if (planeOffset0.IsValid)
            //    planeOffset0.Bake(40);

            //if (jointPlane0.IsValid)
            //    jointPlane0.Bake(40);

            //if (perpPlane.IsValid)
            //    perpPlane.Bake(40);

            innerPoint00 = perpPlane.RayPlane(edgePoint00, v00);
            innerPoint01 = perpPlane.RayPlane(edgePoint01, v01);
            innerPoint10 = perpPlane.RayPlane(edgePoint10, v10);
            innerPoint11 = perpPlane.RayPlane(edgePoint11, v11);



            //Middle points and projection to plane
            Point3d innerPointMid00 = (moveFlag) ? edgePoint00 + (v00 * length * 0.5) : edgePoint00 - (v00 * length * 0.5);
            Point3d innerPointMid01 = (moveFlag) ? edgePoint01 + (v01 * length * 0.5) : edgePoint01 - (v01 * length * 0.5);
            Point3d innerPointMid10 = (moveFlag) ? edgePoint10 + (v10 * length * 0.5) : edgePoint10 - (v10 * length * 0.5);
            Point3d innerPointMid11 = (moveFlag) ? edgePoint11 + (v11 * length * 0.5) : edgePoint11 - (v11 * length * 0.5);
            Point3d innerPointMid   = (innerPointMid00 + innerPointMid01 + innerPointMid10 + innerPointMid11) * 0.25;
            Plane   perpPlaneMid    = new Plane(innerPointMid, jointPlane0.Normal, perpPlane.YAxis);


            //if (planeOffset0.IsValid)
            //    planeOffset0.Bake(40);


            //if(perpPlaneMid.IsValid)
            //perpPlaneMid.Bake(40);

            innerPointMid00 = perpPlaneMid.RayPlane(edgePoint00, v00);
            innerPointMid01 = perpPlaneMid.RayPlane(edgePoint01, v01);
            innerPointMid10 = perpPlaneMid.RayPlane(edgePoint10, v10);
            innerPointMid11 = perpPlaneMid.RayPlane(edgePoint11, v11);



            //It is not closest point because the connection is not perpendicular to two adjacent plates
            //It might be close to perpendicular but not possible

            //edgePoint00.Bake();
            //innerPointMid00.Bake();
            //innerPointMid01.Bake();
            //edgePoint01.Bake();

            //edgePoint10.Bake();
            //innerPointMid10.Bake();
            //innerPointMid11.Bake();
            //edgePoint11.Bake();

            Polyline cut0 = new Polyline(new Point3d[] { edgePoint00, innerPointMid00 + v00 * e, innerPointMid01 + v01 * e, edgePoint01 });//perpPlane.ClosestPoint
            Polyline cut1 = new Polyline(new Point3d[] { edgePoint10, innerPointMid10 + v10 * e, innerPointMid11 + v11 * e, edgePoint11 });

            this.cuts.Add(cut0);
            this.cuts.Add(cut1);



            Polyline cutNei0 = new Polyline(new Point3d[] { innerPoint00, innerPointMid00 + v00 * -e, innerPointMid10 + v01 * -e, innerPoint10 });//perpPlane.ClosestPoint
            Polyline cutNei1 = new Polyline(new Point3d[] { innerPoint01, innerPointMid01 + v10 * -e, innerPointMid11 + v11 * -e, innerPoint11 });

            jointPanel.cuts.Add(cutNei0);
            jointPanel.cuts.Add(cutNei1);


            contour[0].InsertPolyline(cut0);
            contour[1].InsertPolyline(cut1);


            double additionalExtend = 20;

            //if (additionalExtend > 0) {
            //    Vector3d v0 = (cutNei0[0] - cutNei0[1]).UnitVector() * additionalExtend;
            //    Vector3d v1 = (cutNei0[3] - cutNei0[2]).UnitVector() * additionalExtend;
            //    cutNei0[0] += v0;
            //    cutNei0[0] += v1;

            //    v0 = (cutNei1[0] - cutNei1[1]).UnitVector() * additionalExtend;
            //    v1 = (cutNei1[3] - cutNei1[2]).UnitVector() * additionalExtend;
            //    cutNei1[0] += v0;
            //    cutNei1[0] += v1;
            //}


            cutNei0[0] = LineUtil.LineLine(cutNei0.SegmentAt(0), jointPanel.contour[0].SegmentAt((int)Math.Floor(jointPanel.contour[0].ClosestParameter(cutNei0[0]))));
            cutNei0[3] = LineUtil.LineLine(cutNei0.SegmentAt(2), jointPanel.contour[0].SegmentAt((int)Math.Floor(jointPanel.contour[0].ClosestParameter(cutNei0[3]))));

            cutNei1[0] = LineUtil.LineLine(cutNei1.SegmentAt(0), jointPanel.contour[1].SegmentAt((int)Math.Floor(jointPanel.contour[1].ClosestParameter(cutNei1[0]))));
            cutNei1[3] = LineUtil.LineLine(cutNei1.SegmentAt(2), jointPanel.contour[1].SegmentAt((int)Math.Floor(jointPanel.contour[1].ClosestParameter(cutNei1[3]))));
            jointPanel.contour[0].InsertPolyline(cutNei0);
            jointPanel.contour[1].InsertPolyline(cutNei1);

            //cutNei0.Bake();
            //cutNei1.Bake();

            //if (bake) {
            //    Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cut0);
            //    Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cut1);
            //}

            //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cutNei0);
            //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cutNei1);
        }