PDA

Click to See Complete Forum and Search --> : Messed up Arcsin functin in VB


Sep 16th, 2000, 12:04 AM
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.

PaulLewis
Sep 17th, 2000, 04:53 PM
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.


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

Sep 17th, 2000, 08:33 PM
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.

PaulLewis
Sep 17th, 2000, 09:10 PM
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