public static List<LineSegment> fractalLineSegment(LineSegment ls, float maxOffset, float threshold) { s_lineFractalPerp = ls.getLine().getPerpVector(); s_lineFractalLength = ls.getLength(); return fractalLineSegment(ls, maxOffset, threshold, 1); }
public bool getIntersect(ref LineSegment rhs, out Vector2 pt) { Line l1 = this.getLine(); Line l2 = rhs.getLine(); pt = l1.getIntersect(l2); if (this.containsX(pt.X) && rhs.containsX(pt.X)) { return true; } return false; }
public static List<LineSegment> fractalLineSegment(LineSegment ls, float baseMaxOffset, float threshold, int depth) { // TODO fix for short line segments... it goes crazy! that or increase threshold, but still... const int maxDepth = 6; List<LineSegment> result = new List<LineSegment>(); // recursive base case if (ls.getLengthSquared() < threshold || depth >= maxDepth) { result.Add(ls); return result; } // calculate and offset midpt // easy approach - midpt Vector2 midpt = ls.getMidpoint(); // other approach - any pt on the line segment selected from a normal dist between the pts // for whatever reason, this doesn't seem to work quite as well //float percentBetween = RandomManager.nextNormalDistPercent(1); //Vector2 midpt = ls.getLine().getPt(ls.p.X + (ls.q.X - ls.p.X) * percentBetween); // Can calculate max offset for this segment either as proportion of the original max depth // float maxOffset = maxOffset * (maxDepth - depth) / maxDepth; // Or as a proportion of the original length of the line float maxOffset = baseMaxOffset * ls.getLength() / s_lineFractalLength; float offset = (float)(RandomManager.get().NextDouble() - 0.5f) * maxOffset; // Can get offset direction either from current line segment or original line segment // Vector2 dir = ls.getLine().getPerpVector(); Vector2 offsetDir = s_lineFractalPerp; offsetDir.Normalize(); midpt += offset * offsetDir; // recurse! List<LineSegment> left = fractalLineSegment(new LineSegment(ls.p, midpt), maxOffset, threshold, depth+1); List<LineSegment> right = fractalLineSegment(new LineSegment(midpt, ls.q), maxOffset, threshold, depth+1); result.AddRange(left); result.AddRange(right); return result; }
/// <summary> /// Maps fractals at the Region level into fractals at the Area level. /// </summary> /// <param name="fractals">Fractals to be mapped.</param> /// <param name="areaX">X position of Area RELATIVE TO THE REGION.</param> /// <param name="areaY">Y position of Area RELATIVE TO THE REGION.</param> /// <returns>Fractals with coordinates corresponding to the specified Area's coordinate system.</returns> public static List<LineFractalInfo> mapFractals(List<LineFractalInfo> fractals, int areaX, int areaY) { List<LineFractalInfo> mappedFractals = new List<LineFractalInfo>(); foreach (LineFractalInfo lfi in fractals) { List<LineSegment> mappedFractal = new List<LineSegment>(); foreach (LineSegment ls in lfi.fractal) { LineSegment mappedSeg = new LineSegment( Region.mapCoordToArea(ls.p, areaX, areaY), Region.mapCoordToArea(ls.q, areaX, areaY)); mappedFractal.Add(mappedSeg); } mappedFractals.Add(new LineFractalInfo(mappedFractal)); } return mappedFractals; }