vb.净代码两个解决方案之间有什么区别 [英] vb. net code what diffreance between two solution

查看:100
本文介绍了vb.净代码两个解决方案之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一种编码类型:
Visual Basic的Atn函数仅返回Pi和-Pi之间的值.此例程显示了如何在其他两个象限中找到正确的角度.
您向Atan2函数传递了沿感兴趣方向的X和Y偏移量.该函数使用偏移量的符号来找出要返回的象限.它寻找非常小的X偏移量,这将在计算Atn(y/x)时产生不确定的错误,并使用Atn计算其他值.

1st Type of Coding :
Visual Basic''s Atn function only returns values between Pi and -Pi. This routine shows how to find correct angles in the other two quadrants.
You pass the Atan2 function the X and Y offsets in the direction of interest. The function uses the signs of the offsets to figure out which quadrant to return. It looks for very small X offsets which would produce an undefined error in calculating Atn(y / x) and uses Atn to calculate other values.

Public Function Atan2(ByVal y As Double, ByVal x As Double) _
    As Double
  Dim theta As Double

  If (Abs(x	) < 0.0000001) Then
    If (Abs(y) < 0.0000001) Then
      theta = 0#
    ElseIf (y > 0#) Then
      theta = 1.5707963267949
    Else
      theta = -1.5707963267949
    End If
  Else
    theta = Atn(y / x)
  
    If (x < 0) Then
      If (y >= 0#) Then
        theta = 3.14159265358979 + theta
      Else
        theta = theta - 3.14159265358979
      End If
    End If
  End If
    
  Atan2 = theta
End Function


第二种编码类型:

可以这样模拟非常有用的atan2函数(计算矢量的四个象限中的角度):


2nd Type of coding :

The very useful atan2 function (calculate the angle in all four quadrants of a vector) can be simulated like this:

Public Const Pi As Double = 3.14159265358979
  
Public Function Atan2(ByVal y As Double, ByVal x As Double) As Double
 
    If y > 0 Then
      If x >= y Then
        Atan2 = Atn(y / x)
      ElseIf x <= -y Then
        Atan2 = Atn(y / x) + Pi
      Else
        Atan2 = Pi / 2 - Atn(x / y)
      End If
    Else
      If x >= -y Then
        Atan2 = Atn(y / x)
      ElseIf x <= y Then
        Atan2 = Atn(y / x) - Pi
      Else
        Atan2 = -Atn(x / y) - Pi / 2
      End If
    End If
 
  End Function



//或VB.Net中#的含义及其用法.



// Or What is meaning of # in VB.Net and how its use.

推荐答案

带有dim语句的特殊字符的含义:

类型字符 字符
整数
&
十进制 @
Double #
字符串
The meanings of special characters with dim statement:

Type CharacterCharacter
Integer%
Long&
Decimal@
Single!
Double#
String




有关Double和其他数据类型的更多信息,可以在以下位置找到: http://msdn.microsoft.com /en-us/library/x99xtshc.aspx [ ^ ]


More about Double and other data types, you can find at: http://msdn.microsoft.com/en-us/library/x99xtshc.aspx[^]


这篇关于vb.净代码两个解决方案之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