private static ulong GetMinHsf(Vector3D v) { var hsfAll = Numerics.GetHighestSquareFactorOfAll( new[] { (ulong)Math.Abs(Math.Round(v.X)), (ulong)Math.Abs(Math.Round(v.Y)), (ulong)Math.Abs(Math.Round(v.Z)) } .Where(h => h > 0).ToArray()); return(hsfAll); }
public static ulong GetSurfacePoints(Cube c) { var s = (ulong)c.A.Length; var s3 = s * s * s; var hsf = Numerics.GetHighestSquareFactor(s); var surfacePoints = s3 - (hsf + 2) * s + hsf + 1; return(surfacePoints); }
private bool CalcIsPrimitive() { var nonZeroSides = Sides.Where(s => s != 0).ToArray(); for (int f = 2; f <= (int)Math.Ceiling((double)Sides.Max()); f++) { if (nonZeroSides.All(s => Numerics.IsIntegral((double)s / f))) { return(false); } } return(true); }
public static bool IsIntegral(Vector3D v) { var isIntegral = Numerics.IsIntegral(v.X) && Numerics.IsIntegral(v.Y) && Numerics.IsIntegral(v.Z); return(isIntegral); }
public void FindTwins() { using (var cmd = new SqlCommand("delete primitivetripletwins", sqlConnection)) { cmd.ExecuteNonQuery(); } double count = 0, tot = 853831; var twinFields = new string[] { "ux", "uy", "uz", "vx", "vy", "vz", "nx", "ny", "nz" }; var twinFieldParamNames = twinFields.Select(s => "@" + s).ToArray(); using (var cmd = new SqlCommand("select A,B,C,[Square] from primitivetriples", sqlConnection)) using (var cmdAlt = new SqlCommand( "select a,b,c " + "from primitivetriplepermutations " + "where [square] = @square", sqlConnection)) using (var cmdIns = new SqlCommand($"insert primitivetripletwins({twinFields.ToCsvString()}) values({twinFieldParamNames.ToCsvString()})", sqlConnection)) { var altSqParam = cmdAlt.Parameters.Add("@square", SqlDbType.Int); var twin = twinFieldParamNames.ToDictionary(s => s, s => cmdIns.Parameters.Add(s, SqlDbType.Int)); using (var rs = cmd.ExecuteReader()) while (rs.Read()) { Console.Write($"\r{count++/tot:0.00%} "); var a = Convert.ToInt32(rs["A"]); var b = Convert.ToInt32(rs["B"]); var c = Convert.ToInt32(rs["C"]); var square = Convert.ToInt32(rs["square"]); var v1 = new Vector3D(a, b, c); altSqParam.Value = square; bool found = false; using (var rsAlt = cmdAlt.ExecuteReader()) while (!found && rsAlt.Read()) { var altA = Convert.ToInt32(rsAlt["A"]); var altB = Convert.ToInt32(rsAlt["B"]); var altC = Convert.ToInt32(rsAlt["C"]); var v2 = new Vector3D(altA, altB, altC); if (v1.IsAtRightAnglesTo(v2)) { var cp = Vector3D.CrossProduct(v1, v2); cp *= (v1.Length / cp.Length); if (Numerics.IsIntegral(cp.X) && Numerics.IsIntegral(cp.Y) && Numerics.IsIntegral(cp.Z)) { //found twin["@ux"].Value = a; twin["@uy"].Value = b; twin["@uz"].Value = c; twin["@vx"].Value = altA; twin["@vy"].Value = altB; twin["@vz"].Value = altC; twin["@nx"].Value = (int)Math.Round(cp.X); twin["@ny"].Value = (int)Math.Round(cp.Y); twin["@nz"].Value = (int)Math.Round(cp.Z); cmdIns.ExecuteNonQuery(); found = true; } } } if (!found) { throw new InvalidOperationException($"No twin vector found for {v1}"); } } } }