/** * divideCrvsByDeltaTan : Curve[] * double -> LinkedList<Plane> * REQUIRES: theta > 0 * ENSURES: divideCrvsByDeltaTan(crvs, theta) returns a linked list of planes * along the curves s.t. there is a plane at every point along * the curve where the change in the tangent vector between * two points is greater than theta. **/ private IEnumerable <Point3d> DivByAngle(Curve crv, double angle) { //initialize parameters double theta = angle; Interval dom = crv.Domain; double stepSize = Math.Abs(dom.Length) * Constants.AbsoluteTolerance * Constants.AbsoluteTolerance; //initialize list List <Point3d> pts = new List <Point3d>(); Continuity c = Continuity.C1_continuous; //initialize data double rover = dom.Min; //steps along the curve by stepSize //Add plane at start point of curve to list Point3d pt = crv.PointAt(rover); pts.Add(pt); //Increment Vector3d prevTan = crv.TangentAt(rover); double oldRover = rover; //stores the previous rover for comparison rover += stepSize; while (rover < dom.Max) { Vector3d currTan = crv.TangentAt(rover); //If there is a discontinuity between the oldRover and rover //then place a point at the discontinuity and update prevTan. double discontinuity; bool isDisc = crv.GetNextDiscontinuity(c, oldRover, rover, out discontinuity); if (isDisc) { pt = crv.PointAt(discontinuity); pts.Add(pt); prevTan = crv.TangentAt(discontinuity); } //If the change in tangent vector is greater than theta, //then drop a target at the rover and update prevTan. double delta = RhinoMath.ToDegrees(Math.Abs(Vector3d.VectorAngle(prevTan, currTan))); if (delta > theta) { pt = crv.PointAt(rover); pts.Add(pt); prevTan = currTan; } //Increment oldRover = rover; rover += stepSize; } //Add target at end point of curve pt = crv.PointAt(dom.Max); pts.Add(pt); return(pts); }
public static Result GetAngle(RhinoDoc doc) { var gp = new GetPoint(); gp.SetCommandPrompt("Base point"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var base_point = gp.Point(); gp.SetCommandPrompt("First reference point"); gp.DrawLineFromPoint(base_point, true); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var first_point = gp.Point(); double angle_radians; var rc = RhinoGet.GetAngle("Second reference point", base_point, first_point, 0, out angle_radians); if (rc == Result.Success) { RhinoApp.WriteLine("Angle = {0} degrees", RhinoMath.ToDegrees(angle_radians)); } return(rc); }
//private void ExportSampler() //{ // _mitsubaXml.CreateSamplerXml(); //} /// <summary> /// This method exports the Mitsuba emitters: lights and environment. /// /// NOTE: if you try to get the environment with RhinoDoc.ActiveDoc.RenderEnvironments[0] /// Rhino crashes with a "pure virtual function called" error... /// </summary> private void ExportEmitters() { if (RhinoDoc.ActiveDoc.RenderEnvironments.Count > 0) { //HDR environment var environment = RenderEnvironment.CurrentEnvironment; var texture = environment.FindChild("texture"); if (texture != null) { var env_file = texture.Fields.GetField("filename").ValueAsObject(); _mitsubaXml.CreateEnvironmentEmitterXml(env_file.ToString()); } } //Lights foreach (var obj in RhinoDoc.ActiveDoc.Objects.GetObjectList(ObjectType.Light)) { if (!obj.Visible) { continue; } var objRef = new ObjRef(obj); var light = objRef.Light(); MitsubaEmitter emitter = null; if (light.IsPointLight) { //var location = light.Location; //var spectrum = light.Diffuse; //var sampleWeight = light.Intensity; emitter = new PointLightSource(light.Location, (float)light.Intensity * 100); } else if (light.IsSpotLight) { var origin = light.Location; var target = light.Direction; var cutoffAngle = (float)RhinoMath.ToDegrees(light.SpotAngleRadians); var intensity = (float)light.Intensity * 50000; //TODO Multiplicador SpotLight ??? emitter = new SpotLightSource(origin, target, intensity, cutoffAngle); } else if (light.IsSunLight) { //TODO SunLight } if (emitter != null) { _mitsubaXml.CreateEmitterXml(emitter); } } }
protected override void SolveInstance(IGH_DataAccess access) { string text = null; string font = null; Color colour = Color.Black; Point3d location = Point3d.Origin; double horizontal = 0.0; double vertical = 0.0; double rotation = 0.0; if (!access.GetData(0, ref text)) { return; } if (!access.GetData(1, ref font)) { return; } if (!access.GetData(2, ref location)) { return; } if (!access.GetData(3, ref colour)) { return; } if (!access.GetData(4, ref horizontal)) { return; } if (!access.GetData(5, ref vertical)) { return; } if (!access.GetData(6, ref rotation)) { return; } Param_Number param = (Param_Number)Params.Input[6]; if (!param.UseDegrees) { rotation = RhinoMath.ToDegrees(rotation); } GdiTextGoo goo = new GdiTextGoo(text, font, colour, location, horizontal, vertical, rotation); access.SetData(0, goo); }
private void RunScript(Plane source, Plane target, ref object XYZ, ref object ABC) { // <Custom code> Transform temp = Transform.PlaneToPlane(source, target); double C = RhinoMath.ToDegrees(Math.Atan2(temp.M21, temp.M22)); double B = RhinoMath.ToDegrees(-Math.Atan2(temp.M20, Math.Sqrt((temp.M21 * temp.M21 + temp.M22 * temp.M22)))); double A = RhinoMath.ToDegrees(Math.Atan2(temp.M10, temp.M00)); ABC = new Vector3d(A, B, C); Point3d _XYZ; source.RemapToPlaneSpace(target.Origin, out _XYZ); XYZ = _XYZ; // </Custom code> }
//내각 구하기 public List <double> InnerAngles(List <Line> lineSegments) { List <double> innerAngles = new List <double>(); for (int i = 0; i < lineSegments.Count; i++) { Line l1 = lineSegments[i]; Line l2 = lineSegments[(i + 1) % lineSegments.Count]; double a, b; Vector3d v1, v2; Rhino.Geometry.Intersect.Intersection.LineLine(l1, l2, out a, out b, 0, false); if (a > 0 && b <= 0) { v1 = lineSegments[i].UnitTangent * -1; v2 = lineSegments[(i + 1) % lineSegments.Count].UnitTangent; } else if (b > 0 && a <= 0) { v1 = lineSegments[i].UnitTangent; v2 = lineSegments[(i + 1) % lineSegments.Count].UnitTangent * -1; } else if (b > 0 && a > 0) { v1 = lineSegments[i].UnitTangent * -1; v2 = lineSegments[(i + 1) % lineSegments.Count].UnitTangent * -1; } else { v1 = lineSegments[i].UnitTangent; v2 = lineSegments[(i + 1) % lineSegments.Count].UnitTangent; } double innerAngle = RhinoMath.ToDegrees(Vector3d.VectorAngle(v2, v1, Plane.WorldXY)); innerAngles.Add(innerAngle); } return(innerAngles); }
/// <summary> /// Calcuate the wire rotataion from -360 to +360 based on the input vector and current location. /// </summary> /// <param name="vector">Vector3d - The direction the wire should be oriented toward.</param> /// <returns>double - angle measurement from -360 to +360.</returns> public double VectorRotation(Vector3d vector) { /* * Locate the Angle of a Vector from 0 to 360 * Using: * A<dot> B =|| A || *|| B || *cos(Angle) * Cosine Law Computes between 0 and 180. * Vertical Referance allows(+/ -) orientation to be solved. * * H_Len - Magnitude of Horizontal Referance * H_DP - Dot Product of Vector and Horizontal * H_Angle - Angle from Horizontal to Vector * * V_Len - Magnitude of Vertical Referance * V_DP - Dot Product of Vector and Vertical * V_Angle - Angle from Vertical to Vector * * Quadrent Key: * I - H_Angle + V_Angle == 90 * II - H_Angle - V_Angle == 90 * III - H_Angle + V_Angle == 270 * IV - V_Angle - H_Angle == 90 * ########################### ## ## ## II | I ## ## \ | / ## ## \ | / ## ##^ \ | / ## ##0_________\|/__________## ## /|\ ## ## / | \ ## ## / | \ ## ## / | \ ## ## III | IV ## ## ## ########################### */ Vector3d horizontal = this.cutPlane.XAxis; Vector3d vertical = this.cutPlane.YAxis; if (this.cutPlane.Normal.IsParallelTo(vector) != 0) { throw new Exception($"Wire angle vector cannot be parallel to the cut plane normal!"); } if (!this.cutPlane.Normal.IsPerpendicularTo(vector)) { vector = (Vector3d)this.cutPlane.ClosestPoint(new Point3d(vector.X, vector.Y, vector.Z)); } vector.Unitize(); var hAngle = RhinoMath.ToDegrees(Vector3d.VectorAngle(vector, horizontal)); var vAngle = RhinoMath.ToDegrees(Vector3d.VectorAngle(vector, vertical)); double angle; if (vector.IsParallelTo(this.cutPlane.XAxis) != 0) { angle = 0; } else if (vector.IsParallelTo(this.cutPlane.YAxis) != 0) { angle = 90; } else if (Math.Abs(hAngle + vAngle - 90) <= this.Doc.ModelAbsoluteTolerance) { // Quadrent I // angle = hAngle; } else if (Math.Abs(hAngle - vAngle - 90) <= this.Doc.ModelAbsoluteTolerance) { // Quadrend II // angle = 90 + vAngle; } else if (Math.Abs(hAngle + vAngle - 270) <= this.Doc.ModelAbsoluteTolerance) { // Quadrend III // angle = 90 + vAngle; } else if (Math.Abs(vAngle - hAngle - 90) <= this.Doc.ModelAbsoluteTolerance) { // Quadrend IV // angle = 360 - hAngle; } else { throw new Exception("Error calcuating wire position"); } double move = angle - this.CurrentLocation[3]; for (int adj = -360; adj <= 360; adj += 180) { if (Math.Abs(move) > Math.Abs(move + adj)) { move = move + (double)adj; } } return(Math.Round(this.CurrentLocation[3] + move, this.ToleranceDecimals)); }
public static HyparPlane ToHyparPlane(this rg.Plane p) { return(new HyparPlane(p.Origin.ToVector3(), RhinoMath.ToDegrees(rg.Vector3d.VectorAngle(rg.Vector3d.XAxis, p.XAxis, rg.Plane.WorldXY)))); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Definition of input variables var north = new Vector3d(); var sazi = new List <double>(); var salt = new List <double>(); var shours = new List <double>(); var pmesh = new List <Mesh>(); var atol = new double(); //Definition of output variable var siftazi = new GH_Structure <GH_Number>(); var siftalt = new GH_Structure <GH_Number>(); var sifthours = new GH_Structure <GH_Number>(); var svector = new GH_Structure <GH_Vector>(); // Populating the list input variables if (!DA.GetData(0, ref north)) { return; } if (!DA.GetDataList(1, sazi)) { return; } if (!DA.GetDataList(2, salt)) { return; } if (!DA.GetDataList(3, shours)) { return; } if (!DA.GetDataList(4, pmesh)) { return; } if (!DA.GetData(5, ref atol)) { return; } // Evaluate if North == null if (north == null) { north = new Vector3d(1.0, 0.0, 0.0); } //Project north in the XY world and unitize if (!north.IsPerpendicularTo(new Vector3d(0.0, 0.0, 1.0))) { var xyworld = new Plane(new Point3d(0.0, 0.0, 0.0), new Vector3d(0.0, 0.0, 1.0)); var proj_xyworld = new Transform(); proj_xyworld = Transform.PlanarProjection(xyworld); north.Transform(proj_xyworld); north.Unitize(); } else { north.Unitize(); } // Abort the component if retrieval fails or input length are zeros if (sazi == null) { return; } if (salt == null) { return; } if (shours == null) { return; } if (sazi.Count == 0) { return; } if (salt.Count == 0) { return; } if (shours.Count == 0) { return; } // Abort if sazi, salt and shours counts differ if (!(sazi.Count == salt.Count || sazi.Count == shours.Count || salt.Count == shours.Count)) { return; } // start the analysis int scount = sazi.Count; int mcount = pmesh.Count; //for each input mesh for (int i = 0; i < mcount; i++) { GH_Path p1 = new GH_Path(i); var current_mesh = pmesh[i]; var current_centroid = new Point3d(AreaMassProperties.Compute(current_mesh).Centroid); current_mesh.FaceNormals.ComputeFaceNormals(); var current_normal = current_mesh.FaceNormals[0]; current_normal.Unitize(); //for each input sun vector for (int j = 0; j < scount; j++) { GH_Path p2 = new GH_Path(i, j); //convert sun angles to radians var current_sazi_r = RhinoMath.ToRadians(sazi[j]); var current_salt_r = RhinoMath.ToRadians(salt[j]); // convert to clockwise angle values current_sazi_r = 2 * Math.PI - current_sazi_r; current_salt_r = 2 * Math.PI - current_salt_r; var current_sazi = new GH_Number(RhinoMath.ToDegrees(current_sazi_r)); var current_salt = new GH_Number(RhinoMath.ToDegrees(current_salt_r)); var current_shour = new GH_Number(shours[j]); //create sun vector var current_sun = new Vector3d(north.X - current_centroid.X, north.Y - current_centroid.Y, north.Z - current_centroid.Z); current_sun.Unitize(); //current_sun.Reverse(); current_sun.Rotate(current_salt_r, Vector3d.CrossProduct(new Vector3d(0.0, 0.0, 1.0), north)); current_sun.Rotate(current_sazi_r, new Vector3d(0.0, 0.0, 1.0)); //current_sun.Reverse(); // Dot product mesh normal current_sun var dsn = Vector3d.Multiply(current_normal, current_sun); if (dsn > (0 + Math.Cos(Math.PI / 2 - atol))) { siftazi.Append(current_sazi, p1); siftalt.Append(current_salt, p1); sifthours.Append(current_shour, p1); svector.Append(new GH_Vector(current_sun)); } } } DA.SetDataTree(0, siftazi); DA.SetDataTree(1, siftalt); DA.SetDataTree(2, sifthours); DA.SetDataTree(3, svector); }
/// <summary> /// This procedure contains the user code. Input parameters are provided as regular arguments, /// Output parameters as ref arguments. You don't have to assign output parameters, /// they will have a default value. /// </summary> private void RunScript(DataTree <Curve> cTree, DataTree <double> oTree, double angleThreshold, ref object crvs, ref object crvs2, ref object pts, ref object perps) { DataTree <Curve> outputCrvs = new DataTree <Curve>(); DataTree <Point3d> outputPts = new DataTree <Point3d>(); DataTree <Curve> fillerCrvs = new DataTree <Curve>(); List <Curve> outCrvs = new List <Curve>(); for (int i = 0; i < cTree.BranchCount; i++) { List <Curve> cList = cTree.Branch(i); GH_Path p = cTree.Path(i); Curve crv = null; for (int j = 0; j < cList.Count; j++) { double offsetValue = oTree.Branch(i)[j]; //offset & extend if (offsetValue != 0) { Curve[] cArr = cList[j].Offset(Plane.WorldXY, offsetValue, RhinoMath.DefaultDistanceToleranceMillimeters, CurveOffsetCornerStyle.None); foreach (Curve c in cArr) { crv = c; } } else { crv = cList[j]; } // if for loop is not in the first iteration && tangent of current curve equals tangent of previous curve && curves are disjoint, Create a line perpendidular between the 2 curves) if ((i > 0)) { Curve prevCrv = outputCrvs.Branch(i - 1)[j]; double vecAngle = RhinoMath.ToDegrees(Vector3d.VectorAngle(crv.TangentAtStart, prevCrv.TangentAtEnd)); if (vecAngle < angleThreshold) { List <Point3d> _pts = new List <Point3d>() { prevCrv.PointAtEnd, crv.PointAtStart }; outCrvs.Add(Curve.CreateControlPointCurve(_pts)); fillerCrvs.Add(Curve.CreateControlPointCurve(_pts), p); } else { crv = crv.Extend(CurveEnd.Start, crv.GetLength(), CurveExtensionStyle.Line); } } outCrvs.Add(crv); outputCrvs.Add(crv, p); outputPts.Add(crv.PointAtNormalizedLength(0.5), p); } } outputCrvs.MergeTree(fillerCrvs); crvs = outputCrvs; crvs2 = outCrvs; pts = outputPts; perps = fillerCrvs; }