角度の算出(2点)

Namespace: FVIL.Caliper
Assembly: FVILbasic (in FVILbasic.dll) Version: 3.1.0.0 (3.1.0.17)

Syntax

C#
public static CFviAngle Angle(
	CFviPoint point1,
	CFviPoint point2
)
Visual Basic
Public Shared Function Angle ( 
	point1 As CFviPoint,
	point2 As CFviPoint
) As CFviAngle

Parameters

point1
Type: FVIL.Data..::..CFviPoint
直線を生成する座標点1
point2
Type: FVIL.Data..::..CFviPoint
直線を生成する座標点2

Return Value

Type: CFviAngle
2点から直線を生成し角度を算出して返します。 角度の範囲は、-PI/2~PI/2 の範囲です。 point1point2 が同一座標の場合は、直線が定まらないため例外を発行します。

正常に実行できなかった場合は例外を発行します。 例外の原因と発生位置を特定するには、発行された例外クラスの ErrorCode メンバと Function メンバを参照してください。

エラーコード:

ErrorCode メンバ内容
51FVIL.ErrorCode.LICENSE_ERROR ライセンスキーが見つからない為、実行できません。 または、 FVIL._SetUp.InitVisionLibrary が実行されていません。
11FVIL.ErrorCode.INVALID_PARAMETERパラメータに誤りがあります。
29FVIL.ErrorCode.NOT_CALCULABLE計算不可能です。

Examples

C# Copy imageCopy
//    $Revision: 1.3 $

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using fvalgcli;    // FvPluginXXXX attribute requires fvalgcli

namespace User.SampleCode
{
    public partial class Caliper
    {
        /// <summary>
        /// 角度の算出(2点)の測定.
        /// </summary>
        /// <remarks>
        /// FVIL.Caliper.Function.Angle(FVIL.Data.CFviPoint,FVIL.Data.CFviPoint)
        /// </remarks>
        [FvPluginExecute]
        public void Angle_point_point()
        {
            // 1) 2点の生成.
            FVIL.Data.CFviPoint point1 = new FVIL.Data.CFviPoint(80, 140); 
            FVIL.Data.CFviPoint point2 = new FVIL.Data.CFviPoint(240, 60);


            // 2) 計測実行.
            FVIL.Data.CFviAngle result = FVIL.Caliper.Function.Angle(point1, point2);

            // 確認用.
            {
                // 画像、描画表示クラス、オーバーレイのインスタンスの生成.
                FVIL.Data.CFviImage image = new FVIL.Data.CFviImage(320, 240, FVIL.ImageType.UC8, 1);
                FVIL.GDI.CFviDisplay display = new FVIL.GDI.CFviDisplay();
                FVIL.GDI.CFviOverlay overlay = new FVIL.GDI.CFviOverlay();

                {
                    // 描画図形の生成.
                    // 入力点1
                    FVIL.GDI.CFviGdiPoint gpoint1 = new FVIL.GDI.CFviGdiPoint(point1);
                    gpoint1.Pen.Color = Color.Green;
                    gpoint1.Pen.Width = 4;

                    // 入力点2
                    FVIL.GDI.CFviGdiPoint gpoint2 = new FVIL.GDI.CFviGdiPoint(point2);
                    gpoint2.Pen.Color = Color.Green;
                    gpoint2.Pen.Width = 4;

                    // 補助線1
                    FVIL.Data.CFviLineSegment lineseg = new FVIL.Data.CFviLineSegment(point1, point2);
                    FVIL.Data.CFviLine line = lineseg.ToCFviLine();
                    FVIL.GDI.CFviGdiLine gline1 = new FVIL.GDI.CFviGdiLine(line);
                    gline1.Pen.Color = Color.Green;
                    gline1.Pen.Width = 1;
                    gline1.Pen.Style = FVIL.GDI.PenStyle.Dot;

                    // 補助線2
                    FVIL.Data.CFviLine horz = new FVIL.Data.CFviLine(0, 1, -120);
                    FVIL.GDI.CFviGdiLine gline2 = new FVIL.GDI.CFviGdiLine(horz);
                    gline2.Pen.Color = Color.Green;
                    gline2.Pen.Width = 1;
                    gline2.Pen.Style = FVIL.GDI.PenStyle.Dot;

                    // 結果(角度)のGDI文字列の生成.
                    string str = String.Format("{0:F}°", result.Degree);
                    FVIL.GDI.CFviGdiString gStr = new FVIL.GDI.CFviGdiString(str);
                    FVIL.Data.CFviPoint pos = FVIL.Caliper.Function.CrossPoint(line, horz);
                    pos.X = pos.X + 30;
                    pos.Y = pos.Y - 15;
                    gStr.Position = pos;
                    gStr.Font.Weight = FVIL.GDI.FontWeight.Thin;    // 文字の太さ.
                    gStr.Font.Height = 12;    // 文字の高さ.
                    gStr.Font.Width = 6;    // 文字の幅.
                    gStr.Color = Color.Red;

                    // 描画図形の追加.
                    overlay.Figures.Add(gpoint1);
                    overlay.Figures.Add(gpoint2);
                    overlay.Figures.Add(gline1);
                    overlay.Figures.Add(gline2);
                    overlay.Figures.Add(gStr);
                    overlay.Enable = true;
                }

                // 画像表示クラスへの追加.
                display.Overlays.Add(overlay);
                display.Image = image;
                display.DisplayRect = image.Window;

                // 描画イメージの保存.
                FVIL.Data.CFviImage dstimage = new FVIL.Data.CFviImage();
                display.SaveImage(dstimage);
                FVIL.File.Function.SaveImageFile(Defs.ResultDir + "/Caliper.Angle_point_point.png", dstimage);
            }
        }
    }
}


