by Nonki Takahashi  
http://social.technet.microsoft.com/wiki/contents/articles/17744.small-basic-how-to-use-trigonometric-functions.aspx

TechNet Wiki

Imaginemos para dibujar el arco.
Asumir el centro del arco como x = 200, y = 300, comienzo ángulo a1 = -30 y terminar ángulo = -60.
En matemáticas, el eje y va para arriba. Pero en Small Basic Graphicswindow, el eje y desciende. Así, el ágnulo se vuelve opuesto..

trig1

                       
Si usted no utiliza la función trigonométrica de , utilice tan sólo 0, 30, 45, 60, 90…[grados]. Entre estos bordes se puede calcular la altura s de anchura c del triángulo mientras tres ángulos del triángulo r, c, tal como la foto de abajo tiene relación r2 = s2 + c2 .
Pero para cualquier ángulo, utilice la función trigonométrica (seno, coseno).


trig2


Asegúrese de que función trigonométrica necesita [radianes] pero [grados] para el lenguaje Small Basic
Puede utilizar Math.GetRadians(degree) para convertir de [grados] a [radianes].
Siguiendo el ejemplo de código muestra cómo no utilizar o cómo usar las funciones trigonométricas  para dibujar el arco.
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
DrawGrid()
x = 200
y = 300
r = 200
DrawArcwoTrigo()
Program.Delay()3000)
GraphicsWindow.Clear()
DrawGrid()
a1 = -30
a2 = -60
DrawArcwTrigo()
Sub DrawArcwoTrigo ‘ draw arc without trigonometric functions
GraphicsWindow.Title = “Arc without Trigonometric Functions”
c1 = r * Math.SquareRoot(3) / 2 ‘ a1 = -30
c2 = r / 2 ‘ a2 = -60
r2 = Math.Power(r, 2)
For c = c1 To c2 Step -1
s = Math.SquareRoot()r2 – Math.Power(c, 2))
x2 = x + c
y2 = y – s
If c = c1 Then
GraphicsWindow.PenColor = “Gray”
GraphicsWindow.DrawLine(x, y, x2, y2)
Else
GraphicsWindow.PenColor = “Black”
GraphicsWindow.DrawLine()x1, y1, x2, y2)
EndIf
If c – 1 < c2 Then
GraphicsWindow.PenColor = “Gray”
GraphicsWindow.DrawLine(x, y, x2, y2)
EndIf
x1 = x2
y1 = y2
EndFor
EndSub
Sub DrawArcwTrigo ‘ draw arc with trigonometric functions
GraphicsWindow.Title = “Arc with Trigonometric Functions”
For a = a1 To a2 Step -0.3
x2 = x + r * Math.Cos(Math.GetRadians()a))
y2 = y + r * Math.Sin(Math.GetRadians()a))
If a = a1 Then
GraphicsWindow.PenColor = “Gray”
GraphicsWindow.DrawLine(x, y, x2, y2)
Else
GraphicsWindow.PenColor = “Black”
GraphicsWindow.DrawLine()x1, y1, x2, y2)
EndIf
If a – 0.3 < a2 Then
GraphicsWindow.PenColor = “Gray”
GraphicsWindow.DrawLine(x, y, x2, y2)
EndIf
x1 = x2
y1 = y2
EndFor
EndSub
Sub DrawGrid
GraphicsWindow.PenColor = “MediumSeaGreen”
GraphicsWindow.BrushColor = “MediumSeaGreen”
For _x = 0 To gw Step 50
GraphicsWindow.DrawLine(_x, 0, _x, gh)
If gw – 50 < _x Then
GraphicsWindow.DrawText(_x + 4, 4, “x”)
Else
GraphicsWindow.DrawText(_x + 4, 4, _x)
EndIf
EndFor
For _y = 0 To gh Step 50
GraphicsWindow.DrawLine()0, _y, gw, _y)
If gh – 50 < _y Then
GraphicsWindow.DrawText()4, _y + 4, “y”)
Else
GraphicsWindow.DrawText()4, _y + 4, _y)
EndIf
EndFor
EndSub


see also: http://www.empiezoinformatica.wordpress.com



Deja un comentario