凸多角形に関する最遠点対問題(浮動小数点型)

Namespace: fvalgcli
Assembly: fvalgcli (in fvalgcli.dll) Version: 3.1.0.0 (3.1.0.11)

Syntax

C#
public static int fnFIE_cg_convex_polygon_diameter_d(
	DPNT_T_PTR vrtx,
	int num,
	ref int ans_pnt1,
	ref int ans_pnt2,
	ref double diameter
)
Visual Basic
Public Shared Function fnFIE_cg_convex_polygon_diameter_d ( 
	vrtx As DPNT_T_PTR,
	num As Integer,
	ByRef ans_pnt1 As Integer,
	ByRef ans_pnt2 As Integer,
	ByRef diameter As Double
) As Integer

Parameters

vrtx
Type: fvalgcli..::..DPNT_T_PTR
凸多角形の頂点列
num
Type: System..::..Int32
頂点数
ans_pnt1
Type: System..::..Int32%
回答点の番号1( vrtx の配列番号)
ans_pnt2
Type: System..::..Int32%
回答点の番号2( vrtx の配列番号)
diameter
Type: System..::..Double%
最も離れている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 imageCopy
//    $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_d()
        {
            int status = (int)f_err.F_ERR_NONE;

            DPNT_T_PTR vrtx = DPNT_T_PTR.Zero;    // 凸多角形の頂点列.
            int num;        // 頂点数
            int ans_pnt1 = new int();            // 回答点の番号1( vrtx の配列番号).
            int ans_pnt2 = new int();            // 回答点の番号2( vrtx の配列番号).
            double diameter = new double();        // 最も離れている2点の距離(集合の直径)の2乗.

            try
            {
                // 凸多角形の頂点列を確保、設定する.
                num = 5;
                vrtx = DPNT_T_PTR.alloc(num);

                vrtx[0] = DPNT_T.init(3, 13);
                vrtx[1] = DPNT_T.init(5, 28);
                vrtx[2] = DPNT_T.init(15, 28);
                vrtx[3] = DPNT_T.init(22, 24);
                vrtx[4] = DPNT_T.init(25, 2);

                // 期待値.
                int calc_pnt1 = new int();
                int calc_pnt2 = new int();
                double calc_diameter = double.MinValue;

                for (int i = 0; i < num; i++)
                {
                    for (int j = 0; j < num; j++)
                    {
                        double d = 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_d(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:f3} ...",
                    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 imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text

Imports fvalgcli

Public Partial Class FIE
    <FvPluginExecute> _
    Public Sub fnFIE_cg_convex_polygon_diameter_d()
        Dim status As Integer = CInt(f_err.F_ERR_NONE)

        Dim vrtx As DPNT_T_PTR = DPNT_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 Double()
        ' 最も離れている2点の距離(集合の直径)の2乗.
        Try
            ' 凸多角形の頂点列を確保、設定する.
            num = 5
            vrtx = DPNT_T_PTR.alloc(num)

            vrtx(0) = DPNT_T.init(3, 13)
            vrtx(1) = DPNT_T.init(5, 28)
            vrtx(2) = DPNT_T.init(15, 28)
            vrtx(3) = DPNT_T.init(22, 24)
            vrtx(4) = DPNT_T.init(25, 2)

            ' 期待値.
            Dim calc_pnt1 As New Integer()
            Dim calc_pnt2 As New Integer()
            Dim calc_diameter As Double = Double.MinValue

            For i As Integer = 0 To num - 1
                For j As Integer = 0 To num - 1
                    Dim d As Double = 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_d(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:f3} ...", 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

See Also