Hello Guest it is March 28, 2024, 09:03:22 AM

Author Topic: can any one chech this code  (Read 4879 times)

0 Members and 1 Guest are viewing this topic.

can any one chech this code
« 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

Offline zealous

*
  •  489 489
  • HI!
    • View Profile
    • Artsoft Solutions
Re: can any one chech this code
« Reply #1 on: January 02, 2009, 02:28:13 PM »
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:

Code: [Select]
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
« Last Edit: January 02, 2009, 02:35:58 PM by zealous »

Offline zealous

*
  •  489 489
  • HI!
    • View Profile
    • Artsoft Solutions
Re: can any one chech this code
« Reply #2 on: January 02, 2009, 03:19:55 PM »
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.

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: can any one chech this code
« Reply #4 on: January 03, 2009, 10:18:49 AM »
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
fun times
Re: can any one chech this code
« Reply #5 on: January 03, 2009, 11:57:17 AM »
that's really nice and that's all i want ...thanks and thanks again.
swetha