diff --git a/Physics/VectorVisualisation.mch b/Physics/VectorVisualisation.mch index b2ecfd67cbade4b451d7e64382efb869a7973952..821e90018c78a8386043b68006e2265d620c63b7 100644 --- a/Physics/VectorVisualisation.mch +++ b/Physics/VectorVisualisation.mch @@ -2,6 +2,7 @@ MACHINE VectorVisualisation // Small visualisation to show two vectors and various operations on them DEFINITIONS NVECS==2; +// "VectorVisualisationVisB.def"; // can now be used as alternative VISB_JSON_FILE == "vector_visualisation_visb.json"; "LibrarySVG.def" INCLUDES Vectors2 @@ -14,6 +15,8 @@ OPERATIONS vectors(i) := times_vec(k,vectors(i)) END; AddVec = BEGIN vectors(1):= add_vec(vectors(1),vectors(2)) END; + SubVec1 = BEGIN vectors(1):= [vectors(1)(1)-vectors(2)(1), vectors(1)(2)-vectors(2)(2)] END; + SubVec2 = BEGIN vectors(1):= [vectors(2)(1)-vectors(1)(1), vectors(2)(2)-vectors(1)(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 diff --git a/Physics/VectorVisualisationVisB.def b/Physics/VectorVisualisationVisB.def new file mode 100644 index 0000000000000000000000000000000000000000..4028c408621af98c33866381c58d5e2eb6cbd669 --- /dev/null +++ b/Physics/VectorVisualisationVisB.def @@ -0,0 +1,89 @@ +DEFINITIONS + "LibrarySVG.def"; + "LibraryStrings.def"; + SCALE100 == 0.05; + VISB_JSON_FILE == ""; + VISB_SVG_OBJECTS1 == rec( + svg_class:"circle", + `id`:"origin", + cx:0, + cy:0, + r:5, + `stroke-width`:0.0, + fill:"green"); + + VISB_SVG_OBJECTS2 == ran(%vec.(vec:1..NVECS| + rec( + svg_class:"line", + `id`:"vector_"^TO_STRING(vec), + x1:0, + y1:0, + x2:5, + y2:5, + stroke:IF vec=1 THEN "blue" ELSIF vec=2 THEN "green" ELSE "#000" END, + `stroke-width`:1.75, + `marker-end`:"url(#arrowhead)" + ))); + VISB_SVG_UPDATES2 == ran(%vec.(vec:1..NVECS| + rec( + `id`:"vector_"^TO_STRING(vec), + x2:vectors(vec)(1) / SCALE100, + y2:-vectors(vec)(2)/ SCALE100 + ))); + + VISB_SVG_UPDATES3 == + rec( + `id`:"axis", + points:svg_axis(0..10,1.0/SCALE100,10.0/SCALE100,0.2/SCALE100) + ); + + VISB_SVG_BOX == rec(height:500,width:500,viewBox:"-250 -250 500 600"); + + VISB_SVG_CONTENTS == ''' + <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" /> + + <text text-align="left" x="250" y="30" + font-size ="20" fill="blue" font-family="sans-serif"> + <tspan id="vec_1_0_txt">v1</tspan> + </text> + <text text-align="left" x="250" y="50" + font-size ="20" fill="blue" font-family="sans-serif"> + <tspan id="vec_1_1_txt">x(1)</tspan> + </text> + <text text-align="left" x="250" y="70" + font-size ="20" fill="blue" font-family="sans-serif"> + <tspan id="vec_1_2_txt">x(2)</tspan> + </text> + + + <text text-align="left" x="250" y="-70" + font-size ="20" fill="green" font-family="sans-serif"> + <tspan id="vec_2_0_txt">v2</tspan> + </text> + <text text-align="left" x="250" y="-50" + font-size ="20" fill="green" font-family="sans-serif"> + <tspan id="vec_2_1_txt">x(1)</tspan> + </text> + <text text-align="left" x="250" y="-30" + font-size ="20" fill="green" font-family="sans-serif"> + <tspan id="vec_2_2_txt">x(2)</tspan> + </text> +''' \ No newline at end of file