LDTriangleList simpleTriangle() { LDTriangleList triangles = new LDTriangleList(); LDTriangle t1 = new LDTriangle(0, 1, 2); triangles.Add(t1); return(triangles); }
//一つでも線を共有してるかどうか。同じ三角形でも当然共有してる public bool isSharedLine(LDTriangle t) { if (containsLine(t.getLine1())) { return(true); } if (containsLine(t.getLine2())) { return(true); } if (containsLine(t.getLine3())) { return(true); } return(false); }
// 三角形を与えてその外接円を求める public static LDCircle getCircumscribedCirclesOfTriangle(LDPointList form, LDTriangle t) { // 三角形の各頂点座標を (x1, y1), (x2, y2), (x3, y3) とし、 // その外接円の中心座標を (x, y) とすると、 // (x - x1) * (x - x1) + (y - y1) * (y - y1) // = (x - x2) * (x - x2) + (y - y2) * (y - y2) // = (x - x3) * (x - x3) + (y - y3) * (y - y3) // より、以下の式が成り立つ // // x = { (y3 - y1) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) // + (y1 - y2) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1)} / c // // y = { (x1 - x3) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) // + (x2 - x1) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1)} / c // // ただし、 // c = 2 * {(x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)} LDPoint p1 = t.getPoint1(form); LDPoint p2 = t.getPoint2(form); LDPoint p3 = t.getPoint3(form); float x1 = (float)p1.x(); float y1 = (float)p1.y(); float x2 = (float)p2.x(); float y2 = (float)p2.y(); float x3 = (float)p3.x(); float y3 = (float)p3.y(); float c = 2.0f * ((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)); float x = ((y3 - y1) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) + (y1 - y2) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1)) / c; float y = ((x1 - x3) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) + (x2 - x1) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1)) / c; LDPoint center = new LDPoint(x, y); // 外接円の半径 r は、半径から三角形の任意の頂点までの距離に等しい double r = math.PointUtil.distance(center, p1); return(new LDCircle(center, (float)r)); }
// 三角形を与えてその外接円を求める public static LDCircle getCircumscribedCirclesOfTriangle(LDPointList form, LDTriangle t) { // 三角形の各頂点座標を (x1, y1), (x2, y2), (x3, y3) とし、 // その外接円の中心座標を (x, y) とすると、 // (x - x1) * (x - x1) + (y - y1) * (y - y1) // = (x - x2) * (x - x2) + (y - y2) * (y - y2) // = (x - x3) * (x - x3) + (y - y3) * (y - y3) // より、以下の式が成り立つ // // x = { (y3 - y1) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) // + (y1 - y2) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1)} / c // // y = { (x1 - x3) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) // + (x2 - x1) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1)} / c // // ただし、 // c = 2 * {(x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)} LDPoint p1 = t.getPoint1(form); LDPoint p2 = t.getPoint2(form); LDPoint p3 = t.getPoint3(form); float x1 = (float)p1.x(); float y1 = (float)p1.y(); float x2 = (float)p2.x(); float y2 = (float)p2.y(); float x3 = (float)p3.x(); float y3 = (float)p3.y(); float c = 2.0f * ((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)); float x = ((y3 - y1) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) + (y1 - y2) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1)) / c; float y = ((x1 - x3) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) + (x2 - x1) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1)) / c; LDPoint center = new LDPoint(x, y); // 外接円の半径 r は、半径から三角形の任意の頂点までの距離に等しい double r = math.PointUtil.distance(center, p1); return new LDCircle(center, (float)r); }
//一つでも線を共有してるかどうか。同じ三角形でも当然共有してる public bool isSharedLine(LDTriangle t) { if (containsLine(t.getLine1())) { return true; } if (containsLine(t.getLine2())) { return true; } if (containsLine(t.getLine3())) { return true; } return false; }
LDTriangleList simpleTriangle() { LDTriangleList triangles=new LDTriangleList(); LDTriangle t1=new LDTriangle(0, 1, 2); triangles.Add(t1); return triangles; }