角度の算出(2点)
Namespace: FVIL.CaliperAssembly: 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 |
Return Value
Type:
CFviAngle
2点から直線を生成し角度を算出して返します。
角度の範囲は、-PI/2~PI/2 の範囲です。
point1 と
point2 が同一座標の場合は、直線が定まらないため例外を発行します。
正常に実行できなかった場合は例外を発行します。
例外の原因と発生位置を特定するには、発行された例外クラスの ErrorCode メンバと Function メンバを参照してください。
エラーコード:
値 | ErrorCode メンバ | 内容 |
---|
51 | FVIL.ErrorCode.LICENSE_ERROR |
ライセンスキーが見つからない為、実行できません。
または、 FVIL._SetUp.InitVisionLibrary が実行されていません。
|
11 | FVIL.ErrorCode.INVALID_PARAMETER | パラメータに誤りがあります。 |
29 | FVIL.ErrorCode.NOT_CALCULABLE | 計算不可能です。 |
Examples
C# | Copy |
---|
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using fvalgcli;
namespace User.SampleCode
{
public partial class Caliper
{
[FvPluginExecute]
public void Angle_point_point()
{
FVIL.Data.CFviPoint point1 = new FVIL.Data.CFviPoint(80, 140);
FVIL.Data.CFviPoint point2 = new FVIL.Data.CFviPoint(240, 60);
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();
{
FVIL.GDI.CFviGdiPoint gpoint1 = new FVIL.GDI.CFviGdiPoint(point1);
gpoint1.Pen.Color = Color.Green;
gpoint1.Pen.Width = 4;
FVIL.GDI.CFviGdiPoint gpoint2 = new FVIL.GDI.CFviGdiPoint(point2);
gpoint2.Pen.Color = Color.Green;
gpoint2.Pen.Width = 4;
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;
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;
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 |
---|
Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports fvalgcli
Namespace SampleCode
Public Partial Class Caliper
<FvPluginExecute> _
Public Sub Angle_point_point()
Dim point1 As New FVIL.Data.CFviPoint(80, 140)
Dim point2 As New FVIL.Data.CFviPoint(240, 60)
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
Dim gpoint1 As New FVIL.GDI.CFviGdiPoint(point1)
gpoint1.Pen.Color = Color.Green
gpoint1.Pen.Width = 4
Dim gpoint2 As New FVIL.GDI.CFviGdiPoint(point2)
gpoint2.Pen.Color = Color.Green
gpoint2.Pen.Width = 4
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
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
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
See Also