## g2 : object Mechanical extensions. (Requires cartesian coordinates) **Kind**: global namespace * [g2](#g2) : object * _instance_ * [.mark(mrk, loc, [dir])](#g2+mark) ⇒ object * [.label(str, [loc], off)](#g2+label) ⇒ object * [.vec([p], [r])](#g2+vec) ⇒ object * [.avec([p], r, [w], [dw])](#g2+avec) ⇒ object * [.dim([p], [r], args)](#g2+dim) ⇒ object * [.adim([p], r, [w], [dw], args)](#g2+adim) ⇒ object * [.slider([p], w, args)](#g2+slider) ⇒ object * [.spring([p], [r], args)](#g2+spring) ⇒ object * [.damper([p], [r], args)](#g2+damper) ⇒ object * [.link(pts, [closed], [style])](#g2+link) ⇒ object * [.link2(pts, [closed])](#g2+link2) ⇒ object * [.beam(pts)](#g2+beam) ⇒ object * [.beam2(pts)](#g2+beam2) ⇒ object * [.bar([p], [r], [style])](#g2+bar) ⇒ object * [.bar2([p], [r])](#g2+bar2) ⇒ object * [.pulley([p], [r])](#g2+pulley) ⇒ object * [.pulley2([pos], [r])](#g2+pulley2) ⇒ object * [.rope([p1], [r1], [p2], [r2])](#g2+rope) ⇒ object * [.ground(pts, [closed], [args])](#g2+ground) ⇒ object * [.load(pts, spacing, [style])](#g2+load) ⇒ object * _static_ * [.State](#g2.State) : object * [.symbol](#g2.symbol) : object ### g2.mark(mrk, loc, [dir]) ⇒ object Draw markers on line element. **Kind**: instance method of [g2](#g2) **Returns**: object - g2 | Param | Type | Default | Description | | --- | --- | --- | --- | | mrk | object | string | | `g2` object or Marker name. | | loc | number | string | array | | line parameters [0..1]
line location ['beg','end','mid',..]
array of line parameters or strings. | | [dir] | int | 0 | Direction:
-1 : negative tangent direction
0 : no orientation (rotation)
1 : positive tangent direction | **Example** ```js g2().lin(10,10,100,10).mark("tick",[0,0.5,1],1) .arc(100,100,50,3.14).mark("sqr",1,['beg','end']);
[Example](https://goessner.github.io/g2-mec/test/index.html#mark) ``` ### g2.label(str, [loc], off) ⇒ object Add label to certain elements. See element for support and meaning of arguments. *Please note:* any use of the `label` element requires previous setting of the `cartesian` flag, as it highly depends on definition of a right handed coordinate system (which is implemented exclusively here). **Kind**: instance method of [g2](#g2) **Returns**: object - g2 | Param | Type | Default | Description | | --- | --- | --- | --- | | str | string | | Label text | | [loc] | float | string | 'c' | Label location depending on referenced element.
'c': centered, wrt. rec, cir, arc
'beg','mid', 'end', wrt. lin
'n', 'ne', 'e', 'se', 's', 'sw', 'w', or 'nw': cardinal directions | | off | float | | Offset distance [optional]. | ### g2.vec([p], [r]) ⇒ object Draw vector arrow. **Kind**: instance method of [g2](#g2) **Returns**: object - g2 | Param | Type | Default | Description | | --- | --- | --- | --- | | [p] | object | {x:0,y:0} | Start point. | | [r] | object | {dx:10,dy:0} | End point / direction vector in:
{x,y} absolute coordinates
{dx,dy} relative coordinates
{r,w} polar coordinates | ### g2.avec([p], r, [w], [dw]) ⇒ object Angular vector **Kind**: instance method of [g2](#g2) **Returns**: object - g2 | Param | Type | Default | Description | | --- | --- | --- | --- | | [p] | object | {x:0,y:0} | Center point. | | r | float | | Radius | | [w] | float | 0 | Start angle (in radian). | | [dw] | float | Math.PI/2 | Angular range in radian. In case of positive values it is running clockwise with left handed default coordinate system. | ### g2.dim([p], [r], args) ⇒ object Linear dimension **Kind**: instance method of [g2](#g2) **Returns**: object - g2 | Param | Type | Default | Description | | --- | --- | --- | --- | | [p] | object | {x:0,y:0} | Start point. | | [r] | object | {dx:10,dy:0} | Dimension end point / direction vector in:
{x,y} absolute coordinates
{dx,dy} relative coordinates
{r,w} polar coordinates | | args | object | | Arguments object holding style properties. See 'g2.prototype.style' for details. | | [args.pos] | string | "in" | Draw dimension arrows:
'in': between ticks
'out': outside of ticks | ### g2.adim([p], r, [w], [dw], args) ⇒ object Angular dimension **Kind**: instance method of [g2](#g2) **Returns**: object - g2 | Param | Type | Default | Description | | --- | --- | --- | --- | | [p] | object | {x:0,y:0} | Center point. | | r | float | | Radius | | [w] | float | 0 | Start angle (in radian). | | [dw] | float | Math.PI/2 | Angular range in radian. In case of positive values it is running clockwise with left handed default coordinate system. | | args | object | | Arguments object holding style properties. See 'g2.prototype.style' for details. | | [args.pos] | string | "in" | Draw dimension arrows:
'in': between ticks
'out': outside of ticks | ### g2.slider([p], w, args) ⇒ object Draw slider. **Kind**: instance method of [g2](#g2) **Returns**: object - g2 | Param | Type | Default | Description | | --- | --- | --- | --- | | [p] | object | {x:0,y:0,w:0} | Center point. | | w | angle | | Rotation angle [rad] | | args | object | | Arguments object holding style properties. See 'g2.prototype.style' for details. | | [args.b] | float | 32 | Slider breadth. | | [args.h] | float | 16 | Slider height. | ### g2.spring([p], [r], args) ⇒ object Draw linear spring **Kind**: instance method of [g2](#g2) **Returns**: object - g2 | Param | Type | Default | Description | | --- | --- | --- | --- | | [p] | object | {x:0,y:0} | Start point. | | [r] | object | {dx:10,dy:0} | Spring end point / direction vector in:
{x,y} absolute coordinates
{dx,dy} relative coordinates
{r,w} polar coordinates | | args | object | | Arguments object holding style properties. See 'g2.prototype.style' for details. | | [args.h] | float | 16 | Spring height. | ### g2.damper([p], [r], args) ⇒ object Draw line with centered square damper symbol. **Kind**: instance method of [g2](#g2) **Returns**: object - g2 | Param | Type | Default | Description | | --- | --- | --- | --- | | [p] | object | {x:0,y:0} | Start point. | | [r] | object | {dx:10,dy:0} | Damper end point / direction vector in:
{x,y} absolute coordinates
{dx,dy} relative coordinates
{r,w} polar coordinates | | args | object | | Arguments object. | | [args.h] | float | 16 | Spring height. | | [args.style] | any | | Style property. See 'g2.prototype.style' for details. | ### g2.link(pts, [closed], [style]) ⇒ object Draw polygonial link. **Kind**: instance method of [g2](#g2) **Returns**: object - this | Param | Type | Default | Description | | --- | --- | --- | --- | | pts | array | | Array of points. | | [closed] | bool | false | true:closed
false:non-closed. | | [style] | object | | Style object. | ### g2.link2(pts, [closed]) ⇒ object Draw alternate glossy polygonial link. **Kind**: instance method of [g2](#g2) **Returns**: object - this | Param | Type | Default | Description | | --- | --- | --- | --- | | pts | array | | Array of points. | | [closed] | bool | false | true:closed
false:non-closed. | ### g2.beam(pts) ⇒ object Draw polygonial beam. **Kind**: instance method of [g2](#g2) **Returns**: object - this | Param | Type | Description | | --- | --- | --- | | pts | array | Array of points. | ### g2.beam2(pts) ⇒ object Draw alternate glossy polygonial beam. **Kind**: instance method of [g2](#g2) **Returns**: object - this | Param | Type | Description | | --- | --- | --- | | pts | array | Array of points. | ### g2.bar([p], [r], [style]) ⇒ object Draw bar. **Kind**: instance method of [g2](#g2) **Returns**: object - this | Param | Type | Default | Description | | --- | --- | --- | --- | | [p] | v2 | {x:0,y:0} | Start point. | | [r] | v2 | {dx:10,dy:0} | Bar vector in absolute {x,y}, relative {dx,dy} or polar {r,w} coordinates. | | [style] | object | | Style object. | ### g2.bar2([p], [r]) ⇒ object Draw bar. **Kind**: instance method of [g2](#g2) **Returns**: object - this | Param | Type | Default | Description | | --- | --- | --- | --- | | [p] | v2 | {x:0,y:0} | Start point. | | [r] | v2 | {dx:10,dy:0} | Bar end point in absolute {x,y} or vector in relative {dx,dy} or polar {r,w} coordinates. | ### g2.pulley([p], [r]) ⇒ object Draw pulley. **Kind**: instance method of [g2](#g2) **Returns**: object - this | Param | Type | Default | Description | | --- | --- | --- | --- | | [p] | v2 | {x:0,y:0} | Center point. | | [r] | float | 25 | Radius. | ### g2.pulley2([pos], [r]) ⇒ object Draw alternate pulley. **Kind**: instance method of [g2](#g2) **Returns**: object - this | Param | Type | Default | Description | | --- | --- | --- | --- | | [pos] | object | {x:0,y:0,w:0} | Center point position and rotation angle. | | [r] | float | 25 | Radius. | ### g2.rope([p1], [r1], [p2], [r2]) ⇒ object Draw rope. Amount of pulley radii must be greater than 10 units. They are forced to zero otherwise. **Kind**: instance method of [g2](#g2) **Returns**: object - this | Param | Type | Default | Description | | --- | --- | --- | --- | | [p1] | v2 | {x:0,y:0} | Start pulley center. | | [r1] | float | 20 | Start pulley radius. With positive radius the rope leaves the pulley in counterclockwise direction. Negative radius forces the rope to leave in clockwise direction (cartesian rule). | | [p2] | v2 | {x:0,y:0} | End pulley center. | | [r2] | float | 20 | End pulley radius. With positive radius the rope leaves the pulley in counterclockwise direction. Negative radius forces the rope to leave in clockwise direction (cartesian rule). | ### g2.ground(pts, [closed], [args]) ⇒ object Polygon ground. **Kind**: instance method of [g2](#g2) **Returns**: object - this | Param | Type | Default | Description | | --- | --- | --- | --- | | pts | array | | Array of points | | [closed] | bool | false | Closed polygon. | | [args] | object | | Arguments object. | | [args.h] | float | 4 | Ground shade line width. | | [args.pos] | string | "right" | Ground shade position ["left","right"]. | ### g2.load(pts, spacing, [style]) ⇒ object Polygonial line load. The first and last point define the base line onto which the load is acting orthogonal. **Kind**: instance method of [g2](#g2) **Returns**: object - this | Param | Type | Description | | --- | --- | --- | | pts | array | Array of load contour points. | | spacing | real | Spacing of the vectors drawn as a positive real number, interprete as
* spacing < 1: spacing = 1/m with a partition of m.
* spacing > 1: length of spacing. | | [style] | object | Arguments object. | ### g2.State : object Mechanical style values. Not really meant to get overwritten. But if you actually want, proceed.
Theses styles can be referenced using the comfortable '@' syntax. **Kind**: static namespace of [g2](#g2) **Properties** | Name | Type | Default | Description | | --- | --- | --- | --- | | State | object | | `g2` state namespace. | | State.nodcolor | string | "#333" | node color. | | State.nodfill | string | "#dedede" | node fill color. | | State.nodfill2 | string | "#aeaeae" | alternate node fill color, somewhat darker. | | State.linkcolor | string | "#666" | link color. | | State.linkfill | string | "rgba(200,200,200,0.5)" | link fill color, semi-transparent. | | State.dimcolor | string | "darkslategray" | dimension color. | | State.solid | array | [] | solid line style. | | State.dash | array | [15,10] | dashed line style. | | State.dot | array | [4,4] | dotted line style. | | State.dashdot | array | [25,6.5,2,6.5] | dashdotted line style. | | State.labelOffset | number | 5 | default label offset distance. | | State.labelSignificantDigits | number | 3 | default label's significant digits after floating point. | ### g2.symbol : object Mechanical symbols and line markers as individual `g2` instances. Use them via `use` command.
**Kind**: static namespace of [g2](#g2) **Properties** | Name | Type | Description | | --- | --- | --- | | symbol | object | `g2` symbol namespace. | | symbol.origin | object | origin symbol. | | symbol.nod | object | node symbol. | | symbol.dblnod | object | double-node symbol. | | symbol.nodfix | object | fixed node / bearing symbol. | | symbol.dblnodfix | object | fixed double-node / bearing symbol. | | symbol.nodflt | object | floating node / bearing symbol. | | symbol.dblnodfix | object | floating double-node / bearing symbol. | | symbol.gnd | object | ground node symbol. | | symbol.pol | object | pole symbol. | | symbol.dot | object | dot marker symbol. | | symbol.sqr | object | square marker symbol. | | symbol.tilde | object | tilde marker symbol. | | symbol.arrow | object | arrow marker symbol. | | symbol.tick | object | tick marker symbol. | | symbol.arrowtick | object | arrow-tick marker symbol. |