积极答复者
请教一段数学算式

问题
-
public class Vector
{
public double? R = null;
public double? Theta = null;
public double? ThetaRadians
{
get
{
return (Theta * Math.PI / 180.0);
}
}
public Vector(double? r, double? theta)
{
if (r < 0)
{
r = -r;
theta += 180;
}
theta = theta % 360;
R = r;
Theta = theta;
}
public static Vector operator +(Vector op1, Vector op2)//可否给逐行解析一下
{
double newX = op1.R.Value * Math.Sin(op1.ThetaRadians.Value) + op2.R.Value * Math.Sin(op2.ThetaRadians.Value);
double newY = op1.R.Value * Math.cos(op1.ThetaRadians.Value) + op2.R.Value * Math.cos(op2.ThetaRadians.Value);
double newR = Math.Sqrt(newX * newX + newY * newY);
double newTheta = Math.Atan2(newX, newY) * 180.0 / Math.PI;
return new Vector(newR, newTheta);
}
答案
-
-
你好!
public static Vector operator +(Vector op1, Vector op2)//重载“+”运算符来实现向量的加法,重载以后,当两个Vector实力相加的时候,就执行这个方法中的代码
{
double newX = op1.R.Value * Math.Sin(op1.ThetaRadians.Value) + op2.R.Value * Math.Sin(op2.ThetaRadians.Value);
double newY = op1.R.Value * Math.cos(op1.ThetaRadians.Value) + op2.R.Value * Math.cos(op2.ThetaRadians.Value);
double newR = Math.Sqrt(newX * newX + newY * newY);
double newTheta = Math.Atan2(newX, newY) * 180.0 / Math.PI;
return new Vector(newR, newTheta);
}
周雪峰- 已标记为答案 乔峰 2010年9月26日 6:31
全部回复
-
-
你好!
public static Vector operator +(Vector op1, Vector op2)//重载“+”运算符来实现向量的加法,重载以后,当两个Vector实力相加的时候,就执行这个方法中的代码
{
double newX = op1.R.Value * Math.Sin(op1.ThetaRadians.Value) + op2.R.Value * Math.Sin(op2.ThetaRadians.Value);
double newY = op1.R.Value * Math.cos(op1.ThetaRadians.Value) + op2.R.Value * Math.cos(op2.ThetaRadians.Value);
double newR = Math.Sqrt(newX * newX + newY * newY);
double newTheta = Math.Atan2(newX, newY) * 180.0 / Math.PI;
return new Vector(newR, newTheta);
}
周雪峰- 已标记为答案 乔峰 2010年9月26日 6:31