# How do I perform a perspective transform on a straight line?

I'm trying to make a software renderer, but I want to avoid creating extra triangles with clipping. For this I want to transform lines which compose triangles, instead of individual points. However I'm not sure how to do a perspective transformation on a line equation.

• How is the line represented? Oct 10 at 20:58
• Doesn't matter, so long I can easily flatten it to XY and check if a point(pixel) is on its left or right side. That is, the representation should contain the direction of the line(though I could just use an extra bool if needed). Could be a pair of XY coordinates, implicitly at z=0, z=1; or a pair of ax+by=c; anything thats "easy to work" with. Oct 11 at 0:43

There are many methods you could use to go about doing this, here is one using the parametric form of a line which is: $$L(t) = p+t\vec v$$ Where $$p$$ is a point on the line and would be stored as a 4 component vector $$p = \{x,y,z,1\}$$ and $$\vec v$$ is a vector that would be stored as a 4 components $$\vec v = \{x,y,z,0\}$$
The point can be chosen as one of the ends of the line (it doesn't matter which just be consistent), and the vector is computed just like you would expect. IE if the line has the two end points $$a$$ and $$b$$ and the $$a$$ is chosen as the start, then the vector is computed as $$b-a$$.
Do not normalize the vector and just vary $$t$$ between 0 and 1 for every line. Though you may want to calculate the magnitude of the vector (which corresponds to the length of the line) to determine how many points on the line you want to compute WRT the resolution of the image.