Answer the question
In order to leave comments, you need to log in
How to rotate a line to a coordinate system?
Good evening! I don't understand what the error is when turning a straight line on a coordinate system. Given 2 points of a straight line, found that the angle of inclination of a straight line is calculated by the formula: (y2-y1) / (x2-x1). According to the resulting value, I take tg and convert it to radians.
private static double GetAngleOfInclination(Point a, Point b)
{
var angleOfInclination = (double)(b.Y - a.Y) / (b.X - a.X);
angleOfInclination = Math.Tan(angleOfInclination);
return GetRadiance(angleOfInclination);
}
private static double GetXPointWithInclination(double pointX, double pointY, double angleOfInclination)
{
var x = pointX * Math.Cos(angleOfInclination) + pointY * Math.Sin(angleOfInclination);
return Math.Round(x, 1);
}
private static double GetYPointWithInclination(double pointX, double pointY, double angleOfInclination)
{
var y = -pointX * Math.Sin(angleOfInclination) + pointY * Math.Cos(angleOfInclination);
return Math.Round(y, 1);
}
Answer the question
In order to leave comments, you need to log in
You need to take the arc tangent from the ratio, not the tangent (y2-y1) / (x2-x1).
> take tg and convert to radians
First, you need the arc tangent.
Secondly, it will already be in radians.
Well, and thirdly, it is not necessary at all. You have two points and formulas to translate them into a new coordinate system. You just need to translate them there and you will have new coordinates of these points that describe the line.
Expected result: for the line specified by the points to lie on one of the axes, therefore, X or Y must become zero for the points.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question