Graphite icon indicating copy to clipboard operation
Graphite copied to clipboard

Perspective skew on the transform cage

Open Keavon opened this issue 2 years ago • 9 comments

This lets the user skew the perspective of the rectangle with some arbitrary affine transform. The user can access this by dragging a corner of the transform cage while holding Ctrl.

Keavon avatar Jun 02 '23 07:06 Keavon

I do not believe this is possible with an Affine2.

You wish to allow the user to transform a unit square with vertices at (0,0) (1,0) (1,1) (0,1) into any arbitrary quadrilateral.

An affine transformation represented by a translation (which must be used to transform the point at the origin ). There is also a two by two matrix. The first column of the matrix (i) is the result of the transform of the vector (1,0) and the second column (j) is the result of the transformation of the vector (0,1). The transformation of the vector (1,1) is always equal to i+j (the two columns added together).

A visual proof that there is often no linear transformation to any arbitary points: image Note that during a linear transformation, the thin black grid lines must remain parallel and evenly spaced.

0HyperCube avatar Jun 03 '23 16:06 0HyperCube

I think we can mandate no ~~convex~~ concave angles, so the right image would be clamped to forming a triangle. Does that work with an affine transform?

Keavon avatar Jun 03 '23 19:06 Keavon

Only sometimes, see the following stack exchange answer: https://math.stackexchange.com/a/614375

0HyperCube avatar Jun 05 '23 18:06 0HyperCube

Is an affine transform a subset of a perspective transform? Should we consider switching our transforms to perspective transforms?

Keavon avatar Jun 05 '23 19:06 Keavon

Our current 2D affine transformations are a subset of perspective transformations.

0HyperCube avatar Jun 17 '23 19:06 0HyperCube

Ok, that's helpful to know. Are you aware of any impediments to switching to the superset, and do you know how much effort (and affected code) would be involved in such a refactor?

Keavon avatar Jun 17 '23 20:06 Keavon

@Keavon Search for DAffine2 - you will find 308 occurrences in 50 files.

0HyperCube avatar Dec 20 '23 16:12 0HyperCube

@Keavon another issue is that we frequently transform a bézier curve by an affine transform to be another bézier curve. However it is not possible with a perspective transform unless a more general NURBS is used as output.

0HyperCube avatar Jun 02 '24 14:06 0HyperCube

That's an interesting challenge. From a bit of research it looks like rational Bezier curves are needed to represent perspective transforms, which is a special case of a regular Bezier curve. And rational Beziers are special cases of NURBS (see here). So I wonder if we want to just support all of NURBS and have a hierarchy of data complexity/purity, then build Bezier-rs functionality to approximate NURBS as Bezier segments similar to some of the existing algorithms it already has involving approximations like reduce, offset, and arcs.

There's this video on projective geometry which gives a taste of homogeneous coordinates that I found helpful in starting to understand these concepts:

  • https://youtube.com/watch?v=XXzhqStLG-4
  • (And I also recommend watching this video, perhaps even before that one: https://www.youtube.com/watch?v=YDanHdjPJVs )

Further reading:

  • https://ftp.unpad.ac.id/ctan/macros/latex/contrib/lapdf/bezinfo.pdf (section 1.4)
  • https://www.rose-hulman.edu/~finn/CCLI/Notes/day22_23.pdf
  • https://www.rose-hulman.edu/~finn/CCLI/Notes/day21.pdf

Keavon avatar Jun 05 '24 01:06 Keavon