public long Distance(long otherX, long otherY) { temp1 = this.x - otherX; temp1 *= temp1; temp2 = this.y - otherY; temp2 *= temp2; return(FixedMath.Sqrt((temp1 + temp2) >> FixedMath.SHIFT_AMOUNT)); }
public void Normalize() { long magnitude = FixedMath.Sqrt(x.Mul(x) + y.Mul(y) + z.Mul(z)); x = x.Div(magnitude); y = y.Div(magnitude); z = z.Div(magnitude); }
/// <summary> /// This vector's magnitude. /// </summary> public long Magnitude() { temp1 = (this.x * this.x + this.y * this.y); if (temp1 == 0) { return(0); } temp1 >>= FixedMath.SHIFT_AMOUNT; return(FixedMath.Sqrt(temp1)); }
public long Distance(Vector3d other) { long tX = other.x - x; tX *= tX; tX >>= FixedMath.SHIFT_AMOUNT; long tY = other.y - y; tY *= tY; tY >>= FixedMath.SHIFT_AMOUNT; long tZ = other.z - z; tZ *= tZ; tZ >>= FixedMath.SHIFT_AMOUNT; return(FixedMath.Sqrt(tX + tY + tZ)); }
public static Vector2d GenerateRandomPointOnCircle(bool evenDistribution = false) { long angle = LSUtility.GetRandomOne().Mul(FixedMath.TwoPi); long distance = LSUtility.GetRandomOne(); if (evenDistribution) { distance = FixedMath.Sqrt(distance); } Vector2d randomOffset = new Vector2d( FixedMath.Trig.Cos(angle), FixedMath.Trig.Sin(angle) ) * distance; return(randomOffset); }
public static long Cos(long theta) { long sin = Sin(theta); return(FixedMath.Sqrt(FixedMath.One - (sin.Mul(sin)))); }