public static float RemapFromSeedDecimal(float min, float max, System.Random randomSeed) { float zeroToOneValue = (float)randomSeed.NextDouble(); float minToMaxValue = ExtUtilityFunction.Remap(zeroToOneValue, 0, 1, min, max); return(minToMaxValue); }
/// <summary> /// here we have a min & max, we remap the random 0,1 value finded to this min&max /// warning: we cast it into an int at the end /// use: /// System.Random seed = ExtRandom.Seedrandom("hash"); /// int randomInt = ExtRandom.RemapFromSeed(0, 50, seed); /// </summary> public static int RemapFromSeed(double min, double max, System.Random randomSeed) { double zeroToOneValue = randomSeed.NextDouble(); int minToMaxValue = (int)ExtUtilityFunction.Remap(zeroToOneValue, 0, 1, min, max); return(minToMaxValue); }
public static double RemapFromSeedDecimal(double min, double max, System.Random randomSeed) { double zeroToOneValue = randomSeed.NextDouble(); double minToMaxValue = ExtUtilityFunction.Remap(zeroToOneValue, 0, 1, min, max); return(minToMaxValue); }
public static Vector3 GetMiddleOfXVector(Vector3[] arrayVect) { Vector3 sum = Vector3.zero; for (int i = 0; i < arrayVect.Length; i++) { if (ExtUtilityFunction.IsNullVector(arrayVect[i])) { continue; } sum += arrayVect[i]; } return((sum).normalized); }
/// <summary> /// take into acount unidirectinnal option, return null if not found /// </summary> /// <returns></returns> private Vector3 GetGoodPointUnidirectionnal(Vector3 p, Vector3 foundPosition) { //Vector3 projectedOnPlane = TriPlane.Project(EdgeAb.A, TriNorm.normalized, p); Vector3 dirPlayer = p - foundPosition; float dotPlanePlayer = ExtQuaternion.DotProduct(dirPlayer.normalized, TriNorm.normalized); if ((dotPlanePlayer < 0 && !inverseDirection) || dotPlanePlayer > 0 && inverseDirection) { return(foundPosition); } else { Debug.DrawRay(p, dirPlayer, Color.yellow, 5f); Debug.DrawRay(p, TriNorm.normalized, Color.black, 5f); return(ExtUtilityFunction.GetNullVector()); } }
public static bool IsCloseXToClampAmount(Quaternion q, float minX, float maxX, float margin = 2) { if (q.w == 0) { return(true); } q.x /= q.w; q.y /= q.w; q.z /= q.w; q.w = 1.0f; float angleX = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.x); if (ExtUtilityFunction.IsClose(angleX, minX, margin) || ExtUtilityFunction.IsClose(angleX, maxX, margin)) { return(true); } return(false); }
public Vector3 ClosestPointTo(Vector3 p) { // Find the projection of the point onto the edge var uab = EdgeAb.Project(p); var uca = EdgeCa.Project(p); bool isInPlane = false; Vector3 rightPositionIfOutsidePlane = CalculateCornerAndLine(p, uab, uca, ref isInPlane); if (!infinitePlane) { //ici on est dans un plan fini, si on dis de ne pas prendre //en compte les borders, juste tomber ! if (noGravityBorders && !isInPlane) { //Debug.Log("ici on est PAS dans le plane, juste tomber !"); return(ExtUtilityFunction.GetNullVector()); } else if (noGravityBorders && isInPlane) { //Debug.Log("ici on est DANS le plane, ET en noGravityBorder: tester la normal ensuite !"); if (unidirectionnal) { return(GetGoodPointUnidirectionnal(p, TriPlane.Project(EdgeAb.A, TriNorm.normalized, p))); //get the good point (or null) in a plane unidirectionnal } else { //ici en gravityBorder, et on est dans le plan, et c'esst multi directionnel, alors OK dac ! return(TriPlane.Project(EdgeAb.A, TriNorm.normalized, p)); } } else if (!noGravityBorders && unidirectionnal) { //here not infinite, and WITH borders AND unidirectionnal if (isInPlane) { return(GetGoodPointUnidirectionnal(p, TriPlane.Project(EdgeAb.A, TriNorm.normalized, p))); //get the good point (or null) in a plane unidirectionnal } else { return(GetGoodPointUnidirectionnal(p, rightPositionIfOutsidePlane)); } } else { //here Not infinite, WITH borders, NO unidirectionnal if (isInPlane) { return(TriPlane.Project(EdgeAb.A, TriNorm.normalized, p)); } else { return(rightPositionIfOutsidePlane); } } } else { if (unidirectionnal) { return(GetGoodPointUnidirectionnal(p, TriPlane.Project(EdgeAb.A, TriNorm.normalized, p))); //get the good point (or null) in a plane unidirectionnal } } //ici le plan est infini, OU fini mais on est dedant // The closest point is in the triangle so // project to the plane to find it //Vector3 projectedPoint = TriPlane.Project(EdgeAb.A, TriNorm.normalized, p); return(TriPlane.Project(EdgeAb.A, TriNorm.normalized, p)); }
/// <summary> /// return the middle of X points /// </summary> public static Vector3 GetMiddleOfXPoint(Vector3[] arrayVect, bool barycenter = true) { if (arrayVect.Length == 0) { return(ExtUtilityFunction.GetNullVector()); } if (!barycenter) { Vector3 sum = Vector3.zero; for (int i = 0; i < arrayVect.Length; i++) { sum += arrayVect[i]; } return(sum / arrayVect.Length); } else { if (arrayVect.Length == 1) { return(arrayVect[0]); } float xMin = arrayVect[0].x; float yMin = arrayVect[0].y; float zMin = arrayVect[0].z; float xMax = arrayVect[0].x; float yMax = arrayVect[0].y; float zMax = arrayVect[0].z; for (int i = 1; i < arrayVect.Length; i++) { if (arrayVect[i].x < xMin) { xMin = arrayVect[i].x; } if (arrayVect[i].x > xMax) { xMax = arrayVect[i].x; } if (arrayVect[i].y < yMin) { yMin = arrayVect[i].y; } if (arrayVect[i].y > yMax) { yMax = arrayVect[i].y; } if (arrayVect[i].z < zMin) { zMin = arrayVect[i].z; } if (arrayVect[i].z > zMax) { zMax = arrayVect[i].z; } } Vector3 lastMiddle = new Vector3((xMin + xMax) / 2, (yMin + yMax) / 2, (zMin + zMax) / 2); return(lastMiddle); } }