/// <summary> /// Get lamella widths and heights from input curve and cross-section guide frames. /// </summary> /// <param name="c">Centreline curve.</param> /// <param name="lamella_width">Maximum lamella width.</param> /// <param name="lamella_height">Maximum lamella height</param> /// <param name="frames">Guide frames.</param> /// <param name="k_samples">Number of curvature samples to use.</param> /// <returns>A pair of doubles for maximum curvature in X and Y directions.</returns> public static double[] GetLamellaSizes(Curve c, out double lamella_width, out double lamella_height, Plane[] frames = null, int k_samples = 0) { if (c.IsLinear()) { lamella_width = double.MaxValue; lamella_height = double.MaxValue; return(new double[] { 0, 0 }); } Beam beam = new Lam.Beam(c, null, frames); if (k_samples < 3) { k_samples = DefaultCurvatureSamples; } double[] tt = beam.Centreline.DivideByCount(k_samples, false); double maxK = 0.0; int index = 0; Vector3d kvec = Vector3d.Unset; Vector3d tVec; double maxKX = 0.0; double maxKY = 0.0; double dotKX, dotKY; Plane tPlane; for (int i = 0; i < tt.Length; ++i) { tVec = beam.Centreline.CurvatureAt(tt[i]); tPlane = beam.GetPlane(tt[i]); dotKX = Math.Abs(tVec * tPlane.XAxis); dotKY = Math.Abs(tVec * tPlane.YAxis); maxKX = Math.Max(dotKX, maxKX); maxKY = Math.Max(dotKY, maxKY); if (tVec.Length > maxK) { index = i; kvec = tVec; maxK = tVec.Length; } } if (maxKX == 0.0) { lamella_width = double.MaxValue; } else { lamella_width = 1 / maxKX / Glulam.RadiusMultiplier; } if (maxKY == 0.0) { lamella_height = double.MaxValue; } else { lamella_height = 1 / maxKY / Glulam.RadiusMultiplier; } return(new double[] { maxKX, maxKY }); }
public static GlulamData FromCurveLimits(Curve c, double width, double height, Plane[] frames = null) { Beam beam = new Lam.Beam(c, null, frames); double[] tt = beam.Centreline.DivideByCount(100, true); double maxK = 0.0; int index = 0; Vector3d kvec = Vector3d.Unset; Vector3d temp; for (int i = 0; i < tt.Length; ++i) { temp = beam.Centreline.CurvatureAt(tt[i]); if (temp.Length > maxK) { index = i; kvec = temp; maxK = temp.Length; } } Plane frame = beam.GetPlane(tt[index]); if (frame == null) { throw new Exception("Frame is null!"); } //double max_lam_width = Math.Ceiling(width); //double max_lam_height = Math.Ceiling(height); double max_lam_width = width; double max_lam_height = height; //double lam_width = Math.Ceiling(Math.Min(1 / (Math.Abs(kvec * frame.XAxis) * Glulam.RadiusMultiplier), max_lam_width)); //double lam_height = Math.Ceiling(Math.Min(1 / (Math.Abs(kvec * frame.YAxis) * Glulam.RadiusMultiplier), max_lam_height)); double lam_width = Math.Min(1 / (Math.Abs(kvec * frame.XAxis) * Glulam.RadiusMultiplier), max_lam_width); double lam_height = Math.Min(1 / (Math.Abs(kvec * frame.YAxis) * Glulam.RadiusMultiplier), max_lam_height); if (lam_width == 0.0) { lam_width = max_lam_width; } if (lam_height == 0.0) { lam_height = max_lam_height; } GlulamData data = new GlulamData(); data.LamHeight = lam_height; data.LamWidth = lam_width; int num_height = (int)(Math.Ceiling(height / lam_height)); int num_width = (int)(Math.Ceiling(width / lam_width)); data.Lamellae = new Stick[num_width, num_height]; data.Samples = (int)(c.GetLength() / DefaultSampleDistance); // I forget why this is here... if (data.NumHeight * data.LamHeight - height > 20.0) { data.LamHeight = Math.Ceiling((height + 10.0) / data.NumHeight); } if (data.NumWidth * data.LamWidth - width > 20.0) { data.LamWidth = Math.Ceiling((width + 10.0) / data.NumWidth); } return(data); }