public float GetNoiseTiled(Vector2 vec) { var s = vec.X / _periodX; var t = vec.Y / _periodY; const float x1 = 0; const float x2 = 1; const float y1 = 0; const float y2 = 1; const float dx = x2 - x1; const float dy = y2 - y1; const float tau = (float)Math.TAU; //(float)Math.PI * 2; const float dxTau = dx / tau; const float dyTau = dy / tau; var nx = x1 + (float)Math.Cos(s * tau) * dxTau; var ny = y1 + (float)Math.Cos(t * tau) * dyTau; var nz = x1 + (float)Math.Sin(s * tau) * dxTau; var nw = y1 + (float)Math.Sin(t * tau) * dyTau; return(GetNoise(nx, ny, nz, nw)); }
/// <summary> /// Converts this angle to a unit direction vector. /// </summary> /// <returns>Unit Direction Vector</returns> public Vector2 ToVec() { var x = Math.Cos(Theta); var y = Math.Sin(Theta); return(new Vector2((float)x, (float)y)); }
public static Matrix3 CreateRotation(Angle angle) { var cos = (float)Math.Cos(angle); var sin = (float)Math.Sin(angle); var result = Identity; /* column major * cos -sin 0 * sin cos 0 * 0 0 1 */ result.R0C0 = cos; result.R1C0 = sin; result.R0C1 = -sin; result.R1C1 = cos; return(result); }
/// <summary> /// calculates the smallest AABB that will encompass the rotated box. The AABB is in local space. /// </summary> public Box2 CalcBoundingBox() { // https://stackoverflow.com/a/19830964 var(X0, Y0) = Box.BottomLeft; var(X1, Y1) = Box.TopRight; var Fi = Rotation.Theta; var CX = (X0 + X1) / 2; //Center point var CY = (Y0 + Y1) / 2; var WX = (X1 - X0) / 2; //Half-width var WY = (Y1 - Y0) / 2; var SF = Math.Sin(Fi); var CF = Math.Cos(Fi); var NH = Math.Abs(WX * SF) + Math.Abs(WY * CF); //boundrect half-height var NW = Math.Abs(WX * CF) + Math.Abs(WY * SF); //boundrect half-width return(new Box2((float)(CX - NW), (float)(CY - NH), (float)(CX + NW), (float)(CY + NH))); //draw bound rectangle }