public virtual trajectory.Trajectory roll() { var r = worldRect.width(); var diagAng = Mathf.Asin(worldRect.height() / r); var horOffsetLimit = r - r * Mathf.Cos(diagAng); float xMin = worldRect.x0 + r; float xMax = worldRect.x0 + 2 * r - horOffsetLimit; float x0 = UnityEngine.Random.Range(xMin, xMax); float y0 = UnityEngine.Random.Range(worldRect.y0, worldRect.y1); float speedSign = odd ? 1 : -1; float angSpeed = speedSign * speed.value / r; var period = new Range(t, t + 10); float yInWorldRectSpace = y0 - worldRect.y0; float startAngle = odd ? Mathf.PI + Mathf.Acos((yInWorldRectSpace) / r) : (Mathf.PI * 3 / 2) + Mathf.Asin((worldRect.height() - yInWorldRectSpace) / r); var tr = new LeftArcTrajectory(x0, y0, r, angSpeed, startAngle, period); tr.period.t2 = odd ? tr.getTbyY(worldRect.y1): tr.getTbyY(worldRect.y0); return(tr); }
public static trajectory.Trajectory buildLine(float x1, float x2, float t0, math.WorldRect worldRect, float s, bool odd) { var xSign = x1 > x2 ? -1 : 1; var ySign = odd ? 1 : -1; float dx = (x2 - x1); float dy = worldRect.height(); float dxSq = (dx * dx); float dySq = (dy * dy); float sySq = (((s * s) * dySq) / ((dySq + dxSq))); float sxSq = ((s * s) - sySq); float pathLen = Mathf.Sqrt(dxSq + dySq); var period = new Range(t0, t0 + pathLen / s); var line = new LineTrajectory(x1, odd ? worldRect.y0 : worldRect.y1, xSign * Mathf.Sqrt(sxSq), ySign * Mathf.Sqrt(sySq), period); return(line); }