MATSIM
Static Public Member Functions | Static Private Member Functions | List of all members
org.matsim.vis.vecmathutils.VectorUtils Class Reference

Static Public Member Functions

static Tuple< Point2D.Double, Point2D.Double > scaleVector (final Point2D.Double start, final Point2D.Double end, double scaleFactor)
 
static Tuple< Point2D.Double, Point2D.Double > scaleVectorStart (final Point2D.Double start, final Point2D.Double end, double scaleFactor)
 
static Tuple< Point2D.Double, Point2D.Double > scaleVectorEnd (final Point2D.Double start, final Point2D.Double end, double scaleFactor)
 

Static Private Member Functions

static Tuple< Point2D.Double, Point2D.Double > calculateScaledVector (final Point2D.Double start, final Point2D.Double end, double scaleFactor)
 

Detailed Description

Util class containing stateless vecmath utility methods frequently needed for visualization code.

Author
dgrether
tthunig

Definition at line 32 of file VectorUtils.java.

Member Function Documentation

◆ scaleVector()

static Tuple<Point2D.Double, Point2D.Double> org.matsim.vis.vecmathutils.VectorUtils.scaleVector ( final Point2D.Double  start,
final Point2D.Double  end,
double  scaleFactor 
)
static

Scales a vector given by start and end point by a factor. Changes both - start and end coordinate of the vector.

Parameters
scaleFactora scale factor in [0..1]
Returns
a tuple with the scaled start point as first and the end point as second entry

Definition at line 40 of file VectorUtils.java.

References org.matsim.vis.vecmathutils.VectorUtils.calculateScaledVector().

Referenced by org.matsim.lanes.VisLaneModelBuilder.createVisLinkLanes().

41  {
42 
43  return calculateScaledVector(start, end, scaleFactor);
44  }
static Tuple< Point2D.Double, Point2D.Double > calculateScaledVector(final Point2D.Double start, final Point2D.Double end, double scaleFactor)
Here is the call graph for this function:

◆ scaleVectorStart()

static Tuple<Point2D.Double, Point2D.Double> org.matsim.vis.vecmathutils.VectorUtils.scaleVectorStart ( final Point2D.Double  start,
final Point2D.Double  end,
double  scaleFactor 
)
static

Scales a vector given by start and end point by a factor. Changes only the start coordinate of the vector.

Parameters
scaleFactora scale factor in [0..1]
Returns
a tuple with the scaled start point as first and the old end point as second entry
Deprecated:
not used yet

Definition at line 54 of file VectorUtils.java.

References org.matsim.vis.vecmathutils.VectorUtils.calculateScaledVector().

55  {
56 
57  Tuple<Point2D.Double, Point2D.Double> scaledVector = calculateScaledVector(start, end, scaleFactor);
58  return new Tuple<Point2D.Double, Point2D.Double>(scaledVector.getFirst(), end);
59  }
static Tuple< Point2D.Double, Point2D.Double > calculateScaledVector(final Point2D.Double start, final Point2D.Double end, double scaleFactor)
Here is the call graph for this function:

◆ scaleVectorEnd()

static Tuple<Point2D.Double, Point2D.Double> org.matsim.vis.vecmathutils.VectorUtils.scaleVectorEnd ( final Point2D.Double  start,
final Point2D.Double  end,
double  scaleFactor 
)
static

Scales a vector given by start and end point by a factor. Changes only the end coordinate of the vector.

Parameters
scaleFactora scale factor in [0..1]
Returns
a tuple with the old start point as first and the scaled end point as second entry
Deprecated:
not used yet

Definition at line 69 of file VectorUtils.java.

References org.matsim.vis.vecmathutils.VectorUtils.calculateScaledVector().

70  {
71 
72  Tuple<Point2D.Double, Point2D.Double> scaledVector = calculateScaledVector(start, end, scaleFactor);
73  return new Tuple<Point2D.Double, Point2D.Double>(start, scaledVector.getSecond());
74  }
static Tuple< Point2D.Double, Point2D.Double > calculateScaledVector(final Point2D.Double start, final Point2D.Double end, double scaleFactor)
Here is the call graph for this function:

◆ calculateScaledVector()

static Tuple<Point2D.Double, Point2D.Double> org.matsim.vis.vecmathutils.VectorUtils.calculateScaledVector ( final Point2D.Double  start,
final Point2D.Double  end,
double  scaleFactor 
)
staticprivate

Definition at line 77 of file VectorUtils.java.

Referenced by org.matsim.vis.vecmathutils.VectorUtils.scaleVector(), org.matsim.vis.vecmathutils.VectorUtils.scaleVectorEnd(), and org.matsim.vis.vecmathutils.VectorUtils.scaleVectorStart().

79  {
80  //norm
81  Point2D.Double.Double delta = new Point2D.Double.Double(end.x - start.x, end.y - start.y);
82  double length = Math.sqrt(Math.pow(delta.x, 2) + Math.pow(delta.y, 2));
83  Point2D.Double.Double deltaNorm = new Point2D.Double.Double(delta.x / length, delta.y / length);
84  //scale
85  double scaledLength = length * scaleFactor;
86  double offset = (length - scaledLength) / 2;
87  Point2D.Double scaledEnd = new Point2D.Double(start.x + ((length - offset) * deltaNorm.x), start.y
88  + ((length - offset) * deltaNorm.y));
89  Point2D.Double scaledStart = new Point2D.Double(start.x
90  + (offset * deltaNorm.x), start.y
91  + (offset * deltaNorm.y));
92  Tuple<Point2D.Double, Point2D.Double> scaledVector = new Tuple<Point2D.Double, Point2D.Double>(scaledStart, scaledEnd);
93  return scaledVector;
94  }

The documentation for this class was generated from the following file: