public LDLine toLine(LDPointList form) { Debug.Assert(form.length() > m_index1); Debug.Assert(form.length() > m_index2); return(new LDLine(form.at(m_index1), form.at(m_index2))); }
public LDPolygon toPolygon(LDPointList points) { Debug.Assert((points.length() > m_index1)); Debug.Assert(points.length() > m_index2); Debug.Assert(points.length() > m_index3); LDPolygon v = new LDPolygon(); v.Add(new LDPoint(points.at(m_index1))); v.Add(new LDPoint(points.at(m_index2))); v.Add(new LDPoint(points.at(m_index3))); return(v); }
public LDLineList getLines(LDPointList points) { LDLineList result = new LDLineList(); for (int i = 0; i < size(); i++) { int index1 = this.at(i).getIndex1(); int index2 = this.at(i).getIndex2(); LDPoint point1 = points.at(index1); LDPoint point2 = points.at(index2); result.Add(new LDLine(point1, point2)); } return(result); }
public void setClockWise(LDPointList form, ClockWise clockWise) { Debug.Assert(form.length() > m_index1); Debug.Assert(form.length() > m_index2); Debug.Assert(form.length() > m_index3); LDPoint v0 = form.at(m_index1); LDPoint v1 = form.at(m_index2); LDPoint v2 = form.at(m_index3); //行列式で時計回りか判定 //行列式の計算。 QMatrix3x3にはないので手動で作成。 double[,] m = new double[3, 3] { { v0.x(), v0.y(), 1 }, { v1.x(), v1.y(), 1 }, { v2.x(), v2.y(), 1 } }; double determinant = m[0, 0] * m[1, 1] * m[2, 2] + m[0, 1] * m[1, 2] * m[2, 0] + m[0, 2] * m[1, 0] * m[2, 1] - m[0, 2] * m[1, 1] * m[2, 0] - m[0, 0] * m[1, 2] * m[2, 1] - m[0, 1] * m[1, 0] * m[2, 2]; ClockWise current; if (determinant < 0) //CW { current = ClockWise.CW; } else //CCWまたは3点が一直線上など { current = ClockWise.CCW; } if (clockWise != current) //設定した順番と異なる場合 Indexを入れ替える { var p = m_index1; m_index1 = m_index2; m_index2 = p; } }