角度の算出(2直線)

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

Syntax

C#
public static CFviAngle Angle(
	CFviLine line1,
	CFviLine line2
)
Visual Basic
Public Shared Function Angle ( 
	line1 As CFviLine,
	line2 As CFviLine
) As CFviAngle

Parameters

line1
Type: FVIL.Data..::..CFviLine
直線1
line2
Type: FVIL.Data..::..CFviLine
直線2

Return Value

Type: CFviAngle
2直線のなす角のうち、小さい方の角度 [0~PI/2] を返します。

正常に実行できなかった場合は例外を発行します。 例外の原因と発生位置を特定するには、発行された例外クラスの 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.CFviLine,FVIL.Data.CFviLine)
        /// </remarks>
        [FvPluginExecute]
        public void Angle_line_line()
        {
            // 1) 直線の生成.
            FVIL.Data.CFviLine line1 = new FVIL.Data.CFviLine(0.5, 1, -180);
            FVIL.Data.CFviLine line2 = new FVIL.Data.CFviLine(-0.5, 1, -10);

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

            // 確認用.
            {
                // 画像、描画表示クラス、オーバーレイのインスタンスの生成.
                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.CFviGdiLine gline1 = new FVIL.GDI.CFviGdiLine(line1);
                    gline1.Pen.Color = Color.Green;
                    gline1.Pen.Width = 1;

                    // 入力線2
                    FVIL.GDI.CFviGdiLine gline2 = new FVIL.GDI.CFviGdiLine(line2);
                    gline2.Pen.Color = Color.Green;
                    gline2.Pen.Width = 1;

                    // 結果(角度)の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(line1, line2); 
                    pos.X = pos.X + 14;
                    pos.Y = pos.Y - 4;
                    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(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_line_line.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.CFviLine,FVIL.Data.CFviLine)
        ''' </remarks>
        <FvPluginExecute> _
        Public Sub Angle_line_line()
            ' 1) 直線の生成.
            Dim line1 As New FVIL.Data.CFviLine(0.5, 1, -180)
            Dim line2 As New FVIL.Data.CFviLine(-0.5, 1, -10)

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

            ' 確認用.
            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 gline1 As New FVIL.GDI.CFviGdiLine(line1)
                    gline1.Pen.Color = Color.Green
                    gline1.Pen.Width = 1

                    ' 入力線2
                    Dim gline2 As New FVIL.GDI.CFviGdiLine(line2)
                    gline2.Pen.Color = Color.Green
                    gline2.Pen.Width = 1

                    ' 結果(角度)の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(line1, line2)
                    pos.X = pos.X + 14
                    pos.Y = pos.Y - 4
                    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(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_line_line.png", dstimage)
            End If
        End Sub
    End Class
End Namespace

Exceptions

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

See Also