Reputation: 359
I'm trying to find a simple solution for getting a set of points on arc.
My program runs with c#, wpf and telerik.
In my program I have a map, with camera's FOV (field of view) on it.
Till now I had triangular fov , but client wants it with an arc.
I have a center point (camera's origin) with two points representing left and right FOV boundaries.
The points are represented as coordinates.
A draw of what I wish to accomplish
My goal is to gather a set of points on top of the arc which connects the FOV limits (left and right points), which then I'll send to telerik to draw.
some remarks:
Does c# and Math class has some tools which can help? I tried calculating it by myself, but it got too complicated for me to handle.
Thanks, Naor.
Upvotes: 1
Views: 1528
Reputation: 128062
You could use a Path
control with an appropriate PathGeometry
that contains an ArcSegment
.
In the example below, (100,100)
is the center point and (50,50)
and (150,50)
are the start and end points of the arc. Note that the arc is a segment of an ellipse, where the Size
property of the ArcSegment specifies the ellipse radii. Here it is a circle of radius 50*sqrt(2)
.
<Path Stroke="Black">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="100,100" IsClosed="True">
<LineSegment Point="50,50"/>
<ArcSegment Point="150,50" Size="70.7,70.7" SweepDirection="Clockwise"/>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
Or shorter:
<Path Stroke="Black" Data="M100,100 L50,50 A70.7,70.7 0 0 1 150,50Z" />
Assuming that your view model has four properties that describe the arc figure like
public Point Center { get; private set; } = new Point(100, 100);
public Point Start { get; private set; } = new Point(50, 50);
public Point End { get; private set; } = new Point(150, 50);
public Size Size { get; private set; } = new Size(70.7, 70.7);
you could write the XAML with Bindings like this:
<PathFigure StartPoint="{Binding Center}" IsClosed="True">
<LineSegment Point="{Binding Start}"/>
<ArcSegment Point="{Binding End}" Size="{Binding Size}" SweepDirection="Clockwise"/>
</PathFigure>
You can of course also create such a geometry in code behind.
Upvotes: 1