凸多角形に関する最遠点対問題(整数型)
Namespace: fvalgcliAssembly: fvalgcli (in fvalgcli.dll) Version: 3.1.0.0 (3.1.0.11)
Syntax
C# |
---|
public static int fnFIE_cg_convex_polygon_diameter( PNT_T_PTR vrtx, int num, ref int ans_pnt1, ref int ans_pnt2, ref int diameter ) |
Visual Basic |
---|
Public Shared Function fnFIE_cg_convex_polygon_diameter ( vrtx As PNT_T_PTR, num As Integer, ByRef ans_pnt1 As Integer, ByRef ans_pnt2 As Integer, ByRef diameter As Integer ) As Integer |
Parameters
- vrtx
- Type: fvalgcli..::..PNT_T_PTR
凸多角形の頂点列
- num
- Type: System..::..Int32
頂点数
- ans_pnt1
- Type: System..::..Int32%
回答点の番号1( vrtx の配列番号)
- ans_pnt2
- Type: System..::..Int32%
回答点の番号2( vrtx の配列番号)
- diameter
- Type: System..::..Int32%
最も離れている2点の距離(集合の直径)の2乗
Return Value
Type: Int32以下のエラーコードを返します。
エラーコード:
f_err | 内容 |
---|---|
F_ERR_NONE | 正常終了 |
F_ERR_INVALID_PARAM | 不正なパラメータが渡された |
F_ERR_CALC_IMPOSSIBLE | 頂点列が凸多角形ではないため、計算不能(頂点数が3以上の場合) |
F_ERR_NO_LICENCE | ライセンスエラー、または未初期化エラー |
Remarks
Examples
C# | Copy |
---|---|
// $Revision: 1.1 $ using System; using System.Collections.Generic; using System.Text; using fvalgcli; namespace TC { public partial class FIE { [FvPluginExecute] public void fnFIE_cg_convex_polygon_diameter() { int status = (int)f_err.F_ERR_NONE; PNT_T_PTR vrtx = PNT_T_PTR.Zero; // 凸多角形の頂点列. int num; // 頂点数. int ans_pnt1 = new int(); // 回答点の番号1( vrtx の配列番号). int ans_pnt2 = new int(); // 回答点の番号2( vrtx の配列番号). int diameter = new int(); // 最も離れている2点の距離(集合の直径)の2乗. try { // 凸多角形の頂点列を確保、設定する. num = 5; vrtx = PNT_T_PTR.alloc(num); vrtx[0] = PNT_T.init(3, 13); vrtx[1] = PNT_T.init(5, 28); vrtx[2] = PNT_T.init(15, 28); vrtx[3] = PNT_T.init(22, 24); vrtx[4] = PNT_T.init(25, 2); // 期待値. int calc_pnt1 = new int(); int calc_pnt2 = new int(); int calc_diameter = int.MinValue; for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { int d = (int)(Math.Pow((vrtx[i].x - vrtx[j].x), 2) + Math.Pow((vrtx[i].y - vrtx[j].y), 2)); if (d > calc_diameter) { calc_diameter = d; calc_pnt1 = i; calc_pnt2 = j; } } } // 凸多角形に関する最遠点対問題(整数型). status = api.fnFIE_cg_convex_polygon_diameter(vrtx, num, ref ans_pnt1, ref ans_pnt2, ref diameter); Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "エラーが発生しました。({0})", (f_err)status); // 結果を出力する. ConsoleOut.WriteFunctionName(":\n"); Console.Write("\tans_pnt1={0}({1}, {2}), ans_pnt2={3}({4}, {5}), diameter={6} ...", ans_pnt1, vrtx[ans_pnt1].x, vrtx[ans_pnt1].y, ans_pnt2, vrtx[ans_pnt2].x, vrtx[ans_pnt2].y, diameter); ConsoleOut.IsTrue( calc_diameter == diameter && ((calc_pnt1 == ans_pnt1 && calc_pnt2 == ans_pnt2) || (calc_pnt1 == ans_pnt2 && calc_pnt2 == ans_pnt1)) ); } finally { vrtx.Dispose(); } } } } |
Visual Basic | Copy |
---|---|
' $Revision: 1.1 $ Imports System.Collections.Generic Imports System.Text Imports fvalgcli Public Partial Class FIE <FvPluginExecute> _ Public Sub fnFIE_cg_convex_polygon_diameter() Dim status As Integer = CInt(f_err.F_ERR_NONE) Dim vrtx As PNT_T_PTR = PNT_T_PTR.Zero ' 凸多角形の頂点列. Dim num As Integer ' 頂点数. Dim ans_pnt1 As New Integer() ' 回答点の番号1( vrtx の配列番号). Dim ans_pnt2 As New Integer() ' 回答点の番号2( vrtx の配列番号). Dim diameter As New Integer() ' 最も離れている2点の距離(集合の直径)の2乗. Try ' 凸多角形の頂点列を確保、設定する. num = 5 vrtx = PNT_T_PTR.alloc(num) vrtx(0) = PNT_T.init(3, 13) vrtx(1) = PNT_T.init(5, 28) vrtx(2) = PNT_T.init(15, 28) vrtx(3) = PNT_T.init(22, 24) vrtx(4) = PNT_T.init(25, 2) ' 期待値. Dim calc_pnt1 As New Integer() Dim calc_pnt2 As New Integer() Dim calc_diameter As Integer = Integer.MinValue For i As Integer = 0 To num - 1 For j As Integer = 0 To num - 1 Dim d As Integer = CInt(Math.Truncate(Math.Pow((vrtx(i).x - vrtx(j).x), 2) + Math.Pow((vrtx(i).y - vrtx(j).y), 2))) If d > calc_diameter Then calc_diameter = d calc_pnt1 = i calc_pnt2 = j End If Next Next ' 凸多角形に関する最遠点対問題(整数型). status = api.fnFIE_cg_convex_polygon_diameter(vrtx, num, ans_pnt1, ans_pnt2, diameter) Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "エラーが発生しました。({0})", CType(status, f_err)) ' 結果を出力する. ConsoleOut.WriteFunctionName(":" & vbLf) Console.Write(vbTab & "ans_pnt1={0}({1}, {2}), ans_pnt2={3}({4}, {5}), diameter={6} ...", ans_pnt1, vrtx(ans_pnt1).x, vrtx(ans_pnt1).y, ans_pnt2, vrtx(ans_pnt2).x, _ vrtx(ans_pnt2).y, diameter) ConsoleOut.IsTrue(calc_diameter = diameter AndAlso ((calc_pnt1 = ans_pnt1 AndAlso calc_pnt2 = ans_pnt2) OrElse (calc_pnt1 = ans_pnt2 AndAlso calc_pnt2 = ans_pnt1))) Finally vrtx.Dispose() End Try End Sub End Class |