g2

g2 ⇒ g2

Mechanical extensions. (Requires cartesian coordinates)

Kind: global typedef
Requires: module:g2.core.js, module:g2.ext.js
Author: Stefan Goessner
License: MIT License

g2.slider() ⇒ object

Draw slider.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object slider arguments object.

Properties

Name Type Default Description
x number   start x coordinate.
y number   start y coordinate.
[b] number 32 slider breadth.
[h] number 16 slider height.
[w] number 0 rotation.

Example

g2().slider({x:150,y:75,w:Math.PI/4,b:64,h:32})

g2.spring() ⇒ object

Draw linear spring

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object linear spring arguments object.

Properties

Name Type Default Description
x1 number   start x coordinate.
y1 number   start y coordinate.
x2 number   end x coordinate.
y2 number   end y coordinate.
[h] number 16 Spring height.

Example

g2().spring({x1:50,y1:100,x2:200,y2:75})

g2.damper() ⇒ object

Draw line with centered square damper symbol.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object damper arguments object.

Properties

Name Type Default Description
x1 number   start x coordinate.
y1 number   start y coordinate.
x2 number   end x coordinate.
y2 number   end y coordinate.
[h] number 16 damper height. * g2().damper({x1:60,y1:120,x2:200,y2:75})

Draw polygonial link.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object link arguments object.

Properties

Name Type Default Description
pts Array.<object> | Array.<Array.<number>> | Array.<number>   array of points.
[closed] bool false closed link.
x number   start x coordinate.
y number   start y coordinate.
[w] number 0 angle.

Example

let A = {x:50,y:25},B = {x:150,y:25},
    C = {x:50,y:75}, D = {x:100,y:75},
    E = {x:50,y:125};
g2().view({cartesian:true})
    .link({pts:[A,B,E,A,D,C]})

g2.link2() ⇒ object

Draw alternate glossy polygonial link.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object link2 arguments object.

Properties

Name Type Default Description
pts Array.<object> | Array.<Array.<number>> | Array.<number>   array of points.
[closed] bool false closed link.
x number   start x coordinate.
y number   start y coordinate.
[w] number 0 angle.

Example

let A = {x:50,y:25},B = {x:150,y:25},
    C = {x:50,y:75}, D = {x:100,y:75},
    E = {x:50,y:125};
g2().view({cartesian:true})
    .link({pts:[A,B,E,A,D,C]})

g2.beam() ⇒ object

Draw polygonial beam.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object beam arguments object.

Properties

Name Type Default Description
pts Array.<object> | Array.<Array.<number>> | Array.<number>   array of points.
x number   start x coordinate.
y number   start y coordinate.
[w] number 0 angle.

Example

g2().view({cartesian})
    .beam({pts:[[200,125][50,125][50,50][200,50]]})

g2.beam2() ⇒ object

Draw alternate glossy polygonial beam.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object beam2 arguments object.

Properties

Name Type Default Description
pts Array.<object> | Array.<Array.<number>> | Array.<number>   array of points.
x number   start x coordinate.
y number   start y coordinate.
[w] number 0 angle.

Example

g2().view({cartesian})
    .beam2({pts:[[200,125][50,125][50,50][200,50]]})

g2.bar() ⇒ object

Draw bar.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object bar arguments object.

Properties

Name Type Description
x1 number start x coordinate.
y1 number start y coordinate.
x2 number end x coordinate.
y2 number end y coordinate.

Example

g2().bar({x1:50,y1:20,x2:250,y2:120})

g2.bar2() ⇒ object

Draw alternate glossy bar.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object bar2 arguments object.

Properties

Name Type Description
x1 number start x coordinate.
y1 number start y coordinate.
x2 number end x coordinate.
y2 number end y coordinate.

Example

g2().bar2({x1:50,y1:20,x2:250,y2:120})

g2.pulley() ⇒ object

Draw pulley.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object pulley arguments object.

Properties

Name Type Description
x number x-value center.
y number y-value center.
r number radius.
w number angle.

Example

g2().pulley({x:100,y:75,r:50})

g2.pulley2() ⇒ object

Draw alternate pulley.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object pulley2 arguments object.

Properties

Name Type Description
x number x-value center.
y number y-value center.
r number radius.
w number angle.

Example

g2().pulley2({x:50,y:30,r:25})

g2.rope() ⇒ object

Draw rope. Amount of pulley radii must be greater than 10 units. They are forced to zero otherwise.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object rope arguments object.

Properties

Name Type Description
p1 object | number starting point or Coordinate.
p2 object | number end point or Coordinate.
r number radius of parent element.

Example

let A = {x:50,y:30}, B = {x:200,y:75};
g2().view({cartesian:true})
    .pulley({...A,r:20})
    .pulley2({...B,r:40})
    .rope({p1:A,r1:20,p2:B,r2:40})

g2.ground() ⇒ object

Polygon ground.

Kind: instance method of g2
Returns: object - g2

Param Type Description
  object ground arguments object.

Properties

Name Type Default Description
pts Array.<object> | Array.<Array.<number>> | Array.<number>   array of points.
[closed] bool false closed polygon.
[h] number 4 ground shade line width.
[pos] string "right" ground shade position [‘left’,’right’].

Example

g2().ground({pts:[25,25,25,75,75,75,75,25,125,25],pos:'left'})

g2.load() ⇒ 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
Returns: object - g2

Param Type Description
  object load arguments object.

Properties

Name Type Description
pts Array.<object> | Array.<Array.<number>> | Array.<number> array of points.
w number angle of vectors.
spacing number 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.