I've noticed you have marked this as solved. Would you like to post your solution? Someone who has a similar problem might find it useful...
Yep. My skills are far deteriorated, so much so that the problem I'm about to describe I'd have cringed at needed help with way back when. Anyways.....
Suppose I have a rectangle, $w wide and $h tall. Consider the diagonals going from top-left to bottom-right and from bottom-left to top-right. I will be cycling through each pixel, and I want to figure out for each one what is the distance from that pixel to the nearer diagonal.
I've tried to work it out on paper but ended up getting frustrated twice.
Can anyone help?
THX
KeeganT
Hello, KeeganT!
Suppose I have a rectangle, $w$ wide and $h$ tall.
Consider the diagonals going from top-left to bottom-right and from bottom-left to top-right.
I will be cycling through each pixel, and I want to figure out for each one
what is the distance from that pixel to the nearer diagonal.
I placed the rectangle on a coordinate system.
Diagonal $AC$ has the equation: $\; y = \tfrac{h}{w}x \quad\Rightarrow\quad hx - wy \:=\:0$Code:(-w/2,h/2) | (w/2,h/2) B * - - - - - + - - - - - * A | . | . | | . | . | - - + - - - - - + - - - - - + - - | . | . | | . | . | C * - - - - - + - - - - - * D (-w/2,-h/2) | (w/2,-h/2) |
Diagonal $BD$ has the equation: $\;y = \text{-}\tfrac{h}{w}x \quad\Rightarrow\quad hx + wy \:=\:0$
If the point $P(x_1,y_1)$ is in Quadrant 1 or 3, it is closer to $AC.$
The distance is: $\;d \:=\:\dfrac{|hx_1 - wy_1|}{\sqrt{h^2+w^2}} $
If the point $P(x_1,y_1)$ is in Quadrant 2 or 4, it is closer to $BD.$
The distance is: $\:d \:=\:\dfrac{|hx_1+wy_1|}{\sqrt{h^2+w^2}}$
I hope this helps.