Graphics Reference
In-Depth Information
B.3
Vector Examples
This section contains a number of examples of using vectors for geometric com-
putations. These map fairly directly into code when you use a library that has
functions or operators for things such as vector addition.
B.3.1
Implicit Curves in 2D
An implicit curve in 2D is a real-valued function
f
(
x
,
y
)
that divides the plane into
positive and negative regions. The boundary where
f
(
x
,
y
)=
0 is the curve. The
reason it is called “implicit” is that
f
can tell you whether a given point is on
the curve, but it does not tell you explicitly which points are on the curve. For
example, the circle centered at the origin of radius 1 is often written
()
x
2
y
2
+
=
1
.
That is not quite in the form
f
(
x
,
y
)=
0. We can subtract 1 from both sides to get
x
2
y
2
+
−
1
=
0
.
For points inside the circle,
x
2
y
2
0. For points outside the circle,
x
2
+
−
1
<
+
y
2
−
0.
Note that for any implicit function
f
1
>
0, the curve is unchanged if we
multiply it by a non-zero constant. For example, a unit circle is also described by
(
x
,
y
)=
2
x
2
2
y
2
+
−
2
=
0
and
2
x
2
2
y
2
−
−
+
2
=
0
.
The constant can change how positive or negative points off the circle are, and in
the case of a negative constant, it reverses which regions off the curve are positive
versus those that are negative. However, points on the curve remain zero.
A more general circle with radius
R
and center
C
is given by:
2
2
R
2
f
(
x
,
y
)=(
x
−
x
c
)
+(
y
−
y
c
)
−
=
0
The same principles of implicit equations apply: points where
f
(
x
,
y
)=
0areon
the curve, and points where
f
0 are not on the curve. Both in math and in
code, vectors give a more compact and less error-prone way to describe a circle:
(
x
,
y
)
=
R
2
(
P
−
C
)
·
(
P
−
C
)
−
=
0
.
Search WWH ::
Custom Search