Results 1 to 4 of 4

Thread: Messed up Arcsin functin in VB

  1. #1
    Guest
    Hi all.

    I have VB5, which does not have any function for "Arcsin". Help files describe some trick using a function using "Ant" and "Sqr", but that function does not seem to work well. Arcsin(1), which should return pi/2 returns an error because of a divisionby zero.

    Is there some sort of API function I could use?

    Thanks.

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Try this

    You are correct but all it means is that you have to check for values of x such that 1-x^2 = 0. In other words, x=1 or x=-1.

    In these cases you have to do a different calculation

    Hope it helps.

    Code:
    Public Function ArcSin(x As Variant) As Variant
      ' inverse since defined as:
      ' y = arcsin(x) where x = sin(y)
      ' limits: -1 <= x <= 1, -pi/2 <= y <= pi/2
      '
      
      Dim b As Double
      Dim pi As Double
      pi = Atn(1) * 4 ' thi sis pi and saves us typing it in
      
      If -1# <= x And x <= 1# Then
        b = Sqr(1# - x * x)
        If b <> 0# Then
          ArcSin = Atn(x / b)
        Else
          ArcSin = 0.5 * pi * ((x = -1#) - (x = 1#))
        End If
      Else
        ArcSin = "Invalid parameter for x"
      End If
    End Function
    Paul Lewis

  3. #3
    Guest
    Ok. Thanks Paul.

    I needed that function to calculate angles (according to given x,y points) to specify to the "Circle" function in VB in order to draw an arc instead of a circle . I decided to use the "Arc" API function instead. I didn't have to calculate Arcsin anymore since this functions simply needs the starting and ending points of the arc, which I had in the first place (points clicked on the screen).

    Although I will keep your function for further use. I will certainly need it.

    Thanks.

    P.S.: I will keep you informed of my CAD project, I'm getting there. Know I just need to know how to rotate texts, which I believe is described somewhere in this web site.

  4. #4
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    No problem

    For your new enquiry, start a new topic if you need to, but a keyword for you is CreateFont (API Call).

    If you get stuck in your search, post the new topic and I or someone will be able to fire up some code for you.

    Regards
    Paul Lewis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width