我的表格里面有三列ID,GInfo,Rotation
其中GInfo是geometry类型的数据,里面是Polygon. 我现在想选出GInfo里面startpoint的矢量夹角=Rotation的数值的数据如果上面过于复杂,下面有两个自定义的点。我该如何写才能得到其矢量夹角=180度或者PI呢
谢谢
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('POINT(20 10)', 0);
SET @h = geometry::STGeomFromText('POINT(10 10)', 0);

解决方案 »

  1.   

    忘记说了,我可以找到distance,但是我要的是夹角
      

  2.   

    我尝试用比较简单的atan来做但是这个方法不会自动滤掉y2-y1=0的情况怎么才能比较聪明的作这个呢,快被刺激死了
      

  3.   

    2个点怎么夹?如果是求2个点分别与point(0 0)的连线 之间的夹角,那就容易办,换算成为极坐标。
      

  4.   

    这个很难吗?
    (2点重合算90度=pi/2,)select a_gh=
    case 
    when @[email protected] then 
         case when @g.STY<[email protected] then pi()/2 else 1.5*pi() end 
    else case 
         when @g.STX<@h.STX and @g.STY<[email protected] then atan((@[email protected])/(@[email protected]))
         when @g.STX>@h.STX and @g.STY<[email protected] then pi()-atan((@[email protected])/(@[email protected]))
         when @g.STX<@h.STX and @g.STY>[email protected] then pi()+atan((@[email protected])/(@[email protected]))
         when @g.STX>@h.STX and @g.STY>[email protected] then 2*pi()-atan((@[email protected])/(@[email protected]))
         end
    end
      

  5.   

    你这样我也会算的,这是我觉得这样不简洁。一个query里面要写好多,不知道spatial data本身有没有好的函数
      

  6.   

    之所以写这么多,是因为我们国内的解析几何跟欧美那边好像不是很统一,我们的象限角是从0~2pi,而计算机里面是正负pi,所以才需要那么多转换,要不就一对case when。