P
P
pwN112014-04-09 21:09:24
Canvas
pwN11, 2014-04-09 21:09:24

How to draw function graph using WPF using Canvas?

How to draw a function graph using WPF using Canvas?
You can link to examples or at least where to dig. Thanks to all.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sumor, 2014-04-11
@pwN11

The values ​​of the function are calculated with a certain step, then objects of the LineSegment type are added to the PathFigure collection (if it is not necessary to interpolate) or another inheritor of the PathSegment class corresponding to the required interpolation. For example, bezier curves of the third order - PolyBezierSegment.
Point specifies the new point to continue the graph to.
When calculating, you need to take into account that the Canvas has the origin in the upper left corner, and the Y axis is directed down. Either consider the next point when calculating, or use Canvas transformations.
Should be like this

<Canvas>
    <Path Stroke="Black" StrokeThickness="1">
        <Path.Data>
            <PathGeometry>
                <PathFigure>
                    <LineSegment Point="100,100"/>
                    <LineSegment Point="150,120"/>      
                    <PolyBezierSegment Points="170,120 190,100 200,160 220,140"/>
                </PathFigure>
            </PathGeometry>
        </Path.Data>
    </Path>    
</Canvas>

M
Mikhail Doshevsky, 2014-04-11
@MikhailD

A simple option: calculate the value of the function at several points and connect with segments. The more dots, the smoother the graph will be.
The option is more complicated: use interpolation
Choose a method, depending on your task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question