Android Question need help to conert angle

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?
 
Upvote 0

Brian Dean

Active Member
Licensed User
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.
 
Upvote 0
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:
    Activity.LoadLayout("main")
    js1.ButtonDrawable = "button"
    js1.PadBackground = "pad"
    
    js2.ButtonColor = Colors.Yellow
    js2.PadColor = Colors.Blue
    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
 
Upvote 0

Johan Schoeman

Expert
Licensed User
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:
    Activity.LoadLayout("main")
    js1.ButtonDrawable = "button"
    js1.PadBackground = "pad"
  
    js2.ButtonColor = Colors.Yellow
    js2.PadColor = Colors.Blue
    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:
Upvote 0
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
 
Upvote 0
Top