Stumped by a problem that would have been easy for me in high school.
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 topleft to bottomright and from bottomleft to topright. 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
Re: Stumped by a problem that would have been easy for me in high school.
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...
Oops, didn't mean to mark it Solved.
Yeah, I'm still looking for a solution.
KeeganT
Re: Stumped by a problem that would have been easy for me in high school.
FYI: I have removed the "Solved" tag.
Dan
Re: Stumped by a problem that would have been easy for me in high school.
Hello, KeeganT!
Quote:
Suppose I have a rectangle, $w$ wide and $h$ tall.
Consider the diagonals going from topleft to bottomright and from bottomleft to topright.
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.
Code:
(w/2,h/2)  (w/2,h/2)
B *      +      * A
 .  . 
 .  . 
  +      +      +  
 .  . 
 .  . 
C *      +      * D
(w/2,h/2)  (w/2,h/2)

Diagonal $AC$ has the equation: $\; y = \tfrac{h}{w}x \quad\Rightarrow\quad hx  wy \:=\:0$
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.