Graphics Reference
In-Depth Information
2 , which is the squared
distance between P and C . Geometrically, that is a nice equation: if the squared
distance between and C is the square of the radius, then P is on the circle.
The familiar slope-intercept equation of the line in 2D, y
2
Note that the dot product just expands to
(
x
x c )
+(
y
y c )
=
mx
+
b , can also be
made into an implicit equation: y
0.
Unfortunately, neither of these equations is well-suited for computation, as m can
be infinite for perfectly valid lines—vertical ones. As we are allowed to multiply
an implicit equation by any non-zero value, we can get rid of this degeneracy.
Usually, a line in a graphics program is specified by two points C and D .The
slope is
mx
b
=
0, or equally valid
y
+
mx
+
b
=
y d
y c
x c ,
with the sign depending on which point is to the right of the other. To eliminate a
possible zero denominator we can multiply through by its value:
±
x d
f
(
x
,
y
)=(
x d
x c )
y
(
y d
y c )
x
(
y d
y c )
b
=
0
.
We can solve for
(
y d
y c )
b by noting that because C and D are on the line,
f
(
x c ,
y c )=
f
(
x d ,
y d )=
0. Plugging in c:
f
(
x
,
y
)=(
x d
x c )
y c (
y d
y c )
x c (
y d
y c )
b
=
0
,
so
(
y d
y c )
b
=(
y d
y c )
x c (
x d
x c )
y c =
x c y d
y c x d .
So our final equation for the line is
y c x d .
This equation can also be derived from a geometric observation. If we have a
vector that is perpendicular to a vector parallel to the line, the dot product of that
vector and the vector between any two points on the line is zero. This “normal”
vector to the line can be derived from the observation that any vector
f
(
x
,
y
)=(
y c
y d )
x
+(
x d
x c )
y
+
x c y d
(
x
,
y
)
is per-
pendicular to vector
(
y
,
x
)
. This can be verified by noting that their dot product
is zero.
The vector D
C is parallel to the line. The vector N
=(
y c
y d ,
x d
x c )
is
perpendicular to D
C . If a point P is on the line, then
N
· (
P
C
)=
0
.
Expanding this gives
(
y c
y d ,
x d
x c )
cot
(
x
x c ,
y
y c )=
0
,
which expands to
f
(
x
,
y
)=(
y c
y d )
x
+(
x d
x c )
y
+
x c y d
y c x d .
Search WWH ::




Custom Search