110,534
社区成员
发帖
与我相关
我的任务
分享
public struct Point
{
public double x;
public double y;
public double z;
}
public static class Angle
{
public static double[] getAllAngle(Point a, Point b, Point c)
{
double[] result = new double[3];
result[0] = getIntersectionAngle(b, c, a);
result[1] = getIntersectionAngle(a, c, b);
result[2] = getIntersectionAngle(a, b, c);
return result;
}
public static double getIntersectionAngle(Point a, Point b, Point Intersection)
{
Point tempPoint1 = new Point { x = Intersection.x - a.x, y = Intersection.y - a.y, z = Intersection.z - a.z };
Point tempPoint2 = new Point { x = Intersection.x - b.x, y = Intersection.y - b.y, z = Intersection.z - b.z };
double temp = tempPoint1.x * tempPoint2.x + tempPoint1.y * tempPoint2.y + tempPoint1.z * tempPoint2.z;
double temp2 = Math.Sqrt(Math.Pow(tempPoint1.x, 2) + Math.Pow(tempPoint1.y, 2) + Math.Pow(tempPoint1.z, 2));
double temp3 = Math.Sqrt(Math.Pow(tempPoint2.x, 2) + Math.Pow(tempPoint2.y, 2) + Math.Pow(tempPoint2.z, 2));
double tempCos = temp / (temp2 * temp3);
double result = Math.Acos(tempCos);
return Math.Round(((180 * result) / Math.PI),1);
}
}
//调用类库:
Point a = new Point { x = 0, y = 0, z = 0 };
Point b = new Point { x = 0, y = 2, z = 0 };
Point c = new Point { x = 0, y = -1, z = Math.Sqrt(3) };
double[] result = Angle.getAllAngle(a, b, c);
Console.WriteLine(string.Format("a:{0}度, b:{1}度, c:{2}度", result[0], result[1], result[2]));
Console.Read();
public static float Angle(Point cen, Point first, Point second)
{
float dx1, dx2, dy1, dy2;
float angle;
dx1 = first.X - cen.X;
dy1 = first.Y - cen.Y;
dx2 = second.X - cen.X;
dy2 = second.Y - cen.Y;
float c = (float)Math.Sqrt(dx1 * dx1 + dy1 * dy1) * (float)Math.Sqrt(dx2 * dx2 + dy2 * dy2);
if (c == 0) return -1;
angle = (float)Math.Acos((dx1 * dx2 + dy1 * dy2) / c);
return angle;
}
S△=√[s*(s-a)*(s-b)*(s-c)] 【s=1/2(a+b+c)】
S△=1/2*ah
得出底所对应的高
知道一条边的长
又知道了高
角度出来了吧