update
This commit is contained in:
@@ -4,6 +4,14 @@ namespace RobotApp.Common.Shares;
|
||||
|
||||
public static class MathExtensions
|
||||
{
|
||||
public static double NormalizeAngle(double angle)
|
||||
{
|
||||
angle = angle % 360;
|
||||
if (angle > 180) angle -= 360;
|
||||
else if (angle < -180) angle += 360;
|
||||
return angle;
|
||||
}
|
||||
|
||||
public static (double x, double y) CurveDegreeTwo(double t, double x1, double y1, double controlPointX, double controlPointY, double x2, double y2)
|
||||
{
|
||||
var x = (1 - t) * (1 - t) * x1 + 2 * t * (1 - t) * controlPointX + t * t * x2;
|
||||
@@ -77,4 +85,21 @@ public static class MathExtensions
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
public static double GetVectorAngle(double originNodeX, double originNodeY, double vector1X, double vector1Y, double vector2X, double vector2Y)
|
||||
{
|
||||
double BA_x = vector1X - originNodeX;
|
||||
double BA_y = vector1Y - originNodeY;
|
||||
double BC_x = vector2X - originNodeX;
|
||||
double BC_y = vector2Y - originNodeY;
|
||||
// Tính độ dài của các vector AB và BC
|
||||
double lengthAB = Math.Sqrt(BA_x * BA_x + BA_y * BA_y);
|
||||
double lengthBC = Math.Sqrt(BC_x * BC_x + BC_y * BC_y);
|
||||
// Tính tích vô hướng của AB và BC
|
||||
double dotProduct = BA_x * BC_x + BA_y * BC_y;
|
||||
if (lengthAB * lengthBC == 0) return 0;
|
||||
if (dotProduct / (lengthAB * lengthBC) > 1) return 0;
|
||||
if (dotProduct / (lengthAB * lengthBC) < -1) return 180;
|
||||
return Math.Acos(dotProduct / (lengthAB * lengthBC)) * (180.0 / Math.PI);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user