Answered by:
Can't figure the trig formula in this sample
Question

Got a couple of questions on this one.
#1. Is there a way to get the shapes for the crosshair images to load into one label called "cross"?
#2. Trying to get a shape I call the gun, rotate to look at the crosshair drawn at the mouse location. I subtract the target y from the gun y to get the opposite side, do the same for x to get the adjacent side, then figuring its a tangent but I realize I should have paid more attention in school. Can someone help me out with this formula?
Thanks for your advice in advance.
'Krueg Trigonometry Lesson
GraphicsWindow.Width = 800
GraphicsWindow.Height = 600
GraphicsWindow.Top = 5
GraphicsWindow.Left = 5
GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.PenColor = "White"
cross = Shapes.AddEllipse(26,26) '+Shapes.AddLine(0,12,25,12)+Shapes.AddLine(12,0,12,25)
cross1 = Shapes.AddLine(10,13,16,13)
cross2 = Shapes.AddLine(13,10,13,16) '#1. How do I add all the shapes to one label????????
gun = Shapes.AddRectangle(3,35)
gx = 400 'Gun Xposition
gy = 510 'Gun YpositionMouse.HideCursor()
GraphicsWindow.MouseMove = targetSub target
tx = GraphicsWindow.MouseX 'Target Xposition
ty = GraphicsWindow.MouseY 'Target Yposition
Shapes.Move(cross ,tx13,ty13)
Shapes.Move(cross1,tx13,ty13)
Shapes.Move(cross2,tx13,ty13)
ga = Math.Tan((gyty)/(gxtx)) '#2. Can't figure out this formula????????????
Shapes.Rotate(gun,ga)
Shapes.Move(gun,gx,gy)
EndSub Edited by JKrueg Saturday, April 21, 2012 2:41 AM Had the sides backwards
Saturday, April 21, 2012 1:44 AM
Answers

try this.
ga = math.GetDegrees(Math.arcTan((gyty)/(txgx)))
Shapes.Rotate(gun,90ga) Marked as answer by JKrueg Saturday, April 21, 2012 3:26 AM
Saturday, April 21, 2012 3:11 AMAnswerer 
Hi JKrueg!
Question #1: The only way to get the shapes to one label in standard smallbasic is to create a jpeg or bmp of the crosshairs and load the image using Shapes.AddImage().
Question #2: You want to use the ArcTan method instead.
Hope that helps!
 Marked as answer by JKrueg Saturday, April 21, 2012 3:26 AM
Saturday, April 21, 2012 3:15 AM 
I just figured it out as well!
ga = Math.GetDegrees(Math.ArcTan((gxtx)/(gyty)))
Shapes.Rotate(gun,ga)
Shapes.Move(gun,gx,gy)Thanks for the quick replies.
Here's the working code GQJ530
http://smallbasic.com/program/?GQJ530
I'll bet you can see where this is going.
 Marked as answer by JKrueg Saturday, April 21, 2012 3:26 AM
Saturday, April 21, 2012 3:26 AM
All replies

try this.
ga = math.GetDegrees(Math.arcTan((gyty)/(txgx)))
Shapes.Rotate(gun,90ga) Marked as answer by JKrueg Saturday, April 21, 2012 3:26 AM
Saturday, April 21, 2012 3:11 AMAnswerer 
Hi JKrueg!
Question #1: The only way to get the shapes to one label in standard smallbasic is to create a jpeg or bmp of the crosshairs and load the image using Shapes.AddImage().
Question #2: You want to use the ArcTan method instead.
Hope that helps!
 Marked as answer by JKrueg Saturday, April 21, 2012 3:26 AM
Saturday, April 21, 2012 3:15 AM 
I just figured it out as well!
ga = Math.GetDegrees(Math.ArcTan((gxtx)/(gyty)))
Shapes.Rotate(gun,ga)
Shapes.Move(gun,gx,gy)Thanks for the quick replies.
Here's the working code GQJ530
http://smallbasic.com/program/?GQJ530
I'll bet you can see where this is going.
 Marked as answer by JKrueg Saturday, April 21, 2012 3:26 AM
Saturday, April 21, 2012 3:26 AM