79311863

Date: 2024-12-27 13:06:49
Score: 1.5
Natty:
Report link

The gradient (normal) vector describes the direction of the gradient. The gradient itself consists of the parallel colored lines in directions orthogonal to the gradient vector.

The transformed normal is the normal of the normal of the original gradient. This sounds a bit vague. To make it more precise: The Java code below exactly does this.

/**
 * Transform the x1, y1, x2, y2 coordinates of the normal vector of a linearGradient
 * @param transform The transform to apply
 * @param coords The gradient normal vector to transform: [ x1, y1, x2, y2 ]
 * @return The transformed gradient normal vector in the same format as coords
 */
static float[] transformCoords(
        AffineTransform transform,
        float[] coords ) {

    final float dx= coords[2]- coords[0];
    final float dy= coords[3]- coords[1];

    final float [] rotated = new float[] {
            coords[0],
            coords[1],
            coords[0] - dy,
            coords[1] + dx
    };

    transform.transform( rotated, 0, rotated, 0, 2 );

    final float d_x= rotated[2]- rotated[0];
    final float d_y= rotated[3]- rotated[1];

    double f = Math.hypot( dx, dy ) / Math.hypot( d_x, d_y );
    double fac= transform.getDeterminant()* f* f;

    return new float[] {
            rotated[0],
            rotated[1],
            rotated[0] + (float) (fac * d_y),
            rotated[1] - (float) (fac * d_x)
    };
}
Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • User mentioned (1): @param
  • User mentioned (0): @param
  • User mentioned (0): @return
  • Low reputation (1):
Posted by: Mark de Does