//辺edを回転軸として面をpolのある平面上に開く
        public bool Open(Edge ed, osPolygon pol)
        {
            if (!isOpened)
            {
                Vector3D edvector = new Vector3D();
                double angle;
                Matrix rotatematrix = new Matrix(3);
                Vector3D polnormal;

                pol.SetNormal();
                polnormal = pol.normal;

                SetNormal();

                angle = Math.Acos(Vector3D.Inner(this.normal, polnormal) / (this.normal.Getnorm() * polnormal.Getnorm()));

                start_vertex = ed.vertex1;
                end_vertex = ed.vertex2;

                edvector = end_vertex.center3D - start_vertex.center3D;

                edvector.Normalization();

                rotatematrix.Set_Rotate_ArbAx(edvector, angle);

                foreach (Vertex vtx in vertex)
                    if (vtx.center3D != start_vertex.center3D && vtx.center3D != end_vertex.center3D)
                    {
                        vtx.center3D -= end_vertex.center3D;
                        vtx.center3D = vtx.center3D * rotatematrix;
                        vtx.center3D += end_vertex.center3D;
                    }

                isOpened = true;

                return true;
            }
            return false;
        }
        //カメラ座標の設定
        public void SetCaemraAxes()
        {
            CameraZ = LookatPoint - Setposition;
            CameraZ.Normalization();

            CameraX = Vector3D.Outer(Upward, CameraZ);
            CameraX.Normalization();

            CameraY = Vector3D.Outer(CameraZ, CameraX);
        }
        //可視判定
        public double Hidden(Vector3D vtr3D)
        {
            Vector3D vector1 = new Vector3D();
            Vector3D vector2 = new Vector3D();
            Vector3D outer = new Vector3D();
            Vector3D S = new Vector3D();
            double cos;

            vector1 = vertex[2].center3D - vertex[0].center3D;
            vector2 = vertex[1].center3D - vertex[0].center3D;
            outer = Vector3D.Outer(vector1, vector2);

            S = vertex[0].center3D - vtr3D;

            outer.Normalization();
            S.Normalization();

            cos = Vector3D.Inner(S, outer);

            if (cos < 0)
            {
                outer = Vector3D.Outer(vector2, vector1);

                outer.Normalization();
                S.Normalization();

                cos = Vector3D.Inner(S, outer);
            }

            return cos;
        }
        //カメラの回転
        public void RotateCamera(double x1, double y1, double x2, double y2)
        {
            Vector2D A = new Vector2D();
            Vector3D N1 = new Vector3D();
            Vector3D N2 = new Vector3D();
            Vector3D temp = new Vector3D();

            double alpha, beta;
            float x, y, z;

            N1.X = Setposition.Y;
            N1.Y = -Setposition.X;
            N1.Z = LookatPoint.Z;

            N1.Normalization();

            N2.X = LookatPoint.X;
            N2.Y = LookatPoint.Y;
            N2.Z = 1;

            N2.Normalization();

            if (Upward.Z > 0)
            {
                A.X = (float)((x2 - x1) / w);
                A.Y = (float)((y2 - y1) / h);
            }
            if (Upward.Z < 0)
            {
                A.X = (float)((x1 - x2) / w);
                A.Y = (float)((y1 - y2) / h);
            }

            alpha = 2 * Math.PI * A.Y;
            beta = 2 * Math.PI * A.X;

            x = Setposition.X;
            y = Setposition.Y;
            z = Setposition.Z;

            rotatematrix.Set_Rotate_ArbAx(N1, alpha);

            temp = Setposition * rotatematrix;

            rotatematrix.Set_Rotate_ArbAx(N2, beta);

            temp = temp * rotatematrix;

            SetPosition(temp.X, temp.Y, temp.Z);

            if (Vector3D.Inner(temp2, Setposition - LookatPoint) > 0 && Upward.Z > 0) Upward.Z = -Upward.Z;

            if (Vector3D.Inner(temp2, Setposition - LookatPoint) < 0 && Upward.Z < 0) Upward.Z = -Upward.Z;

            if (Upward.Z > 0) temp2.Set(-Setposition.X, -Setposition.Y, LookatPoint.Z);

            if (Upward.Z < 0) temp2.Set(Setposition.X, Setposition.Y, LookatPoint.Z);
        }