Interactive MecLib Objects
Collection of developed MecLib objects
by aaronamran
HTML
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jsxgraph/distrib/jsxgraphcore.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jsxgraph/distrib/jsxgraph.css">
<div id="jxgbox" class="jxgbox" style="width:500px; height:500px">
</div>
<!---->
<p id="init">[
[ "grid", "x","y",-1, 15,-1,11, 40],
[ "angle", ".", [1,9],[2,9],0.6,90 ],
[ "angle", "\\alpha", [3,9],[4,9],0.8,60 ],
[ "angle1", "\\beta", [5,9],[6,9],0.8,60 ],
[ "angle2", "\\gamma", [7,9],[8,9],0.8,60 ],
[ "bar", "b", [1,8], [3, 8], "show"],
[ "line", "", [1, 2, 2, 3], [7, 6, 7, 6], "--" ,0.8],
[ "rot", "\\omega", [1.5, 4], [1,4.5], [2.2,4.7] ],
[ "beam","",[1, 1],[3,3],[1,3],[3,1],[1,2],[3,2],0.2, "show"],
[ "dashpot", "d", [5, 8], [8, 8], 0.5, 1, "show"],
[ "dim", "\\ell", [5, 5], [8, 5], 1],
[ "fix1", "A", [4, 4], 60, "show" ],
[ "fix12", "B", [5, 4], 60, "show"],
[ "fix123", "C", [6.5, 4], 60, "show" ],
[ "fix13", "D", [7.5, 4], 60, "show" ],
[ "polygon", "",[5,1], [5,3], [6,3], [6,1], "show"],
[ "circle", "c1", [10, 9], 1, 45, "SHOW" ],
[ "circle", "c2", [13, 9], 0.5, 45, "SHOW" ],
[ "rope", " ", [10, 9], 1, [13, 9], -0.5, "SHOW" ],
[ "springc", "c", [10, 7], [10, 4], 0.5, 10, "show" ],
[ "springt", "t", [12, 7], [12, 4], 0.5, 30, 9, "show" ]
]
</p>
<p id="data"></p>
<p id="fbd_names"></p>
JavaScript
// Start of jsfiddle header.
var mode = "jsfiddle";
var divid = "jxgbox";
var fbd_names = "fbd_names";
var stateRef = "data";
var initstring = document.getElementById("init").innerHTML;
const centeredLabelStyle = {
size: 0,
showInfobox: false,
label: {
offset: [0, 0],
anchorX: 'middle',
anchorY: 'middle'
}
};
// https://github.com/mkraska/meclib/wiki
// version info
const versionText= "JXG "+JXG.version+" Meclib 2023 07 27";
const highlightColor = "orange";
const movableLineColor = "blue";
const loadColor = "blue";
const defaultMecLayer = 6;
var pxunit = 1/40; // is reset by "grid"
var a = 16*pxunit; // is reset by "grid"
const deg2rad = Math.PI/180, rad2deg = 180/Math.PI;
const tolPointLine = 0.001;
var xscale = 1, yscale = 1; // default scale for infobox, can be modified by "grid"
var dpx = 1, dpy = 1; // default decimal precision for infobox, can be modified by "grid"
// infobox settings, further settings after board initiation
JXG.Options.infobox.layer = defaultMecLayer+5;
JXG.Options.infobox.strokeColor = 'black';
JXG.Options.infobox.cssStyle = 'background-color: #ffffffdd;'
// snap settings. Interactive objects are handled explicity
JXG.Options.point.snapToGrid = false; // grid snap spoils rotated static objects
JXG.Options.point.snapSizeX = 0.1;
JXG.Options.point.snapSizeY = 0.1;
// interactive objects are released explicitly
JXG.Options.point.fixed = true;
JXG.Options.line.fixed = true;
JXG.Options.circle.fixed = true;
// label settings
JXG.Options.text.useMathJax = true;
JXG.Options.text.parse = false;
JXG.Options.label.useMathJax = true;
JXG.Options.label.offset = [0, 0];
JXG.Options.label.anchorY = 'middle';
// suppress automatic labels
JXG.Options.point.name = "";
// highlighting is activated explicitly for interactive objects
JXG.Options.curve.highlight = false;
JXG.Options.label.highlight = false;
JXG.Options.text.highlight = false;
JXG.Options.circle.highlight = false;
JXG.Options.line.highlight =...