From 6463c684c0333b48b8c9ca9dcfce94af7c41a210 Mon Sep 17 00:00:00 2001 From: Lucas <lucas.heublein@t-online.de> Date: Thu, 7 Sep 2023 21:56:16 +0200 Subject: [PATCH] Added way to deal with acceleration vectors for bouncing --- connect_to_mmt_W3Bounce.py | 10 ++++---- source/Scrolls/W3DBouncingScroll.mmt | 36 ++++++++++++++-------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/connect_to_mmt_W3Bounce.py b/connect_to_mmt_W3Bounce.py index a74414c..c4d99d1 100644 --- a/connect_to_mmt_W3Bounce.py +++ b/connect_to_mmt_W3Bounce.py @@ -148,10 +148,10 @@ def create_point_fact(val, ref): {"kind": "OMF", "float": val[1]}, {"kind": "OMF", "float": val[2]}]}} -g = -200.0 +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([0.0, g, 0.0], G_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]], @@ -224,9 +224,9 @@ import numpy as np def get_xyz_wrap(xs, ys, zs, xv, yv, zv): def get_xyz(ct): - rx = xs + ct * xv - ry = ys + ct * yv - rz = zs + ct * zv + 0.5 * g * ct**2 + 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 diff --git a/source/Scrolls/W3DBouncingScroll.mmt b/source/Scrolls/W3DBouncingScroll.mmt index 6055c0a..efcc271 100644 --- a/source/Scrolls/W3DBouncingScroll.mmt +++ b/source/Scrolls/W3DBouncingScroll.mmt @@ -21,11 +21,11 @@ theory W3DBouncingScroll = thenx true elsex false) elsex false â™ - get_abcs : List[wall] ⟶ point ⟶ point ⟶ ℠⟶ List[point × wall] ☠= - [w, p, v, g] w map ([wi : wall] ⟨⟨(times_real_lit (wi.c) g), - (plus_real_lit (plus_real_lit (times_real_lit (wi.a) (v _x)) (times_real_lit (wi.b) (v _y))) (times_real_lit (wi.c) (v _z))), - (plus_real_lit (plus_real_lit (plus_real_lit (times_real_lit (wi.a) (p _x)) (times_real_lit (wi.b) (p _y))) (times_real_lit (wi.c) (p _z))) (minus_real_lit (wi.d)))⟩, - wi⟩) â™ + get_abcs : List[wall] ⟶ point ⟶ point ⟶ point ⟶ List[point × wall] ☠= + [w, p, v, g] w map ([wi : wall] ⟨⟨(plus_real_lit (times_real_lit (wi.a) (g _x)) (plus_real_lit (times_real_lit (wi.b) (g _y)) (times_real_lit (wi.c) (g _z)))), + (plus_real_lit (plus_real_lit (times_real_lit (wi.a) (v _x)) (times_real_lit (wi.b) (v _y))) (times_real_lit (wi.c) (v _z))), + (plus_real_lit (plus_real_lit (plus_real_lit (times_real_lit (wi.a) (p _x)) (times_real_lit (wi.b) (p _y))) (times_real_lit (wi.c) (p _z))) (minus_real_lit (wi.d)))⟩, + wi⟩) â™ mget_hts : (point × wall) ⟶ (℠× ℠× wall) ☠= [cabc] (℠× ℠× wall) ifx (eq_zero ((Ï€l cabc) _x)) thenx ((℠× ℠× wall) ifx (eq_zero ((Ï€l cabc) _y)) @@ -36,11 +36,11 @@ theory W3DBouncingScroll = thenx (⟨times_real_lit (plus_real_lit (minus_real_lit ((Ï€l cabc) _y)) (sqrt (plus_real_lit (times_real_lit ((Ï€l cabc) _y) ((Ï€l cabc) _y)) (minus_real_lit (times_real_lit 2.0 (times_real_lit ((Ï€l cabc) _x) ((Ï€l cabc) _z))))))) (inv_real_lit ((Ï€l cabc) _x)), times_real_lit (plus_real_lit (minus_real_lit ((Ï€l cabc) _y)) (minus_real_lit (sqrt (plus_real_lit (times_real_lit ((Ï€l cabc) _y) ((Ï€l cabc) _y)) (minus_real_lit (times_real_lit 2.0 (times_real_lit ((Ï€l cabc) _x) ((Ï€l cabc) _z)))))))) (inv_real_lit ((Ï€l cabc) _x)), (Ï€r cabc)⟩) elsex (⟨-1.0, -1.0, (Ï€r cabc)⟩)) â™ - get_pt : ℠⟶ point ⟶ point ⟶ ℠⟶ point ☠= - [rht, rp, rv, rg] ⟨plus_real_lit (rp _x) (times_real_lit (rv _x) rht), - plus_real_lit (rp _y) (times_real_lit (rv _y) rht), - plus_real_lit (plus_real_lit (rp _z) (times_real_lit (rv _z) rht)) (times_real_lit (times_real_lit 0.5 rg) (times_real_lit rht rht))⟩ â™ - check_hit : (℠× wall) ⟶ point ⟶ point ⟶ ℠⟶ bool ☠= + get_pt : ℠⟶ point ⟶ point ⟶ point ⟶ point ☠= + [rht, rp, rv, rg] ⟨plus_real_lit (plus_real_lit (rp _x) (times_real_lit (rv _x) rht)) (times_real_lit (times_real_lit 0.5 (rg _x)) (times_real_lit rht rht)), + plus_real_lit (plus_real_lit (rp _y) (times_real_lit (rv _y) rht)) (times_real_lit (times_real_lit 0.5 (rg _y)) (times_real_lit rht rht)), + plus_real_lit (plus_real_lit (rp _z) (times_real_lit (rv _z) rht)) (times_real_lit (times_real_lit 0.5 (rg _z)) (times_real_lit rht rht))⟩ â™ + check_hit : (℠× wall) ⟶ point ⟶ point ⟶ point ⟶ bool ☠= [rw, rp, rv, rg] ([np : point] (bool) ifx (leq_real_lit (scalar_productI ((Ï€r rw).point1) ((Ï€r rw).u)) (scalar_productI np ((Ï€r rw).u))) thenx ((bool) ifx (leq_real_lit (scalar_productI np ((Ï€r rw).u)) (scalar_productI ((Ï€r rw).point2) ((Ï€r rw).u))) thenx ((bool) ifx (leq_real_lit (scalar_productI ((Ï€r rw).point1) (point_subtractI ((Ï€r rw).point4) ((Ï€r rw).point1))) (scalar_productI np (point_subtractI ((Ï€r rw).point4) ((Ï€r rw).point1)))) @@ -50,8 +50,8 @@ theory W3DBouncingScroll = elsex false) (get_pt (Ï€l rw) rp rv rg) â™ fold_func : (℠× wall) ⟶ (point × â„) ⟶ (point × â„) ☠= [cur][acc] (point × â„) ifx (leq_real_lit (Ï€l cur) (Ï€r acc)) thenx (⟨(Ï€r cur).norm_vec, (Ï€l cur)⟩) elsex acc â™ - calc_new_vals : (point × point × (point × â„)) ⟶ (℠× â„) ⟶ (point × point) ☠= - [v, bv] ⟨get_pt (Ï€r (Ï€r (Ï€r v))) (Ï€l v) (Ï€l (Ï€r v)) (Ï€l bv), ([d : point] vec_multI (Ï€r bv) (point_subtractI d (vec_multI (times_real_lit 2.0 (scalar_productI d (Ï€l (Ï€r (Ï€r v))))) (Ï€l (Ï€r (Ï€r v)))))) (⟨(Ï€l (Ï€r v)) _x, (Ï€l (Ï€r v)) _y, plus_real_lit ((Ï€l (Ï€r v)) _z) (times_real_lit (Ï€r (Ï€r (Ï€r v))) (Ï€l bv))⟩)⟩ â™ + calc_new_vals : (point × point × (point × â„)) ⟶ (point × â„) ⟶ (point × point) ☠= + [v, bv] ⟨get_pt (Ï€r (Ï€r (Ï€r v))) (Ï€l v) (Ï€l (Ï€r v)) (Ï€l bv), ([d : point] vec_multI (Ï€r bv) (point_subtractI d (vec_multI (times_real_lit 2.0 (scalar_productI d (Ï€l (Ï€r (Ï€r v))))) (Ï€l (Ï€r (Ï€r v)))))) (⟨plus_real_lit ((Ï€l (Ï€r v)) _x) (times_real_lit (Ï€r (Ï€r (Ï€r v))) ((Ï€l bv) _x)), plus_real_lit ((Ï€l (Ï€r v)) _y) (times_real_lit (Ï€r (Ï€r (Ï€r v))) ((Ï€l bv) _y)), plus_real_lit ((Ï€l (Ï€r v)) _z) (times_real_lit (Ï€r (Ï€r (Ï€r v))) ((Ï€l bv) _z))⟩)⟩ â™ end_cond : (point × point × (point × â„)) ⟶ bool ☠= [vals] leq_real_lit (Ï€r (Ï€r (Ï€r vals))) 0.1 â™ map_reduce_hts : (℠× ℠× wall) ⟶ (℠× wall) ☠= @@ -64,12 +64,12 @@ theory W3DBouncingScroll = elsex ((℠× wall) ifx (leq_real_lit (Ï€l wsi) (Ï€l (Ï€r wsi))) thenx (⟨πl wsi, Ï€r (Ï€r wsi)⟩) elsex (⟨πl (Ï€r wsi), Ï€r (Ï€r wsi)⟩))) â™ - get_next_vals : List[wall] ⟶ (℠× â„) ⟶ ((point × point × (point × â„)) ⟶ (point × point × (point × â„))) ☠= + get_next_vals : List[wall] ⟶ (point × â„) ⟶ ((point × point × (point × â„)) ⟶ (point × point × (point × â„))) ☠= [aw, abv] ([v : point × point × (point × â„)] ([x : point × point] ⟨πl x, Ï€r x, ((((((get_abcs aw (Ï€l x) (Ï€r x) (Ï€l abv)) map mget_hts) map map_reduce_hts) filter ([wsj : ℠× wall] leq_real_lit 0.000001 (Ï€l wsj))) filter ([wsk : ℠× wall] check_hit wsk (Ï€l x) (Ï€r x) (Ï€l abv))) fold ⟨⟨-1.0, -1.0, -1.0⟩, 99999.9⟩ fold_func)⟩) (calc_new_vals v abv)) â™ - prep : List[wall] ⟶ point ⟶ point ⟶ ℠⟶ (point × point × (point × â„)) ☠= + prep : List[wall] ⟶ point ⟶ point ⟶ point ⟶ (point × point × (point × â„)) ☠= [awi, p, v, g] ⟨p, v, ((((((get_abcs awi p v g) map mget_hts) map map_reduce_hts) filter ([wsj : ℠× wall] leq_real_lit 0.000001 (Ï€l wsj))) filter ([wsk : ℠× wall] check_hit wsk p v g)) fold ⟨⟨-1.0, -1.0, -1.0⟩, 99999.9⟩ fold_func)⟩ â™ - get_pos_fun: point ⟶ point ⟶ ℠⟶ (℠⟶ point) ☠= - [p, v, g] ([t] ⟨plus_real_lit (p _x) (times_real_lit (v _x) t), plus_real_lit (p _y) (times_real_lit (v _y) t), plus_real_lit (times_real_lit (times_real_lit 0.5 g) (times_real_lit t t)) (plus_real_lit (p _z) (times_real_lit (v _z) t))⟩) â™ + get_pos_fun: point ⟶ point ⟶ point ⟶ (℠⟶ point) ☠= + [p, v, g] ([t] ⟨plus_real_lit (times_real_lit (times_real_lit 0.5 (g _x)) (times_real_lit t t)) (plus_real_lit (p _x) (times_real_lit (v _x) t)), plus_real_lit (times_real_lit (times_real_lit 0.5 (g _y)) (times_real_lit t t)) (plus_real_lit (p _y) (times_real_lit (v _y) t)), plus_real_lit (times_real_lit (times_real_lit 0.5 (g _z)) (times_real_lit t t)) (plus_real_lit (p _z) (times_real_lit (v _z) t))⟩) â™ red_ht : (point × point × (point × â„)) ⟶ ℠☠= [cele] Ï€r (Ï€r (Ï€r cele)) â™ âš @@ -89,9 +89,9 @@ theory W3DBouncingScroll = include ?W3DBouncingScroll/Problem â™ //testw : List[point × point × point × point] ☠= cons (⟨⟨0.0, 0.0, 0.0⟩, ⟨1.0, 0.0, 0.0⟩, ⟨2.0, 0.0, 0.0⟩, ⟨3.0, 0.0, 0.0⟩⟩) (cons (⟨⟨0.0, 1.0, 0.0⟩, ⟨1.0, 1.0, 0.0⟩, ⟨2.0, 1.0, 0.0⟩, ⟨3.0, 1.0, 0.0⟩⟩) nil) â™ //wallse : List[wall] ☠= wallsr map ([cw] create_wall (Ï€l cw) (Ï€l (Ï€r cw)) (Ï€l (Ï€r (Ï€r cw))) (Ï€r (Ï€r (Ï€r cw)))) â™ - full_list: List[point × point × (point × â„)] ☠= stepUntil (point × point × (point × â„)) (prep (wallsr map ([cw] create_wall (Ï€l cw) (Ï€l (Ï€r cw)) (Ï€l (Ï€r (Ï€r cw))) (Ï€r (Ï€r (Ï€r cw))))) position velocity (g_base _y)) (get_next_vals (wallsr map ([cw] create_wall (Ï€l cw) (Ï€l (Ï€r cw)) (Ï€l (Ï€r (Ï€r cw))) (Ï€r (Ï€r (Ï€r cw))))) ⟨(g_base _y), bounce⟩) end_cond â™ + full_list: List[point × point × (point × â„)] ☠= stepUntil (point × point × (point × â„)) (prep (wallsr map ([cw] create_wall (Ï€l cw) (Ï€l (Ï€r cw)) (Ï€l (Ï€r (Ï€r cw))) (Ï€r (Ï€r (Ï€r cw))))) position velocity g_base) (get_next_vals (wallsr map ([cw] create_wall (Ï€l cw) (Ï€l (Ï€r cw)) (Ï€l (Ï€r (Ï€r cw))) (Ï€r (Ï€r (Ï€r cw))))) ⟨g_base, bounce⟩) end_cond â™ ht_list: List[â„] ☠= full_list map red_ht â™ - fun_list : List[℠⟶ point] ☠= full_list map ([vals] get_pos_fun (Ï€l vals) (Ï€l (Ï€r vals)) (g_base _y)) â™ + fun_list : List[℠⟶ point] ☠= full_list map ([vals] get_pos_fun (Ï€l vals) (Ï€l (Ï€r vals)) g_base) â™ meta ?MetaAnnotations?label "W3DBouncingScroll" â™ meta ?MetaAnnotations?description s"Bouncing " â™ âš -- GitLab