Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • FrameIT/frameworld
1 result
Show changes
Commits on Source (86)
Showing
with 653 additions and 0 deletions
bin
content
errors
narration
relational
---------------------------
|Add Scroll to Unity Guide|
---------------------------
In archives:
1. Create and build Scroll in "archives\MathHub\FrameIT\frameworld\source\Scrolls" folder.
2. In "archives\MathHub\FrameIT\frameworld\source\DefaultSituationSpace.mmt" include your scroll
3. Build "DefaultSituationSpace.mmt"
In uframeit
1. add your scroll to "UFrameIT\Assets\Scripts\MMTServer\CommunicationProtocoll\MMTConstants.cs"\
2. Add the MMT-constructor you Implemented into Assets\Scripts\MMTServer\CommunicationProtocol\MMTConstants.cs
in Class "GlobalBehaviour" ("UFrameIT\Assets\Scripts\GlobalBehaviour.cs") Method "GetScrollsfromServer()" loads scrolls from "UFrameIT\Assets\StreamingAssets\scrolls.json":
3. Open: "http://localhost:8085/scroll/list" and copy all the text.
4. Now paste this into: "UFrameIT\Assets\StreamingAssets\scrolls.json" and start the game.
if Class "GlobalBehaviour" ("UFrameIT\Assets\Scripts\GlobalBehaviour.cs") Method "GetScrollsfromServer()" loads scrolls from "UFrameIT\Assets\StreamingAssets\scrolls.json":
2. Open: "http://localhost:8085/scroll/list" and copy all the text.
3. Now paste this into: "UFrameIT\Assets\StreamingAssets\scrolls.json" and start the game.
Additional:
If you want to create a new theory you have to include it in the "theory FrameWorldMeta" in: \archives\MathHub\FrameIT\frameworld\source\MetaTheories.mmt,
which is at the bottom of the file.
This ensures your theory is is in the global namespace.
Then if you want to create a theory with a specific type:
you have to specify this at the top:
namespace http://mathhub.info/FrameIT/frameworld ❚
fixmeta ur:?LF ❚
and in you theory do:
include ?FrameITBasics ❙
at the start
## If something fails, restart vscode and try building again. This fixes a lot of errors
# <u><b>Create Fact</b></u>
### <u>Dependency: MMT-Fact already implemented</u>
In all Array-like structures, always add your facts at the bottom.
1. In Assets\InteractionEngine\FactHandling\Facts create your own fact
<u>Your fact should include</u>:
(<i>use the already existing Facts as examples</i>)
<br>
1. A constructor that calls base(). Constructor can have SomDoc, which is the MMT URI as OMS.
Only set the ServerDefinition inside the constructor if you have a good reason to.
2. define: A method parseFact(List<Fact> ret, MMTFact fact).
convert MMTFact fact to Unity Fact and add it to the List<Fact> ret
hint: use FactRecorder.AllFacts[<uri>] to get the Unity Fact belonging to the <uri>
3. define: public override bool HasDependentFact => [true/false]
4. define: GetDeendentFactIds(), which gives back a string array of the dependent URIs of your facts.
5. define: GetHashCode()
6. define: EquivalentWrapped(YOUR_FACTCLASS, YOUR_FACTCLASS), which is a Method that
returns true if the two facts are (approximately) equal
7. define: _ReInitializeMe(Dictionary<string, string> old_to_new), that gets called when the Fact
gets reinstantiated
8. define: MakeMMTDecalaration(), which gives back a new MMTFact.
9. define: Defines(), which gives back a SOMDoc(MMTObject) of your class
2. Add the MMT-fact you Implemented into Assets\Scripts\MMTServer\CommunicationProtocol\MMTConstants.cs
in OMS_TO_TYPE add a line like:
{
ObjectType,
typeof(ObjectFact)
},
3. Then, in Assets\Scripts\InteractionEngine\FactHandling\Facts\Fact.cs
1. add an entry into ParsingDictionary.parseFactDictionary with your MMTConstant as key and the parseFact Method of the Fact class you implemented.
2. Then add a line to the lines that look like
[JsonSubtypes,.KnownSubType(typeof(YOUR_FACTCLASS), nameof(YOUR_FACTCLASS))]
4. In Assets\Scripts\InteractionEngine\FactHandling\FactSpawner.cs
1. Add a variable of type GameObject for your fact.
2. Create a spawn method for your fact.
3. In SpawnFactRepresentation add your Fact to the switch-case statement
5. In the Unity Editor in Assets\Ressources\Prefabs\Facts create the prefab for your Fact.
6. Connect your Prefab to the FactSpawner class
1. Open Assets\Scenes\Worlds\RiverWorld.
2. In the Unity Project Tab goto folder Assets\Scripts\InteractionEngine\FactHandling
3. Rightclick FactSpawner.cs and select "Find References In Scene".
4. In Hirarchy select WorldCursor and add your Fact Prefab into the Inspector.
5. Alternative to 6.2 & 6.3: in hirarchy search: "ref:Assets/Scripts/InteractionEngine/FactHandling/FactSpawner.cs"
7. Add the Layer of your fact to the LayerMask in WorldFactInteraction
1. Open Assets\Scenes\Worlds\RiverWorld.
2. In the Unity Project Tab goto folder Assets\Scripts\InteractionEngine\
3. Rightclick WorldFactInteraction.cs and select "Find References In Scene"
4. In Hirarchy select MathMenue1_Canvas_0 and add your Fact Layer into the Fact Layer Maks of World Fact Interaction
4. In Hirarchy select HidingCanvas and add your Fact Layer into the Fact Layer Maks of World Fact Interaction
5. Alternative to 6.2 & 6.3: in hirarchy search: "ref:Assets/Scripts/InteractionEngine/WorldFactInteraction.cs"
7. Create an Icon for your Fact
1. Create an Icon-image
1.1 Create an icon-image with dimensions: 200x200 and save it into: "Assets\Scripts\InventoryStuff\Items\images"
1.2 Change the "Texture Type" to: "Sprite (2D and UI)", the "Sprite Mode" to "single" and finally the "Pixel per unit" to "256".
2. Create the prefab for you facticon in: "Assets\Resources\Prefabs\UI\Icons\FactIcons" by copying an existing prefab.
2.1 Drag your created sprite into "Source Image"
2.2 Add or remove additional points associated with your prefab, then edit the variable: "Fact Text" in the script "Fact Object UI".
4. Open: "Assets\Scenes\Worlds\River World"
5. Then search for "DisplayFacts" and open "Factscreen".
6. In both factscreens search for the rownumber of your factclass in "Prefabt Type Readonly" (yes, this is the real name not a typo),
then drag your created prefab into "Prefab Data Config" into the row with the same rownumber.
\ No newline at end of file
1.) create gadget class derived from Gadget in Assets\Scripts\InteractionEngine\Gadgets
2.) add into enum in Gadget class in Assets\Scripts\InteractionEngine\Gadgets\Gadget.cs
3.) add into dictionary in Gadget class in Assets\Scripts\InteractionEngine\Gadgets\Gadget.cs
4.) add a line into the json-definitions at the start of: Assets\Scripts\InteractionEngine\Gadgets\Gadget.cs
-> follow examples, recommendation: always use the class name
5.) go into: Assets\ScriptableObjects\Gadgets
6.) create Scriptable Object in Assets\ScriptableObjects\gadgets
7.) add into Assets\ScriptableObjects\Gadgets\GadgetDataContainerGadgetCollection
8.) in Assets\ScriptableObjects\Gadgets\GadgetDataContainerGadgetCollection add new Element into "Gadget Data" and
"Gadget Type" [same element index]
9.) In "Gadget Data" insert the ScriptableObject you created
10.) in "Gadget Type" insert the enum of the gadget you created
-> in the ScriptableObject you created you can customize your gadget
- Rank: Position in toolbar
- UI Name: name of your gadget
- Button Indx: sets the index of the sprite that is used as the icon in the toolbar,
you can find the indices in Assets\ScriptableObjects\Gadgets\GadgetDataContainerGadgetCollection,
as "Button Sprites", all possible sprites are in Assets\Scripts\InventoryStuff\Items\images
\ No newline at end of file
goto: UFrameIT/Doxygen/output/html/index.html
\ No newline at end of file
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
build FrameIT/frameworld mmt-omdoc MetaTheories.mmt
build FrameIT/frameworld scala-bin
build FrameIT/frameworld mmt-omdoc dynamics.mmt
build FrameIT/frameworld mmt-omdoc Scrolls/
build FrameIT/frameworld mmt-omdoc DefaultSituationSpace.mmt
import http.client
import json
import time
HOST = 'localhost' #'127.0.0.1'
PORT = 8085
headers = {'Content-type': 'application/json'}
bouncing_scroll = 'http://mathhub.info/FrameIT/frameworld?W3DBouncingScroll'
pos_ref = {'uri': 'http://mathhub.info/FrameIT/frameworld?W3DBouncingScroll/Problem?position'}
vel_ref = {'uri': 'http://mathhub.info/FrameIT/frameworld?W3DBouncingScroll/Problem?velocity'}
G_ref = {'uri': 'http://mathhub.info/FrameIT/frameworld?W3DBouncingScroll/Problem?g_base'}
B_ref = {'uri': 'http://mathhub.info/FrameIT/frameworld?W3DBouncingScroll/Problem?bounce'}
W_ref = {'uri': 'http://mathhub.info/FrameIT/frameworld?W3DBouncingScroll/Problem?wallsr'}
real_list = 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory2?real_list'
list_type = 'http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?ListType'
product = 'http://gl.mathhub.info/MMT/LFX/Sigma?Symbols?Product'
real_lit = 'http://mathhub.info/MitM/Foundation?RealLiterals?real_lit'
cons = 'http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?cons'
cons_nil = 'http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?nil_constant'
tuple_mmt = 'http://gl.mathhub.info/MMT/LFX/Sigma?Symbols?Tuple'
point_mmt = 'http://mathhub.info/MitM/core/geometry?3DGeometry?point'
def list_element_4point(p1, p2, p3, p4):
return {'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': p1[0], 'kind': 'OMF'},
{'float': p1[1], 'kind': 'OMF'},
{'float': p1[2], 'kind': 'OMF'}],
'kind': 'OMA'},
{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': p2[0], 'kind': 'OMF'},
{'float': p2[1], 'kind': 'OMF'},
{'float': p2[2], 'kind': 'OMF'}],
'kind': 'OMA'},
{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': p3[0], 'kind': 'OMF'},
{'float': p3[1], 'kind': 'OMF'},
{'float': p3[2], 'kind': 'OMF'}],
'kind': 'OMA'},
{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': p4[0], 'kind': 'OMF'},
{'float': p4[1], 'kind': 'OMF'},
{'float': p4[2], 'kind': 'OMF'}],
'kind': 'OMA'}],
'kind': 'OMA'}
def list_element_4point_plus_nil(p1, p2, p3, p4):
return {'applicant': {'uri': cons, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': cons_nil, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'}],
'kind': 'OMA'},
{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'}],
'kind': 'OMA'},
{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'}],
'kind': 'OMA'},
{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'}],
'kind': 'OMA'}],
'kind': 'OMA'}],
'kind': 'OMA'},
{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': p1[0], 'kind': 'OMF'},
{'float': p1[1], 'kind': 'OMF'},
{'float': p1[2], 'kind': 'OMF'}],
'kind': 'OMA'},
{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': p2[0], 'kind': 'OMF'},
{'float': p2[1], 'kind': 'OMF'},
{'float': p2[2], 'kind': 'OMF'}],
'kind': 'OMA'},
{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': p3[0], 'kind': 'OMF'},
{'float': p3[1], 'kind': 'OMF'},
{'float': p3[2], 'kind': 'OMF'}],
'kind': 'OMA'},
{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': p4[0], 'kind': 'OMF'},
{'float': p4[1], 'kind': 'OMF'},
{'float': p4[2], 'kind': 'OMF'}],
'kind': 'OMA'}],
'kind': 'OMA'}],
'kind': 'OMA'}
def cons_2elements(e1, e2):
return {'applicant': {'uri': cons, 'kind': 'OMS'},
'arguments': [e1, e2],
'kind': 'OMA'}
def construct_list_4point_df(values):
# Values needs to be of the form [[[x1, y1, z1], [x2, y2, z2], [x3, y3, z3], [x4, y4, z4]], ...]
prev_ele = {}
for ci, cv in enumerate(values[::-1]):
if ci == 0:
prev_ele = list_element_4point_plus_nil(cv[0], cv[1], cv[2], cv[3])
else:
cur_ele = list_element_4point(cv[0], cv[1], cv[2], cv[3])
prev_ele = cons_2elements(prev_ele, cur_ele)
return prev_ele
def create_walls_fact(values):
# Values needs to be of the form [[x1, y1, x2, y2], [x1, y1, x2, y2], ...]
return {'ref': W_ref,
'label': 'Wallsr',
'tp': {'applicant': {'uri': list_type, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'uri': point_mmt, 'kind': 'OMS'},
{'uri': point_mmt, 'kind': 'OMS'},
{'uri': point_mmt, 'kind': 'OMS'},
{'uri': point_mmt, 'kind': 'OMS'}],
'kind': 'OMA'}],
'kind': 'OMA'},
'kind': 'general',
'df': construct_list_4point_df(values)
}
def create_R_fact(val, ref):
return {"ref": ref,
"label": "X",
"kind": "general",
"tp": {'uri': real_lit,
'kind': 'OMS'},
"df": {"kind": "OMF", "float": val}
}
def create_point_fact(val, ref):
return {"ref": ref,
"label": "P",
"kind": "general",
"tp": {"kind": "OMS", "uri": point_mmt},
"df": {"kind": "OMA", "applicant": {"kind": "OMS", "uri": tuple_mmt},
"arguments": [{"kind": "OMF", "float": val[0]},
{"kind": "OMF", "float": val[1]},
{"kind": "OMF", "float": val[2]}]}}
g = [0.0, 0.0, -200.0]
pos_fact = create_point_fact([380.0, 0.0, 300.0], pos_ref)
vel_fact = create_point_fact([-490.0, 100.0, 150.0], vel_ref)
G_fact = create_point_fact(g, G_ref)
B_fact = create_R_fact(0.8, B_ref)
#wallsr_list = [[[-400.0, -400.0, 0.0], [400.0, -400.0, 0.0], [400.0, 400.0, 0.0], [-400.0, 400.0, 0.0]]]
wallsr_list = [[[0.0, 0.0, 0.0], [400.0, 0.0, 0.0], [400.0, 0.0, 400.0], [0.0, 0.0, 400.0]],
[[0.0, 400.0, 0.0], [400.0, 400.0, 0.0], [400.0, 400.0, 400.0], [0.0, 400.0, 400.0]],
[[0.0, 0.0, 0.0], [0.0, 0.0, 400.0], [0.0, 400.0, 400.0], [0.0, 400.0, 0.0]],
[[400.0, 0.0, 0.0], [400.0, 0.0, 400.0], [400.0, 400.0, 400.0], [400.0, 400.0, 0.0]],
[[0.0, 0.0, 400.0], [400.0, 0.0, 400.0], [400.0, 400.0, 400.0], [0.0, 400.0, 400.0]],
[[0.0, 0.0, 0.0], [400.0, 0.0, 0.0], [400.0, 400.0, 0.0], [0.0, 400.0, 0.0]],
[[50.0, 0.0, 200.0], [120.7, 0.0, 270.7], [120.7, 200.0, 270.7], [50.0, 200.0, 200.0]],
[[150.0, 0.0, 100.0], [200.0, 0.0, 100.0], [200.0, 200.0, 100.0], [150.0, 200.0, 100.0]],
[[150.0, 0.0, 286.6], [200.0, 0.0, 200.0], [200.0, 200.0, 200.0], [150.0, 200.0, 286.6]],
[[230.7, 0.0, 340.0], [300.0, 0.0, 300.0], [300.0, 200.0, 300.0], [230.7, 200.0, 340.0]],
[[300.0, 0.0, 100.0], [386.6, 0.0, 150.0], [386.6, 200.0, 150.0], [300.0, 200.0, 100.0]],
[[50.0, 0.0, 50.0], [100.0, 0.0, 136.6], [100.0, 200.0, 136.6], [50.0, 200.0, 50.0]]]
wallsr_fact = create_walls_fact(wallsr_list)
fact_list = [pos_fact, vel_fact, G_fact, B_fact, wallsr_fact]
fact_list_encoded = json.dumps(fact_list).encode('utf-8')
scroll_assignment_list = [{"fact": pos_ref, "assignment": {"kind": "OMS", "uri": 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1'}},
{"fact": vel_ref, "assignment": {"kind": "OMS", "uri": 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact2'}},
{"fact": G_ref, "assignment": {"kind": "OMS", "uri": 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3'}},
{"fact": B_ref, "assignment": {"kind": "OMS", "uri": 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact4'}},
{"fact": W_ref, "assignment": {"kind": "OMS", "uri": 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact5'}}]
scroll_application = {"scroll": bouncing_scroll,
"assignments": scroll_assignment_list}
scroll_encoded = json.dumps(scroll_application).encode('utf-8')
t1 = time.time()
conn = http.client.HTTPConnection(HOST, port=PORT)
conn.request("POST", "/fact/bulkadd", headers=headers, body=fact_list_encoded)
response = conn.getresponse()
data = response.read()
print(response.status, response.reason)
print(time.time() - t1)
data_dict = json.loads(data.decode('utf-8'))
t2 = time.time()
conn = http.client.HTTPConnection(HOST, port=PORT)
conn.request("POST", "/scroll/apply", headers=headers, body=scroll_encoded)
response = conn.getresponse()
data = response.read()
print(response.status, response.reason)
print(time.time() - t2)
data_dict = json.loads(data.decode('utf-8'))
for i in range(len(data_dict["acquiredFacts"])):
print(data_dict["acquiredFacts"][i])
rel_fact = data_dict['acquiredFacts'][0]["df"]["arguments"]
values = []
for rf in rel_fact:
rfa = rf["arguments"]
cvals = []
for ri2, rrf in enumerate(rfa):
if ri2 == len(rfa) - 2:
cvals.extend([x["float"] for x in rrf["arguments"][0]["arguments"]])
cvals.append(rrf["arguments"][1]["float"])
elif ri2 == len(rfa) - 1:
cvals.append(rrf["float"])
else:
cvals.extend([x["float"] for x in rrf["arguments"]])
values.append(cvals)
print("Step\tX\tY\tZ\tXv\tYv\tZv\tht\tnx\tny\tnz")
for i, v in enumerate(values):
print("%d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f" % (i, v[0], v[1], v[2], v[3], v[4], v[5], v[9], v[6], v[7], v[8]))
import matplotlib.pyplot as plt
import numpy as np
def get_xyz_wrap(xs, ys, zs, xv, yv, zv):
def get_xyz(ct):
rx = xs + ct * xv + 0.5 * g[0] * ct**2
ry = ys + ct * yv + 0.5 * g[1] * ct**2
rz = zs + ct * zv + 0.5 * g[2] * ct**2
return np.array([rx, ry, rz])
return get_xyz
# plot ---------------------------------------------------- #
def floatRgb(mag, cmin, cmax):
""" Return a tuple of floats between 0 and 1 for R, G, and B. """
# Normalize to 0-1
x = float(mag - cmin) / (cmax - cmin)
blue = np.minimum(np.maximum(4*(0.75-x), 0.), 1.)
red = np.minimum(np.maximum(4*(x-0.25), 0.), 1.)
green = np.minimum(np.maximum(4*np.abs(x-0.5)-1., 0.), 1.)
return red, green, blue
def rgb(mag, cmin, cmax):
""" Return a tuple of integers, as used in AWT/Java plots. """
red, green, blue = floatRgb(mag, cmin, cmax)
return int(red*255), int(green*255), int(blue*255)
def strRgb(mag, cmin, cmax):
""" Return a hex string, as used in Tk plots. """
return "#%02x%02x%02x" % rgb(mag, cmin, cmax)
plt.figure()
ax = plt.axes(projection ="3d")
pos3ds = []
colors = []
for w in wallsr_list:
spos = np.array(w[0])
in1 = np.array(w[1]) -np.array( w[0])
in2 = np.array(w[3]) - np.array(w[0])
for i1 in np.arange(0, 1.01, 0.1):
for i2 in np.arange(0, 1.01, 0.1):
cur_pos = spos + i1 * in1 + i2 * in2
pos3ds.append([cur_pos[0], cur_pos[1], cur_pos[2]])
colors.append(strRgb(cur_pos[1], 0, 400))
for mii, mi in enumerate(values):
xyz_func = get_xyz_wrap(mi[0], mi[1], mi[2], mi[3], mi[4], mi[5])
pos3ds.extend([xyz_func(ct) for ct in np.arange(0, mi[9], 0.01)])
colors.extend([strRgb(xyz_func(ct)[1], 0, 400) for ct in np.arange(0, mi[9], 0.01)])
pos3ds = np.array(pos3ds)
ax.scatter3D(pos3ds[:, 0], pos3ds[:, 1], pos3ds[:, 2], color=colors)
plt.show()
# plot ---------------------------------------------------- #
import http.client
import json
import time
HOST = 'localhost' #'127.0.0.1'
PORT = 8085
headers = {'Content-type': 'application/json'}
bouncing_scroll = 'http://mathhub.info/FrameIT/frameworld?WBouncingScroll'
pos_ref = {'uri': 'http://mathhub.info/FrameIT/frameworld?WBouncingScroll/Problem?position'}
vel_ref = {'uri': 'http://mathhub.info/FrameIT/frameworld?WBouncingScroll/Problem?velocity'}
G_ref = {'uri': 'http://mathhub.info/FrameIT/frameworld?WBouncingScroll/Problem?g_base'}
B_ref = {'uri': 'http://mathhub.info/FrameIT/frameworld?WBouncingScroll/Problem?bounce'}
W_ref = {'uri': 'http://mathhub.info/FrameIT/frameworld?WBouncingScroll/Problem?walls'}
real_list = 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory2?real_list'
list_type = 'http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?ListType'
product = 'http://gl.mathhub.info/MMT/LFX/Sigma?Symbols?Product'
real_lit = 'http://mathhub.info/MitM/Foundation?RealLiterals?real_lit'
cons = 'http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?cons'
cons_nil = 'http://gl.mathhub.info/MMT/LFX/Datatypes?ListSymbols?nil_constant'
tuple_mmt = 'http://gl.mathhub.info/MMT/LFX/Sigma?Symbols?Tuple'
def list_element_4tuple(x1, y1, x2, y2):
return {'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': x1, 'kind': 'OMF'},
{'float': y1, 'kind': 'OMF'}],
'kind': 'OMA'},
{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': x2, 'kind': 'OMF'},
{'float': y2, 'kind': 'OMF'}],
'kind': 'OMA'}],
'kind': 'OMA'}
def list_element_4tuple_plus_nil(x1, y1, x2, y2):
return {'applicant': {'uri': cons, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': cons_nil, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'}],
'kind': 'OMA'},
{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'}],
'kind': 'OMA'}],
'kind': 'OMA'}],
'kind': 'OMA'},
{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': x1, 'kind': 'OMF'},
{'float': y1, 'kind': 'OMF'}],
'kind': 'OMA'},
{'applicant': {'uri': tuple_mmt, 'kind': 'OMS'},
'arguments': [{'float': x2, 'kind': 'OMF'},
{'float': y2, 'kind': 'OMF'}],
'kind': 'OMA'}],
'kind': 'OMA'}],
'kind': 'OMA'}
def cons_2elements(e1, e2):
return {'applicant': {'uri': cons, 'kind': 'OMS'},
'arguments': [e1, e2],
'kind': 'OMA'}
def construct_list_4tuple_df(values):
# Values needs to be of the form [[x1, y1, x2, y2], [x1, y1, x2, y2], ...]
prev_ele = {}
for ci, cv in enumerate(values[::-1]):
if ci == 0:
prev_ele = list_element_4tuple_plus_nil(cv[0], cv[1], cv[2], cv[3])
else:
cur_ele = list_element_4tuple(cv[0], cv[1], cv[2], cv[3])
prev_ele = cons_2elements(prev_ele, cur_ele)
return prev_ele
def create_walls_fact(values):
# Values needs to be of the form [[x1, y1, x2, y2], [x1, y1, x2, y2], ...]
return {'ref': W_ref,
'label': 'Walls',
'tp': {'applicant': {'uri': list_type, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'}],
'kind': 'OMA'},
{'applicant': {'uri': product, 'kind': 'OMS'},
'arguments': [{'uri': real_lit, 'kind': 'OMS'},
{'uri': real_lit, 'kind': 'OMS'}],
'kind': 'OMA'}],
'kind': 'OMA'}],
'kind': 'OMA'},
'kind': 'general',
'df': construct_list_4tuple_df(values)
}
def create_R_fact(val, ref):
return {"ref": ref,
"label": "X",
"kind": "general",
"tp": {'uri': 'http://mathhub.info/MitM/Foundation?RealLiterals?real_lit',
'kind': 'OMS'},
"df": {"kind": "OMF", "float": val}
}
def create_point_fact(val, ref):
return {"ref": ref,
"label": "P",
"kind": "general",
"tp": {"kind": "OMS", "uri": "http://mathhub.info/MitM/core/geometry?3DGeometry?point"},
"df": {"kind": "OMA", "applicant": {"kind": "OMS", "uri": "http://gl.mathhub.info/MMT/LFX/Sigma?Symbols?Tuple"},
"arguments": [{"kind": "OMF", "float": val[0]},
{"kind": "OMF", "float": val[1]},
{"kind": "OMF", "float": val[2]}]}}
g = -200.0
pos_fact = create_point_fact([0.0, 300.0, 380.0], pos_ref)
vel_fact = create_point_fact([0.0, 150.0, -490.0], vel_ref)
G_fact = create_point_fact([0.0, g, 0.0], G_ref)
B_fact = create_R_fact(0.8, B_ref)
#walls_fact = create_walls_fact([[-10000.0, 0.0, 10000.0, 0.0]])
walls_list = [[-1.0, 0.0, 401.0, 0.0],
[0.0, -1.0, 0.01, 401.0],
[400.0, -1.0, 400.01, 401.0],
[-1.0, 400.0, 401.0, 400.0],
[50.0, 200.0, 120.0, 270.0],
[150.0, 100.0, 200.0, 100.0],
[150.0, 285.0, 200.0, 200.0],
[230.0, 360.0, 300.0, 300.0],
[300.0, 100.0, 385.0, 150.0],
[50.0, 50.0, 100.0, 135.0]]
walls_fact = create_walls_fact(walls_list)
fact_list = [pos_fact, vel_fact, G_fact, B_fact, walls_fact]
fact_list_encoded = json.dumps(fact_list).encode('utf-8')
scroll_assignment_list = [{"fact": pos_ref, "assignment": {"kind": "OMS", "uri": 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact1'}},
{"fact": vel_ref, "assignment": {"kind": "OMS", "uri": 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact2'}},
{"fact": G_ref, "assignment": {"kind": "OMS", "uri": 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact3'}},
{"fact": B_ref, "assignment": {"kind": "OMS", "uri": 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact4'}},
{"fact": W_ref, "assignment": {"kind": "OMS", "uri": 'http://mathhub.info/FrameIT/frameworld?DefaultSituationSpace/SituationTheory1?fact5'}}]
scroll_application = {"scroll": bouncing_scroll,
"assignments": scroll_assignment_list}
scroll_encoded = json.dumps(scroll_application).encode('utf-8')
t1 = time.time()
conn = http.client.HTTPConnection(HOST, port=PORT)
conn.request("POST", "/fact/bulkadd", headers=headers, body=fact_list_encoded)
response = conn.getresponse()
data = response.read()
print(response.status, response.reason)
print(time.time() - t1)
data_dict = json.loads(data.decode('utf-8'))
t2 = time.time()
conn = http.client.HTTPConnection(HOST, port=PORT)
conn.request("POST", "/scroll/apply", headers=headers, body=scroll_encoded)
response = conn.getresponse()
data = response.read()
print(response.status, response.reason)
print(time.time() - t2)
data_dict = json.loads(data.decode('utf-8'))
for i in range(len(data_dict["acquiredFacts"])):
print(data_dict["acquiredFacts"][i])
rel_fact = data_dict['acquiredFacts'][0]["df"]["arguments"]
values = []
def rec_vals(facts):
for rf in facts:
if rf["applicant"]["uri"] == cons_nil:
continue
elif len(rf["arguments"]) == 3:
rfa = rf["arguments"]
cvals = []
for ri2, rrf in enumerate(rfa):
cvals.extend([x["float"] for x in rrf["arguments"]])
values.append(cvals)
continue
else:
rec_vals(rf["arguments"])
return
rec_vals(rel_fact)
print("Step\tX\tY\tXv\tYv\tht\tm")
for i, v in enumerate(values):
print("%d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f" % (i, v[0], v[1], v[2], v[3], v[4], v[5]))
import matplotlib.pyplot as plt
import numpy as np
def get_xy(xs, ys, xv, yv, ct):
rx = xs + ct * xv
ry = ys + ct * yv + 0.5 * g * ct**2
return [rx, ry]
plt.figure()
for wl in walls_list:
plt.plot([wl[0], wl[2]], [wl[1], wl[3]], color="blue", linewidth=3)
for i, vl in enumerate(values):
pvals = np.array([get_xy(vl[0], vl[1], vl[2], vl[3], cct) for cct in np.arange(0, vl[4], 0.01)])
plt.scatter(pvals[:, 0], pvals[:, 1], color="green", s=1)
plt.show()
File deleted
File deleted