Beispiel #1
0
 /// <summary>
 /// 设置为与目标相同的向量值,并返回自身。
 /// </summary>
 /// <param name="target">目标对象</param>
 /// <returns>自身</returns>
 public Vector2D ResetWith(Vector2D target)
 {
     X = target.X;
     Y = target.Y;
     return this;
 }
Beispiel #2
0
 /// <summary>
 /// 将向量设为自身与目标向量的均值
 /// </summary>
 /// <param name="v">目标向量</param>
 /// <returns>自身</returns>
 public Vector2D AverageWith(Vector2D v)
 {
     X=(X + v.X) / 2;
     Y=(Y + v.Y) / 2;
     return this;
 }
Beispiel #3
0
 /// <summary>
 ///  构造函数
 /// </summary>
 /// <param name="vector2d">参照向量</param>
 public Vector2D(Vector2D vector2d)
 {
     X = vector2d.X;
     Y = vector2d.Y;
 }
Beispiel #4
0
 /// <summary>
 /// 判断是否垂直于目标向量
 /// </summary>
 /// <param name="v">检测垂直的目标向量</param>
 /// <returns>是否垂直</returns>
 public bool IsPerpTo(Vector2D v)
 {
     return Dot(v) == 0;
 }
Beispiel #5
0
 /// <summary>
 /// 计算向量间夹角的角度
 /// </summary>
 /// <param name="v">目标向量</param>
 /// <returns>角度值,一个0至360之间的值</returns>
 public double AngleBetween(Vector2D v)
 {
     double dp = Dot(v);
     double cosAngle = dp / (Length * v.Length);
     return MathEx.acosAngle(cosAngle);
 }
Beispiel #6
0
 /// <summary>
 /// 以当前角度为基础,围绕指定中心点旋转指定角度,并返回自身。
 /// </summary>
 /// <param name="angle">旋转角度值,一个0至360之间的值</param>
 /// <param name="center">参照中心点</param>
 /// <returns>自身</returns>
 public Vector2D RotateByCustomCenter(double angle,Vector2D center)
 {
     Minus(center);
     Rotate(angle);
     Plus(center);
     return this;
 }
Beispiel #7
0
 /// <summary>
 /// 将两轴分别乘算并相加以获得点积(数量积)。如果两个向量点积为0,则它们互相垂直。
 /// </summary>
 /// <param name="v">乘算对象</param>
 /// <returns>点积</returns>
 public double Dot(Vector2D v)
 {
     return X * v.X + Y * v.Y;
 }
Beispiel #8
0
 /// <summary>
 /// 依据指定的中心点缩放,即乘运算,并返回自身。
 /// </summary>
 /// <param name="center">中心点</param>
 /// <param name="value">乘算向量值</param>
 /// <returns>自身</returns>
 public Vector2D ScaleByCustomCenter(Vector2D value, Vector2D center)
 {
     return ScaleByCustomCenter(value.X, value.Y, center);
 }
Beispiel #9
0
 /// <summary>
 /// 依据指定的中心点缩放,即乘运算,并返回自身。
 /// </summary>
 /// <param name="xValue">X乘算值</param>
 /// <param name="yValue">Y乘算值</param>
 /// <param name="center">中心点</param>
 /// <returns>自身</returns>
 public Vector2D ScaleByCustomCenter(double xValue, double yValue, Vector2D center)
 {
     Minus(center);
     Scale(xValue, yValue);
     Plus(center);
     return this;
 }
Beispiel #10
0
 /// <summary>
 /// 缩放,即乘运算,并返回自身。
 /// </summary>
 /// <param name="value">乘算向量值</param>
 /// <returns>自身</returns>
 public Vector2D Scale(Vector2D value)
 {
     return Scale(value.X, value.Y);
 }
Beispiel #11
0
 /// <summary>
 /// 向量相减,并返回自身。
 /// </summary>
 /// <param name="value">相减的对象</param>
 /// <returns>自身</returns>
 public Vector2D Minus(Vector2D value)
 {
     X -= value.X;
     Y -= value.Y;
     return this;
 }
Beispiel #12
0
 /// <summary>
 /// 向量相加,并返回自身。
 /// </summary>
 /// <param name="value">相加的对象</param>
 /// <returns>自身</returns>
 public Vector2D Plus(Vector2D value)
 {
     X += value.X;
     Y += value.Y;
     return this;
 }