public Vertex(PdfPath.Line leftEdge, PdfPath.Line rightEdge) { AngleBisectorSlope = double.NaN; AngleBisectorIntercept = double.NaN; AngleBisector = double.NaN; if (leftEdge.To.Equals(rightEdge.From)) { IsValid = true; } LeftEdge = leftEdge; RightEdge = rightEdge; if (IsValid) { AngleBisector = Angle(LeftEdge, RightEdge) / 2.0; // Rotate var deltaX = (double)(LeftEdge.From.X - LeftEdge.To.X); var deltaY = (double)(LeftEdge.From.Y - LeftEdge.To.Y); var cos = Math.Cos(AngleBisector); var sin = Math.Sin(AngleBisector); var newX = cos * deltaX - sin * deltaY + (double)LeftEdge.To.X; var newY = sin * deltaX + cos * deltaY + (double)LeftEdge.To.Y; AngleBisectorRay = new PdfPath.Line(LeftEdge.To, new PdfPoint(newX, newY)); AngleBisectorSlope = (double)((AngleBisectorRay.To.Y - AngleBisectorRay.From.Y) / (AngleBisectorRay.To.X - AngleBisectorRay.From.X)); AngleBisectorIntercept = (double)AngleBisectorRay.To.Y - AngleBisectorSlope * (double)AngleBisectorRay.To.X; } }
public static double DistancePointToLine(PdfPath.Line line, PdfPoint point) { var denominator = Math.Sqrt((double)(line.To.Y - line.From.Y) * (double)(line.To.Y - line.From.Y) + (double)(line.To.X - line.From.X) * (double)(line.To.X - line.From.X)); var numerator = (double)Math.Abs((line.To.Y - line.From.Y) * point.X - (line.To.X - line.From.X) * point.Y + line.To.X * line.From.Y - line.To.Y * line.From.X); return(numerator / denominator); }
private double Angle(PdfPath.Line line1, PdfPath.Line line2) { var angle = (Math.Atan2((double)(line1.From.Y - line1.To.Y), (double)(line1.From.X - line1.To.X)) - Math.Atan2((double)(line2.From.Y - line2.To.Y), (double)(line2.From.X - line2.To.X))); angle = Math.Sign(angle) * Math.PI - angle; if (angle < 0) { angle += 2 * Math.PI; } return(angle); }