Skip to content
Snippets Groups Projects
Commit 89a757a0 authored by Michael Leuschel's avatar Michael Leuschel
Browse files

add a simple vector visualisation example

parent deb63a8e
No related branches found
No related tags found
No related merge requests found
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
<?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>
{
"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": [
]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment