A Vector operations calculator.
It is not necessary that they look or act the same. Engineer's Sandbox was very limited in features.
from utilities.Raylock import *
from math import cos, sin, pi
class App:
def __init__(self):
StartAppUtility(self)
AddToggleSet(self,
"Operation",
[0, "Normalize"],[1, "Decomposition"],[2, "Dot Product"],[3,"Cross Product"],
location="East", outline=False)
AddInput(self, "An", default="1,2,3", label="A", id=0, numbers=False)
AddInput(self, "Ad", default="1,2,3", label="A", id=2, numbers=False)
AddInput(self, "Ac", default="1,2,3", label="A", id=3, numbers=False)
AddInput(self, "Bd", default="1,2,3", label="B", id=2, numbers=False)
AddInput(self, "Bc", default="1,2,3", label="B", id=3, numbers=False)
AddInput(self, "R", id=1, tip="Vector Magnitude")
AddInput(self, "A", label="\u0398", id=1, tip="Vector Angle")
AddOutput(self, "normal", label=" |A|", id=0)
AddOutput(self, "dot", label=" A \u2022 B", id=2)
AddOutput(self, "cross", label=" A x B", id=3)
AddOutput(self, "X Component", id=1, format="%.6f")
AddOutput(self, "Y Component", id=1, format="%.6f")
AddDrawing(self, "drawing1", method="GetDrawing")
self.GetDrawing()
def GetDrawing(self):
ClearDrawing(self, "drawing1")
checked = GetInput(self, "Operation")
if checked == 3:
DrawArrow(self, "drawing1", -60,70,-60,-40,8, pen="AreaOutline1", brush="AreaOutline1", textcolor="AreaOutline1")
DrawText(self, "drawing1", "A x B",-75,25)
DrawText(self, "drawing1", "|A x B|",10,-30)
DrawArrow(self, "drawing1", 0,-70,-60,-40,8, pen="AreaOutline2", brush="AreaOutline2", textcolor="AreaOutline2")
DrawArrow(self, "drawing1", 20,10,-60,-40,8)
DrawText(self, "drawing1", "A",-35,-55)
DrawText(self, "drawing1", "B",-28,-15)
DrawLine(self, "drawing1", (20),(10),(80),(-20), pen="Dimensions", brush="Dimensions", textcolor="Dimensions", penstyle="wxPENSTYLE_LONG_DASH")
DrawLine(self, "drawing1", (0),(-70),(80),(-20))
DrawLine(self, "drawing1", (-60),(-30),(-50),(-30))
DrawLine(self, "drawing1", (-50),(-30),(-50),(-40))
elif checked == 2:
DrawArrow(self, "drawing1", 20,70,-40,-40,8, pen="AreaOutline1", brush="AreaOutline1", textcolor="AreaOutline1")
DrawText(self, "drawing1", "A",-15,20)
DrawArrow(self, "drawing1", 40,-40,-40,-40,8, pen="AreaOutline2", brush="AreaOutline2", textcolor="AreaOutline2")
DrawText(self, "drawing1", "B",5,-33)
DrawHBDimension(self, "drawing1", "a \u2022 b/|b|",-40,-40,20,-40, pen="Dimensions", brush="Dimensions", textcolor="Dimensions")
DrawText(self, "drawing1", "\u0398",-16,-21)
DrawArrow(self, "drawing1", -28,-23,-24,-27,8)
DrawArc(self, "drawing1", -25,-40,-26,-20,-27,-33, brush="transparent")
DrawLine(self, "drawing1", 20,70,20,-40, penstyle="wxPENSTYLE_LONG_DASH")
elif checked == 1:
DrawArrow(self, "drawing1", 40, 70, -40, -40, 8, pen="Dimensions", brush="Dimensions", textcolor="Dimensions")
DrawArrow(self, "drawing1", -28, -23, -24, -27, 8)
DrawText(self, "drawing1", "R", -5, 20)
DrawText(self, "drawing1", "\u0398", -16, -21)
DrawArrow(self, "drawing1", 40, -40, -40, -40, 8, pen="AreaOutline2", brush="AreaOutline2", textcolor="AreaOutline2")
DrawText(self, "drawing1", "X", 5, -33)
DrawArrow(self, "drawing1", 40, 70, 40, -40, 8, pen="AreaOutline1", brush="AreaOutline1", textcolor="AreaOutline1")
DrawText(self, "drawing1", "Y", 35, 10)
DrawArc(self, "drawing1", -25, -40, -26, -20, -27, -33, pen="Dimensions", brush="transparent")
elif checked == 0:
DrawArrow(self, "drawing1", -50,50,-50,-50,3, pen="Dimensions", brush="Dimensions", textcolor="Dimensions")
DrawArrow(self, "drawing1", 50,-50,-50,-50,3)
DrawArrow(self, "drawing1", 16.6,0,-50,-50,8, pen="AreaOutline2", brush="AreaOutline2", textcolor="AreaOutline2")
DrawText(self, "drawing1", "A",-13,-15)
DrawArrow(self, "drawing1", -28.349,-33,-50,-50,8, pen="AreaOutline1", brush="AreaOutline1", textcolor="AreaOutline1")
DrawText(self, "drawing1", "A (unit vector)",-5,-40)
return ReturnDrawing(self, "drawing1")
def solve(self):
check = GetInput(self, "Operation")
if check == 0:
A = Vector(GetInput(self, 'An'))
An = A.Normalize()
SetOutput(self, 'normal',An.GetString())
elif check== 1:
magnitude = GetInput(self, "R")
angle = GetInput(self, 'A')
SetOutput(self, 'X Component', magnitude * cos(angle * pi / 180))
SetOutput(self, 'Y Component', magnitude * sin(angle * pi / 180))
elif check == 2:
A = Vector(GetInput(self, "Ad"))
B = Vector(GetInput(self, 'Bd'))
Ad = A.DotProduct(B)
SetOutput(self, 'dot',Ad)
elif check == 3:
A = Vector(GetInput(self, "Ac"))
B = Vector(GetInput(self, 'Bc'))
SetOutput(self, 'cross',A.CrossProduct(B).GetString())