/// <summary> /// Creates a new triangle /// </summary> /// <param name="sideA">First side</param> /// <param name="sideB">Second side</param> /// <param name="sideC">Third side</param> public Triangle (Complex sideA, Complex sideB, Complex sideC) { SideA = sideA; SideB = sideB; SideC = sideC; AngleAB = Functions.ArcCos((sideA.Square() + sideB.Square() - sideC.Square()) / (2 * sideA * sideB)); AngleBC = Functions.ArcCos((sideC.Square() + sideB.Square() - sideA.Square()) / (2 * sideC * sideB)); AngleAC = Functions.ArcCos((sideA.Square() + sideC.Square() - sideB.Square()) / (2 * sideA * sideC)); }
public HComplex() { Value = new Complex(0, 0); Attributes.Add("real", new HassiumProperty("real", x => Real, (self, x) => Real = x[0].HDouble().Value)); Attributes.Add("imaginary", new HassiumProperty("imaginary", x => Imaginary, (self, x) => Imaginary = x[0].HDouble().Value)); Attributes.Add("imag", new HassiumProperty("imag", x => Imaginary, (self, x) => Imaginary = x[0].HDouble().Value)); Attributes.Add("module", new HassiumProperty("module", x => (double)Value.Module, null, true)); Attributes.Add("argument", new HassiumProperty("argument", x => (double)Value.Argument, null, true)); Attributes.Add("conjugate", new HassiumProperty("conjugate", x => (double)Value.Conjugate, null, true)); Attributes.Add("__add", new InternalFunction(Add, -1)); Attributes.Add("__substract", new InternalFunction(Substract, -1)); Attributes.Add("__multiply", new InternalFunction(Multiply, -1)); Attributes.Add("__divide", new InternalFunction(Divide, -1)); Attributes.Add("__compare", new InternalFunction(x => { var v = x[0].HComplex().Value; if (v > Value) return 1; if (v < Value) return -1; return 0; }, 1)); Attributes.Add("__pow", new InternalFunction(x => new HComplex(Functions.Pow(Value, x[0].HComplex().Value)), 1)); Attributes.Add("__root", new InternalFunction(x => new HComplex(Functions.NthRoot(Value, x[0].HComplex().Value)), 1)); Attributes.Add("negate", new InternalFunction(Negate, 0)); Attributes.Add("square", new InternalFunction(x => new HComplex(Value.Square()), 0)); }
public static Complex ArcCos(Complex value) { if (value.IsReal()) return Math.Acos(value.Real); /*if (value.Imaginary < 0 || value.Imaginary == 0d && value.Real > 0) { return Constant.Pi - Acos(-value); } */ return -Complex.ImaginaryOne * Ln(value + Complex.ImaginaryOne * Sqrt(1 - value.Square())); //return (Constant.Pi / 2.0) + Constant.I * Ln(Constant.I * value + Sqrt(1 - value.Square())); }
public static Complex ArcSin(Complex value) { if (value.IsReal()) return Math.Asin(value.Real); if (value.IsImaginary() || value.Imaginary == 0d && value.Real < 0) { return -ArcSin(-value); } return -Complex.ImaginaryOne * Sqrt(Ln((1 - value.Square())) + (Complex.ImaginaryOne * value)); }
public static Complex HermiteHFunc(Complex nu, Complex z) { return Pow(2.0, nu) * Sqrt(Constants.Pi) * (1.0 / Gamma((1.0 - nu) / 2) * Hypergeometric1F1(-nu / 2.0, 0.5, z.Square()) - (2.0 * z) / Gamma(-nu / 2.0) * Hypergeometric1F1((1.0 - nu) / 2.0, 1.5, z.Square())); }
public static Complex FibonacciFunc(Complex nu, Complex z) { return (Pow(2.0, -nu) * Pow(z + Sqrt(z.Square() + 4.0), nu) - Cos(nu * Constants.Pi) * Pow(2.0, nu) * Pow(z + Sqrt(z.Square() + 4.0), -nu)) / Sqrt(z.Square() + 4.0); }
public static Complex ChebyshevUFunc(Complex nu, Complex z) { return Sin((nu + 1.0) * ArcCos(z)) / Sqrt(1.0 - z.Square()); }
public static Complex AreaCylinder(Complex radius, Complex height) { return 2 * Constants.Pi * radius.Square() + 2 * Constants.Pi * radius * height; }
public static Complex AreaCube(Complex side) { return 6.0 * side.Square(); }
public static Complex AreaSphere(Complex radius) { return 4 * Constants.Pi * radius.Square(); }
public static Complex AreaPolygon(Complex sides, Complex length) { return (sides * length.Square()) / (4 * Tan(Constants.Pi / sides)); }
public static Complex AreaSector(Complex radius, Complex angle) { return (radius.Square() / 2.0) * Angle(angle); }
public static Complex AreaCircle(Complex radius) { return Constants.Pi * radius.Square(); }
public static Complex AreaSquare(Complex cote) { return cote.Square(); }
public static Complex ArcTan(Complex x, Complex y) { return 2.0 * ArcTan(y / (Sqrt(x.Square() + y.Square()) + x)); }
public void CanComputeSquare() { var complex = new Complex(1.19209289550780998537e-7, 1.19209289550780998537e-7); AssertHelpers.AlmostEqual(new Complex(0, 2.8421709430403888e-14), complex.Square(), 15); complex = new Complex(0.0, 1.19209289550780998537e-7); AssertHelpers.AlmostEqual(new Complex(-1.4210854715201944e-14, 0.0), complex.Square(), 15); complex = new Complex(0.0, -1.19209289550780998537e-7); AssertHelpers.AlmostEqual(new Complex(-1.4210854715201944e-14, 0.0), complex.Square(), 15); complex = new Complex(0.0, 0.5); AssertHelpers.AlmostEqual(new Complex(-0.25, 0.0), complex.Square(), 15); complex = new Complex(0.0, -0.5); AssertHelpers.AlmostEqual(new Complex(-0.25, 0.0), complex.Square(), 15); complex = new Complex(0.0, -8.388608e6); AssertHelpers.AlmostEqual(new Complex(-70368744177664.0, 0.0), complex.Square(), 15); }