@svizzle/geometry/2DNetwork

Methods

(static) linkVector(link) → {object}

Source:
Since:
  • 0.1.0

Creates a vector from a link

Example
> linkVector({
	source: {x: 1, y: 1},
	target: {x: 2, y: 2}
})
{
	x: 1,
	y: 1,
	length: 1.4142135623730951,
	versor: {x: 0.7071067811865475, y: 0.7071067811865475}
}
Parameters:
Name Type Description
link object

The edge: {source: {x, y}, target: {x, y}}

Returns:
  • An object {x, y, length, versor} representing a vector with its features
Type
object

(static) makeLinkVector(link) → {object}

Source:
Since:
  • 0.1.0

Creates a vector from a link, considering the nodes radiuses. To get the vector between centers, don't pass radiuses or zero them

Example
> makeLinkVector({
	source: {x: 1, y: 1, radius: 0.1},
	target: {x: 2, y: 2, radius: 0.1}
})
{
	x1: 1.07071067811865475, // 1 + 0.1 * 0.707
	y1: 1.07071067811865475,
	x2: 1.9292893218813452,  // 2 - 0.1 * 0.707
	y2: 1.9292893218813452
}
Parameters:
Name Type Description
link object

The edge: {source: {x, y, radius}, target: {x, y, radius}}

Returns:
  • An object {x1, y1, x2, y2} representing origin and tip points
Type
object