I'm creating a C# code which draws a path. The problem is I don't have coordinates of the path vertices. Instead, I know length of each segment and angle between adjacent segments.
Assuming the first point of the path has coordinates (0;0) I want to draw the path calculating every vertex from given segment length and angle. I'm not good in trigonometry, but I hope it is possible.
I try to cycle through the collection of segments to calculate next point coordinate at each step. So at any step I have the following data:
Given first segment AB with length L1, next segment BC with length L2, an angle ABC between segments AB and BC. Coordinates of points A and B are know, because are evaluated on the previous step.
If it is possible, how to calculate coordinates of the point C from the given data?
This is an example of a collection of segments:
public ObservableCollection<SequenceStep> Sequence { get; set; }
where:
public class SequenceStep
{
public double Length { get; set; }
public double Angle { get; set; }
}
I cycle through the sequence like this:
for (var i = 1; i < Sequence.Count; i++)
{
var sequenceStep = Sequence[i];
var angleInRadians = Math.PI * sequenceStep.Angle / 180.0;
// Calculate next point coordinates from (0,0)
var x = Math.Cos(angleInRadians) * sequenceStep.Length;
var y = Math.Sin(angleInRadians) * sequenceStep.Length;
}
// I start from segment[1], because segment[0] has points (0,0) and (segment[0].Length, 0).
But evaluated coordinates are only for the angle between point and axis X. I think I need to rotate those x,y coordinates, to correspond with orientation of the segment BC. But I always get wrong coordinates.
I would appreciate any help, a C# method or a set formulas.