Discussion:
Graph Plotter
(too old to reply)
TFM
2007-07-05 03:59:14 UTC
Permalink
Hi,

I'm on to developing a 2d/3d graph plotter using managed directx. I
just went through the beginners tutorial and concepts of vertex and
vertex buffers and the primitive type available in directx.

Now I'm a bit uncertain as how to proceed e.g. I want a the graph of
Sin(x) so using what primitives would I be able to create that ? as in
a sin graph is basically curves so where would lines and triangles fit
in here.

Also if anyone knows any link to mathematical plotters or related
sample code do let me know.

Thanks
legalize+ (Richard [Microsoft Direct3D MVP])
2007-07-05 15:59:28 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by TFM
Now I'm a bit uncertain as how to proceed e.g. I want a the graph of
Sin(x) so using what primitives would I be able to create that ? as in
a sin graph is basically curves so where would lines and triangles fit
in here.
Its more of an algorithm question than a DirectX question, but here
goes...

You have to reduce anything you want to draw into the primitives that
are supported by D3D. So if you want to draw a smooth plot, you have
to reduce that to line segments that are sufficiently small as to
reproduce the level of smoothness of the underlying object. This is
the "modeling" part of drawing a graph.

There are basically two methods: brute force subdivision and error
metric based subdivision. With brute force you just subdivide the
curve evenly into equally spaced line segments such that the line
segment length is sufficiently small to capture the sharpest bend in
the visible portion of the curve.

With an error-based metric, you try to compute the error between the
line segment approximating the curve and the real curve. When the
error is too high, then you adaptively subdivide that segment into two
or more segments until the error is within some tolerance. The De
Casteljau subdivision algorithm (google it) is one such example for
Bezier curves.

Generally the error-based metric is only useful in situations where
you have a way of analytically computing the error. This isn't always
possible, but in your case it should be possible.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
Loading...