Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: swetha22 on January 02, 2009, 01:10:01 PM
-
i was trying to get angle of x,y .Please check the following code and tell me what i am doing wrong .
assumed result of xangle is 45 and i am getting 37.20.
Dim x1
Dim x2
Dim y1
Dim y2
Dim x0
Dim y0
Dim hy
Dim ad
Dim aasine
Dim xan
x1 = -50
x2 = 0
y1 = 0
y2 =50
x0 = (x2-x1)^2
y0 = (y2-y1)^2
hy = Sqr(x0+y0)
ad = x2 - x1
aasine = (ad/hy)
xangle = (Sin(aasine)*180/3.142857142857)
Print("x0 is " & x0)
Print ("y0 is "& y0)
Print ("hypotenuse is "& hy)
Print ("aasin is "& Aasine)
Print ("xangle is "& xangle)
thanks
krishna
-
Funny I just got done writing code for this but in Flash ;)
http://alphagraphicdesigns.com/HQ_Updates/examples/2point_Rotation.html
Try this in VB:
Private Const PI As Double = 3.14159265358979
pt1_X = 50
pt1_Y = 0
pt2_X = 0
pt2_Y = -50
dy = pt2_y - pt1_y
dx = pt2_x - pt1_x
MsgBox "X:" & dx & " Y:" & dy
Degree = (Atn(dy,dx)) * 180/PI
MsgBox Degree
-
It looks like Math.atan2 is not supported in VB6 :(
So that will not work! Maybe some one else has a better way to do it.
-
Hi Swetha
I hope these links help.
http://msdn.microsoft.com/en-us/library/thc0a116(VS.80).aspx
http://msdn.microsoft.com/en-us/library/kx6we9k6(VS.85).aspx
http://www.vb-helper.com/howto_atan2.html
Cheers
John Mac
-
Hey is what you need, this is from the "Conversational Wizard" I put up but the code in it will work for you, just modify it for your situation:
Sub Main()
'G68 angle calc
SetUserLed(1039,1)
x1=GetUserDRO(1081)
y1=GetUserDRO(1082)
x2=GetUserDRO(1095)
y2=GetUserDRO(1096)
D=1
pi = 4 * Atn(1)
If x2-x1=0 Then
Message("X2 cannot = X1!!")
Exit Sub
End If
If y2-y1=0 Then
Message("y2 cannot = y1!!")
Exit Sub
End If
If y2=0 Then
Message("y2 cannot = 0!!")
Exit Sub
End If
If x2=0 Then
Message("X2 cannot = 0!!")
Exit Sub
End If
If y2>y1 And x2>x1 Then
D=D*1
End If
If y2>y1 And x2<x1 Then
D=D*-1
End If
If y2<y1 And x2<x1 Then
D=D*1
End If
If y2<y1 And x2>x1 Then
D=D*-1
End If
a=y2-y1
b=x2-x1
ang=(180/pi) * Atn(a/b)
If D>0Then
SetUserDRO(1094,ang)
End If
If D<0Then
SetUserDRO(1094,ang)
End If
End Sub
Main
'scott
-
that's really nice and that's all i want ...thanks and thanks again.
swetha