円周上の座標値を求める関数


CREATE FUNCTION funcCirclePt
(
  @pt AS GEOMETRY,
  @deg AS REAL,
  @r AS REAL,
  @srid AS INT
)
RETURNS geometry
AS
BEGIN
  DECLARE @rad REAL = PI() * @deg / 180.0;
  DECLARE @x REAL = @pt.STX + @r * COS(@rad);
  DECLARE @y REAL = @pt.STY + @r * SIN(@rad);

 RETURN GEOMETRY::Point(@x,@y,@srid);
END

使う方

DECLARE @pt1 GEOMETRY = GEOMETRY::Point(0,0,0);
DECLARE @pt2 GEOMETRY = dbo.funcCirclePt(@pt1 ,0,   100, 0);
DECLARE @pt3 GEOMETRY = dbo.funcCirclePt(@pt1 ,45,  100, 0);
DECLARE @pt4 GEOMETRY = dbo.funcCirclePt(@pt1 ,90,  100, 0);
DECLARE @pt5 GEOMETRY = dbo.funcCirclePt(@pt1 ,180, 100, 0);
DECLARE @pt6 GEOMETRY = dbo.funcCirclePt(@pt1 ,270, 100, 0);

SELECT @pt2.STAsText();
SELECT @pt3.STAsText();
SELECT @pt4.STAsText();
SELECT @pt5.STAsText();
SELECT @pt6.STAsText();
カテゴリー: 開発 タグ: パーマリンク