# 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?

'Krueg Trigonometry Lesson
GraphicsWindow.Width = 800
GraphicsWindow.Height = 600
GraphicsWindow.Top = 5
GraphicsWindow.Left = 5
GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.PenColor = "White"
cross2 = Shapes.AddLine(13,10,13,16)      '#1.   How do I add all the shapes to one label????????
gx = 400                            'Gun X-position
gy = 510                            'Gun Y-position

Mouse.HideCursor()
GraphicsWindow.MouseMove = target

Sub target
tx = GraphicsWindow.MouseX        'Target X-position
ty = GraphicsWindow.MouseY        'Target Y-position
Shapes.Move(cross ,tx-13,ty-13)
Shapes.Move(cross1,tx-13,ty-13)
Shapes.Move(cross2,tx-13,ty-13)
ga = Math.Tan((gy-ty)/(gx-tx))                   '#2. Can't figure out this formula????????????
Shapes.Rotate(gun,ga)
Shapes.Move(gun,gx,gy)
EndSub

• Edited by Saturday, April 21, 2012 2:41 AM Had the sides backwards
Saturday, April 21, 2012 1:44 AM

•

try this.

ga = math.GetDegrees(Math.arcTan((gy-ty)/(tx-gx)))
Shapes.Rotate(gun,90-ga)

• Marked as answer by Saturday, April 21, 2012 3:26 AM
Saturday, April 21, 2012 3:11 AM
• 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 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((gx-tx)/(gy-ty)))
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 Saturday, April 21, 2012 3:26 AM
Saturday, April 21, 2012 3:26 AM

### All replies

•

try this.

ga = math.GetDegrees(Math.arcTan((gy-ty)/(tx-gx)))
Shapes.Rotate(gun,90-ga)

• Marked as answer by Saturday, April 21, 2012 3:26 AM
Saturday, April 21, 2012 3:11 AM
• 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 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((gx-tx)/(gy-ty)))
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 Saturday, April 21, 2012 3:26 AM
Saturday, April 21, 2012 3:26 AM