Visual Basic Copy imageCopy
'    $Revision: 1.1 $

Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports fvalgcli
' FvPluginXXXX attribute requires fvalgcli
Namespace SampleCode
    Public Partial Class Caliper
        ''' <summary>
        ''' 角度の算出(2点)の測定.
        ''' </summary>
        ''' <remarks>
        ''' FVIL.Caliper.Function.Angle(FVIL.Data.CFviPoint,FVIL.Data.CFviPoint)
        ''' </remarks>
        <FvPluginExecute> _
        Public Sub Angle_point_point()
            ' 1) 2点の生成.
            Dim point1 As New FVIL.Data.CFviPoint(80, 140)
            Dim point2 As New FVIL.Data.CFviPoint(240, 60)


            ' 2) 計測実行.
            Dim result As FVIL.Data.CFviAngle = FVIL.Caliper.[Function].Angle(point1, point2)

            ' 確認用.
            If True Then
                ' 画像、描画表示クラス、オーバーレイのインスタンスの生成.
                Dim image As New FVIL.Data.CFviImage(320, 240, FVIL.ImageType.UC8, 1)
                Dim display As New FVIL.GDI.CFviDisplay()
                Dim overlay As New FVIL.GDI.CFviOverlay()

                If True Then
                    ' 描画図形の生成.
                    ' 入力点1
                    Dim gpoint1 As New FVIL.GDI.CFviGdiPoint(point1)
                    gpoint1.Pen.Color = Color.Green
                    gpoint1.Pen.Width = 4

                    ' 入力点2
                    Dim gpoint2 As New FVIL.GDI.CFviGdiPoint(point2)
                    gpoint2.Pen.Color = Color.Green
                    gpoint2.Pen.Width = 4

                    ' 補助線1
                    Dim lineseg As New FVIL.Data.CFviLineSegment(point1, point2)
                    Dim line As FVIL.Data.CFviLine = lineseg.ToCFviLine()
                    Dim gline1 As New FVIL.GDI.CFviGdiLine(line)
                    gline1.Pen.Color = Color.Green
                    gline1.Pen.Width = 1
                    gline1.Pen.Style = FVIL.GDI.PenStyle.Dot

                    ' 補助線2
                    Dim horz As New FVIL.Data.CFviLine(0, 1, -120)
                    Dim gline2 As New FVIL.GDI.CFviGdiLine(horz)
                    gline2.Pen.Color = Color.Green
                    gline2.Pen.Width = 1
                    gline2.Pen.Style = FVIL.GDI.PenStyle.Dot

                    ' 結果(角度)のGDI文字列の生成.
                    Dim str As String = [String].Format("{0:F}°", result.Degree)
                    Dim gStr As New FVIL.GDI.CFviGdiString(str)
                    Dim pos As FVIL.Data.CFviPoint = FVIL.Caliper.[Function].CrossPoint(line, horz)
                    pos.X = pos.X + 30
                    pos.Y = pos.Y - 15
                    gStr.Position = pos
                    gStr.Font.Weight = FVIL.GDI.FontWeight.Thin
                    ' 文字の太さ.
                    gStr.Font.Height = 12
                    ' 文字の高さ.
                    gStr.Font.Width = 6
                    ' 文字の幅.
                    gStr.Color = Color.Red

                    ' 描画図形の追加.
                    overlay.Figures.Add(gpoint1)
                    overlay.Figures.Add(gpoint2)
                    overlay.Figures.Add(gline1)
                    overlay.Figures.Add(gline2)
                    overlay.Figures.Add(gStr)
                    overlay.Enable = True
                End If

                ' 画像表示クラスへの追加.
                display.Overlays.Add(overlay)
                display.Image = image
                display.DisplayRect = image.Window

                ' 描画イメージの保存.
                Dim dstimage As New FVIL.Data.CFviImage()
                display.SaveImage(dstimage)
                FVIL.File.[Function].SaveImageFile(Defs.ResultDir & "/Caliper.Angle_point_point.png", dstimage)
            End If
        End Sub
    End Class
End Namespace

Exceptions

ExceptionCondition
FVIL..::..CFviExceptionこの例外の原因については、上記のエラーコード表をご参照ください。

See Also