createFromControlVectors2 static method
AffineTransformation?
createFromControlVectors2(
- Coordinate src0,
- Coordinate src1,
- Coordinate dest0,
- Coordinate dest1,
- Creates an AffineTransformation defined by a pair of control vectors. A
- control vector consists of a source point and a destination point, which is
- the image of the source point under the desired transformation. The
- computed transformation is a combination of one or more of a uniform scale,
- a rotation, and a translation (i.e. there is no shear component and no
- reflection)
- @param src0
- @param src1
- @param dest0
- @param dest1
- @return the computed transformation, or null if the control vectors do not determine a well-defined transformation
- control vector consists of a source point and a destination point, which is
Implementation
static AffineTransformation? createFromControlVectors2(
Coordinate src0, Coordinate src1, Coordinate dest0, Coordinate dest1) {
Coordinate rotPt = new Coordinate(dest1.x - dest0.x, dest1.y - dest0.y);
double ang = Angle.angleBetweenOriented(src1, src0, rotPt);
double srcDist = src1.distance(src0);
double destDist = dest1.distance(dest0);
if (srcDist == 0.0) return null;
double scale = destDist / srcDist;
AffineTransformation trans =
AffineTransformation.translationInstance(-src0.x, -src0.y);
trans.rotate(ang);
trans.scale(scale, scale);
trans.translate(dest0.x, dest0.y);
return trans;
}