public static Dictionary <string, object> CurveSinusoidalPointsWithVoxel( Autodesk.DesignScript.Geometry.Curve _Curve, VoxelImage Voxel, double WaveLength = 5.0, double Amplitude = 1.0, double Resolution = 2.0) { VoxelChannel _VoxelChannel = Voxel.GetChannel(VoxelImageLayout.SHAPECHANNEL); double n = (_Curve.Length / WaveLength) * 4 * Resolution; double _Span = _Curve.Length / n; List <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); List <double> ks = new List <double>(); for (int i = 0; i < n; i++) { Autodesk.DesignScript.Geometry.Plane pl = _Curve.PlaneAtParameter(_Curve.ParameterAtSegmentLength(i * _Span)); Autodesk.DesignScript.Geometry.Point p = _Curve.PointAtSegmentLength(i * _Span); double FieldValue = V2GVoxel.GetVoxelFieldValue(_VoxelChannel, p.X, p.Y, p.Z); double k = FieldValue * Amplitude * Math.Sin(i * _Span * Math.PI * 2 / WaveLength + Math.PI * 2); points.Add((Autodesk.DesignScript.Geometry.Point)p.Translate(pl.YAxis, k)); ks.Add(k); } return(new Dictionary <string, object> { { "Points", points }, { "k", ks } }); }
/// <summary> /// Calculate voxel point properties. /// </summary> /// <param name="_Voxel"></param> public void SetPropertiesWith(VoxelImage _Voxel) { double delta = 0.000001; VoxelImage v = _Voxel as VoxelImage; VoxelChannel vc = v.GetChannel(VoxelImageLayout.SHAPECHANNEL) as VoxelChannel; V2GPoint x0 = this.Position - V2GPoint.XAxis * delta; V2GPoint x1 = this.Position + V2GPoint.XAxis * delta; V2GPoint y0 = this.Position - V2GPoint.YAxis * delta; V2GPoint y1 = this.Position + V2GPoint.YAxis * delta; V2GPoint z0 = this.Position - V2GPoint.ZAxis * delta; V2GPoint z1 = this.Position + V2GPoint.ZAxis * delta; double x = V2GVoxel.GetVoxelFieldValue(vc, x1) - V2GVoxel.GetVoxelFieldValue(vc, x0); double y = V2GVoxel.GetVoxelFieldValue(vc, y1) - V2GVoxel.GetVoxelFieldValue(vc, y0); double z = V2GVoxel.GetVoxelFieldValue(vc, z1) - V2GVoxel.GetVoxelFieldValue(vc, z0); V2GPoint UnitVector = new V2GPoint(x, y, z); UnitVector.Normalize(); double fieldValue = V2GVoxel.GetVoxelFieldValue(vc, this.Position); V2GPoint RealVector = UnitVector * fieldValue; V2GPoint UnitVectorProjected = new V2GPoint(RealVector.X, RealVector.Y, 0); V2GPoint UnitVectorPerpendicularProjected = V2GPoint.CrossProduct(UnitVectorProjected, V2GPoint.ZAxis); UnitVectorProjected.Normalize(); UnitVectorPerpendicularProjected.Normalize(); this.ContourVector3d = UnitVector; this.ContourVector = UnitVectorPerpendicularProjected; this.GradientVector = UnitVectorProjected; this.FieldValue = fieldValue; }
/// <summary> /// Get field value of a VoxelChannel at a given point. /// </summary> /// <param name="vc"></param> /// <param name="p"></param> /// <returns name="Value"></returns> public static double VoxelChannelValueAtPoint(VoxelChannel vc, Autodesk.DesignScript.Geometry.Point p) { return(V2GVoxel.GetVoxelFieldValue(vc, p.X, p.Y, p.Z)); }