FAQ
ArcObjects で円または弧を作成する方法

ナレッジ番号:5275 | 登録日:2023/07/26 | 更新日:2024/11/21

概要

このサンプル コードは、円または弧を作成する方法を示します。

サンプル コード

中心点・半径・方向を指定した完全な円の作成

IConstructCircularArc.ConstructCircle を利用します。

public ICircularArc CreateCircleArc(IPoint point, double radius, bool isCCW)
{
    ICircularArc pCircularArc = new CircularArcClass();
    IConstructCircularArc pConstrutionCircularArc = pCircularArc as IConstructCircularArc;
    pConstrutionCircularArc.ConstructCircle(point, radius, isCCW);
    return pCircularArc;
}
Public Function CreateCircleArc(ByVal pCPoint As ESRI.ArcGIS.Geometry.IPoint, ByVal Radius As Double, ByVal IsCCW As Boolean) As ESRI.ArcGIS.Geometry.ICircularArc
    Dim pConstCArc As IConstructCircularArc = New CircularArcClass()
    pConstCArc.ConstructCircle(pCPoint, Radius, IsCCW)
    CreateCircleArc = pConstCArc
End Function

中心点・開始角・中心角・半径を指定した作成

ICircularArc::PutCoordsByAngle を利用します。

角度は水平を0度とするラジアンで与えます。
public ICircularArc CreateArc2(IPoint pCPoint, double fromAngle, double centralAngle, double Radius){
     ICircularArc pArc = new CircularArcClass();
     pArc.PutCoordsByAngle(pCPoint, fromAngle, centralAngle, Radius);
     return pArc;
}
Public Function CreateArc2(ByVal pCPoint As ESRI.ArcGIS.Geometry.IPoint, ByVal fromAngle As Double, ByVal centralAngle As Double, ByVal Radius As Double) As ESRI.ArcGIS.Geometry.ICircularArc
        Dim pArc As ICircularArc = New CircularArcClass()
        pArc.PutCoordsByAngle(pCPoint, fromAngle, centralAngle, Radius)
        CreateArc2 = pArc
End Function

円弧上の 3 点を指定した円または弧の作成

  • IConstructCircularArc::ConstructThreePoints の利用
public ICircularArc CreateCArcThreePoint(IPoint FromPoint, IPoint ThruPoint, IPoint ToPoint)
{
    ICircularArc pCircularArc = new CircularArcClass();
    IConstructCircularArc pConstrutionCircularArc = pCircularArc as IConstructCircularArc;
    pConstrutionCircularArc.ConstructThreePoints(FromPoint, ThruPoint, ToPoint, true);
    //第4引数を Trueにすると、1点目と3点目が同じ点の場合に1点目と2点目を結んだ線を直径とする円を定義する。
    //第4引数をFalseにすると、1点目と3点目が同じ点の場合に円は定義されない
    return pCircularArc;
}
Public Function CreateCArcThreePoint(ByVal FromPoint As ESRI.ArcGIS.Geometry.IPoint, ByVal ThruPoint As ESRI.ArcGIS.Geometry.IPoint, ByVal ToPoint As ESRI.ArcGIS.Geometry.IPoint) As ESRI.ArcGIS.Geometry.ICircularArc
    Dim ConstCArc As ESRI.ArcGIS.Geometry.IConstructCircularArc = New ESRI.ArcGIS.Geometry.CircularArc
    ConstCArc.ConstructThreePoints(FromPoint, ThruPoint, ToPoint, True)
    '第4引数を Trueにすると、1点目と3点目が同じ点の場合に1点目と2点目を結んだ線を直径とする円を定義する。
    '第4引数をFalseにすると、1点目と3点目が同じ点の場合に円は定義されない。
    CreateCArcThreePoint = ConstCArc
End Function

呼び出し例(共通)

protected override void OnClick()
{
    IPoint CenterPoint = new PointClass();
    CenterPoint.PutCoords(0, 0); // 中心点
    double rad = 800; //半径
    DrawCircle(CreateCircleArc(CenterPoint, rad, true));

    double fAngle = 45.0;
    double cAngle = 135.0;
    double fAngle_radian;
    double cAngle_radian;

    fAngle_radian = fAngle * 2 * System.Math.PI / 360;
    cAngle_radian = cAngle * 2 * System.Math.PI / 360;
    DrawCircle(CreateArc2(CenterPoint, fAngle_radian, cAngle_radian, rad));

    IPoint firstPoint = new PointClass();
    firstPoint.PutCoords(0, 0); // 1点目
    IPoint secondPoint = new PointClass();
    secondPoint.PutCoords(0, 1000); // 2点目
    IPoint thirdPoint = new PointClass();
    thirdPoint.PutCoords(1000, 1000); // 3点目

    //drawcircle(CreateCArcThreePoint(firstPoint, secondPoint, firstPoint)); // 円にする場合
    DrawCircle(CreateCArcThreePoint(firstPoint, secondPoint, thirdPoint)); // 弧にする場合
}
public void DrawCircle(ICircularArc pSegment)
{
    ISegmentCollection pseg = new PolylineClass();
    pseg.AddSegment((ISegment)pSegment);
    IPolyline ppolyline = (IPolyline)pseg;
    ILineElement LineEle = new LineElementClass();
    ((IElement)LineEle).Geometry = ppolyline;
    ((IGraphicsContainer)ArcMap.Document.FocusMap).AddElement((IElement)LineEle, 0);
    ArcMap.Document.ActiveView.Refresh();
}
Protected Overrides Sub OnClick()
    Dim CenterPoint As IPoint = New PointClass()
    CenterPoint.PutCoords(0, 0) '中心点
    Dim rad As Double = 800     '半径
    drawcircle(CreateCircleArc(CenterPoint, rad, True))

    Dim fAngle As Double = 45
    Dim cAngle As Double = 120
    Dim fAngle_radian As Double
    Dim cAngle_radian As Double
    fAngle_radian = fAngle * 2 * System.Math.PI / 360
    cAngle_radian = cAngle * 2 * System.Math.PI / 360
    DrawCircle(CreateArc2(CenterPoint, fAngle_radian, cAngle_radian, 900))

    Dim firstPoint As IPoint = New PointClass()
    firstPoint.PutCoords(0, 0) '1点目
    Dim secondPoint As IPoint = New PointClass()
    secondPoint.PutCoords(0, 1000) '2点目
    Dim thirdPoint As IPoint = New PointClass()
    thirdPoint.PutCoords(1000, 1000) '3点目

    DrawCircle(CreateCArcThreePoint(firstPoint, secondPoint, firstPoint)) '円にする場合
    DrawCircle(CreateCArcThreePoint(firstPoint, secondPoint, thirdPoint)) '弧にする場合
End Sub
Public Sub DrawCircle(pSegment As ICircularArc)
    Dim pseg As ISegmentCollection = New PolylineClass()
    pseg.AddSegment(CType(pSegment, ISegment))
    Dim ppolyline As IPolyline = CType(pseg, IPolyline)
    Dim LineEle As ILineElement = New LineElementClass()
    CType(LineEle, IElement).Geometry = ppolyline
    CType(My.ArcMap.Document.FocusMap, IGraphicsContainer).AddElement(CType(LineEle, IElement), 0)
    My.ArcMap.Document.ActiveView.Refresh()
End Sub

メタデータ

機能

種類

製品