diff --git a/Physics/VectorVisualisation.mch b/Physics/VectorVisualisation.mch new file mode 100644 index 0000000000000000000000000000000000000000..b2ecfd67cbade4b451d7e64382efb869a7973952 --- /dev/null +++ b/Physics/VectorVisualisation.mch @@ -0,0 +1,21 @@ +MACHINE VectorVisualisation +// Small visualisation to show two vectors and various operations on them +DEFINITIONS + NVECS==2; + VISB_JSON_FILE == "vector_visualisation_visb.json"; + "LibrarySVG.def" +INCLUDES Vectors2 +VARIABLES vectors +INVARIANT + vectors : 1..NVECS --> VEC +INITIALISATION vectors := [ [0.0, 2.0] , [2.0, 0.0] ] +OPERATIONS + TimesVec(i,k) = PRE i:dom(vectors) & k: {0.5, 0.75, 1.5, 2.0} THEN + vectors(i) := times_vec(k,vectors(i)) + END; + AddVec = BEGIN vectors(1):= add_vec(vectors(1),vectors(2)) END; + MakeUnit(i) = PRE i:dom(vectors) THEN vectors(i):= unit_vec(vectors(i)) END; + SwapXY(i) = PRE i:dom(vectors) THEN vectors(i):= rev(vectors(i)) END; + Opposite(i) = PRE i:dom(vectors) THEN vectors(i):= [-vectors(i)(1),-vectors(i)(2)] END +END + diff --git a/Physics/vector_visualisation.svg b/Physics/vector_visualisation.svg new file mode 100644 index 0000000000000000000000000000000000000000..f15d79eaff65882d7c0253313585fe362b015235 --- /dev/null +++ b/Physics/vector_visualisation.svg @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns="http://www.w3.org/2000/svg" + height="500" width="500" + viewBox="-250 -250 500 500" + > + + + <defs> + <marker id="arrowhead" markerWidth="10" markerHeight="7" + refX="0" refY="3.5" orient="auto"> + <polygon points="0 0, 10 3.5, 0 7" /> + </marker> + + <marker id="startarrow" markerWidth="10" markerHeight="7" + refX="10" refY="3.5" orient="auto"> + <polygon points="10 0, 10 7, 0 3.5" fill="green" /> + </marker> + + <marker id="endarrow" markerWidth="10" markerHeight="7" + refX="0" refY="3.5" orient="auto"> + <polygon points="0 0, 10 3.5, 0 7" fill="green" /> + </marker> + </defs> + + + <polyline points = "0 0, 100 100" id="axis" stroke="gray"> + +</svg> diff --git a/Physics/vector_visualisation_visb.json b/Physics/vector_visualisation_visb.json new file mode 100644 index 0000000000000000000000000000000000000000..2813ae646ce689f32bfebf7aae59a1525466387b --- /dev/null +++ b/Physics/vector_visualisation_visb.json @@ -0,0 +1,58 @@ +{ + "svg": "vector_visualisation.svg", + "comment": "uses new svg object creation", + "definitions": [ + { "name":"SCALE100", + "value" : "0.05" + } + ], + "svg_objects":[ + { + "svg_class":"circle", + "id":"origin", + "cx":"0", + "cy":"0", + "r":"5", + "stroke-width":"0.0", + "fill":"green" + }, + { + "for":{"from":1,"to":"NVECS"}, + "svg_class":"line", + "id":"vector_%0", + "x1":"0", + "y1":"0", + "x2":"55", + "y2":"15", + "stroke":"#000", + "stroke-width":"1.75", + "marker-end":"url(#arrowhead)" + } + ], + "items": [ + { + "id": "vector_1", + "attr": "stroke", + "value" : "\"blue\"" + }, + { + "id": "axis", + "attr": "points", + "value" : "svg_axis(0..10,1.0/SCALE100,10.0/SCALE100,0.2/SCALE100)" + }, + { + "for": {"from":1, "to":"NVECS"}, + "id": "vector_%0", + "attr": "x2", + "value" : "vectors(%0)(1) / SCALE100" + }, + { + "for": {"from":1, "to":"NVECS"}, + "id": "vector_%0", + "attr": "y2", + "value" : "-vectors(%0)(2)/ SCALE100" + } + ], + "events": [ + ] +}