# Android Questionneed help to conert angle

##### Member
hi i need convert angle to y and x from lib joystick v1.0
i need work in just this lib

#### agraham

##### Expert
Longtime User
Simple trigonometry. The value will probably be very noisy and might need smoothing.
B4X:
``````'remembering that Tan(a) = opposite/adjacent
a = ATan(x/y) * 180/ cPi ' convert to angle from radians (I think I got it right!)``````

Last edited:
• Star-Dust

##### Member
Simple trigonometry. The value will probaby be very noisy and might need sm0othing.
B4X:
``````'remembering that Tan(a) = opposite/adjacent
a = ATan(x/y) * 180/ cPi ' convert to angle from radians (I think I got i right!))``````
Give a clearer example? How do I convert angle to x and y?

#### Brian Dean

##### Active Member
Longtime User
I think it is your question that needs to be clearer - that is why nobody is answering. An angle, on its own, cannot be converted to coordinates. If you have a reference point and a distance as well as an angle then that does make sense. An angle on its own does not.

#### tigrot

##### Well-Known Member
Longtime User
An angle is defined by at least two different couples of coordinates on a cartesian plane. Generally first Point lays on 0,0. But you can start everywhere. It's a simple translation proble..

##### Member
I think it is your question that needs to be clearer - that is why nobody is answering. An angle, on its own, cannot be converted to coordinates. If you have a reference point and a distance as well as an angle then that does make sense. An angle on its own does not.
my code i need send joystick y and x position to my win app c# for remote mouse:
``````Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Type PointType2(x2 As Int,y2 As Int)
Private js1 As JoyStick
Private js2 As JoyStick
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
js1.ButtonDrawable = "button"

js2.ButtonColor = Colors.Yellow
If FirstTime Then
UDPSocket1.Initialize("UDP", 0, 7777)
End If

End Sub
Sub UDP_PacketArrived (Packet As UDPPacket)
Dim msg As String
msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")

End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub js1_value_changed(angle As Double, angleDegrees As Double, powr As Double)

Dim y As Int
Dim x As Int
x =  Cos(angle)
y =  Sin(angle)

x = Cos(angle)
y = Sin(angle)

Log("x " & x)
Log("y " &  y)

Dim s As String =     "{"&""""&"json"&""""&":"&""""&"yes"&""""&","&""""&"y"&""""&":"&""""&y&""""&","&""&""""&"x"&""""&":"&""""&x&""""&"}" 'send joy position to win app
Dim Packet As UDPPacket
Dim data() As Byte
data = s.GetBytes("UTF8")
Packet.Initialize(data, "192.168.1.105", 7777)
UDPSocket1.Send(Packet)

End Sub``````

#### Johan Schoeman

##### Expert
Longtime User
my code i need send joystick y and x position to my win app c# for remote mouse:
``````Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Type PointType2(x2 As Int,y2 As Int)
Private js1 As JoyStick
Private js2 As JoyStick
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
js1.ButtonDrawable = "button"

js2.ButtonColor = Colors.Yellow
If FirstTime Then
UDPSocket1.Initialize("UDP", 0, 7777)
End If

End Sub
Sub UDP_PacketArrived (Packet As UDPPacket)
Dim msg As String
msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")

End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub js1_value_changed(angle As Double, angleDegrees As Double, powr As Double)

Dim y As Int
Dim x As Int
x =  Cos(angle)
y =  Sin(angle)

x = Cos(angle)
y = Sin(angle)

Log("x " & x)
Log("y " &  y)

Dim s As String =     "{"&""""&"json"&""""&":"&""""&"yes"&""""&","&""""&"y"&""""&":"&""""&y&""""&","&""&""""&"x"&""""&":"&""""&x&""""&"}" 'send joy position to win app
Dim Packet As UDPPacket
Dim data() As Byte
data = s.GetBytes("UTF8")
Packet.Initialize(data, "192.168.1.105", 7777)
UDPSocket1.Send(Packet)

End Sub``````
The minimum of Power is probably zero when the joystick is in the centre position. Power should have a max value when the joystick is moved to its max position away from the centre. So, use Power and Angle to get
X= powr * cos(AngleDegrees)
Y= powr * sin(AngleDegrees)

Power will represent the radius of a circle - the joystick moves is a circle of minimum radius (zero) to maximum radius. Maximum radius is when the joystick is max away from the centre position. Power represents the radius I.e how far the joystick is away from the center position.

Last edited:

##### Member
The minimum of Power is probably zero when the joystick is in the centre position. Power should have a max value when the joystick is moved to its max position away from the centre. So, use Power and Angle to get
X= powr * cos(AngleDegrees)
Y= powr * sin(AngleDegrees)
i used and no this working good