public static CrossSectionOfLine GetStarShapedPolygon(double innerRadius, double outerRadius, int starArms) { var result = new CrossSectionOfLine(); int numVertices = starArms * 2; int numNormals = 2 * numVertices; result._vertices = new PointD2D[numVertices]; result._isVertexSharp = new bool[numVertices]; result._normals = new VectorD2D[numNormals]; for (int i = 0; i < numVertices; ++i) { double phi = (Math.PI * (2 * i)) / numVertices; double radius = 0 == (i % 2) ? outerRadius : innerRadius; result._vertices[i] = new PointD2D(radius * Math.Cos(phi), radius * Math.Sin(phi)); result._isVertexSharp[i] = true; } // now the normals, we calculate them using the cross product with the z-axis var zaxis = new VectorD3D(0, 0, 1); for (int i = 0; i < numVertices; ++i) { var line = (VectorD2D)(result._vertices[(i + 1) % numVertices] - result._vertices[i]); VectorD2D cross = new VectorD2D(line.Y, line.X).Normalized; result._normals[(2 * i + 1) % numNormals] = cross; result._normals[(2 * i + 2) % numNormals] = cross; } // normals return(result); }
/// <summary> /// Calculates the normal to a extruded contour. Here the extrusion direction is fixed to z-direction. /// </summary> /// <param name="crossSectionPoint">Original cross section point coordinates.</param> /// <param name="crossSectionNormal">Original cross section normal.</param> /// <param name="contourNormal">Original contour normal.</param> /// <param name="contourZScale">Factor that is multiplied with the x-coordinate of the contour point to return the z-coordinate of the resulting contour.</param> /// <returns>The normal of the extruded contour (x-y is the cross section plane, z the extrusion direction). This vector has then to be transformed into the 3D-space of the body.</returns> protected static VectorD3D GetNormalVector(PointD2D crossSectionPoint, VectorD2D crossSectionNormal, VectorD2D contourNormal, double contourZScale) { return(VectorD3D.CreateNormalized ( contourNormal.Y * crossSectionNormal.X * contourZScale, contourNormal.Y * crossSectionNormal.Y * contourZScale, contourNormal.X * (crossSectionNormal.X * crossSectionPoint.X + crossSectionNormal.Y * crossSectionPoint.Y) )); }
static Octagonal() { _verticesRaw = new PointD2D[8]; _normalsRaw = new VectorD2D[16]; double f = 1 / Math.Cos(0.5 * Math.PI / (4)); for (int i = 0; i < 8; ++i) { var phiV = (0.5 + i) * Math.PI / (4); _verticesRaw[i] = new PointD2D(f * Math.Cos(phiV), f * Math.Sin(phiV)); var phiN = (i) * Math.PI / (4); _normalsRaw[2 * i] = _normalsRaw[(2 * i + 15) % 16] = new VectorD2D(Math.Cos(phiN), Math.Sin(phiN)); } }
public VectorD2D Normals(int idx) { switch (idx) { case 0: return(new VectorD2D(-1, 0)); case 1: return(new VectorD2D(-1, 0)); case 2: return(VectorD2D.CreateNormalized(1, 1)); case 3: return(VectorD2D.CreateNormalized(1, 1)); default: throw new IndexOutOfRangeException(); } }
public VectorD2D Normals(int i) { double phi = i * (2 * Math.PI / _numberOfVertices); return(VectorD2D.CreateNormalized(_radius2 * Math.Cos(phi), _radius1 * Math.Sin(phi))); }
/// <summary> /// Transforms the specified vector <paramref name="v"/>. For a vector transform, the offset elements M41..M43 are ignored. /// The transformation is carried out as a prepend transformation, i.e. result = v * matrix (v considered as horizontal vector). /// </summary> /// <param name="v">The vector to transform. The z component is assumed to be 0.</param> /// <returns>The transformed vector.</returns> public VectorD3D Transform(VectorD2D v) { double x = v.X; double y = v.Y; return new VectorD3D( x * M11 + y * M21, x * M12 + y * M22, x * M13 + y * M23 ); }
/// <summary> /// Creates a transformation matrix that uses three basis vectors to construct the matrix that transform points expressed in the three basis vectors to points in /// the coordinate system. /// </summary> /// <param name="xBasis">Basis vector for the x-direction.</param> /// <param name="yBasis">Basis vector for the y-direction.</param> /// <returns>A transformation matrix that uses the three basis vectors, and a location</returns> public static Matrix2x2 NewFromBasisVectors(VectorD2D xBasis, VectorD2D yBasis) { return new Matrix2x2( xBasis.X, xBasis.Y, yBasis.X, yBasis.Y ); }
/// <summary> /// Calculates the normal to a extruded contour. Here the extrusion direction is fixed to z-direction. /// </summary> /// <param name="crossSectionPoint">Original cross section point coordinates.</param> /// <param name="crossSectionNormal">Original cross section normal.</param> /// <param name="contourNormal">Original contour normal.</param> /// <param name="contourZScale">Factor that is multiplied with the x-coordinate of the contour point to return the z-coordinate of the resulting contour.</param> /// <returns>The normal of the extruded contour (x-y is the cross section plane, z the extrusion direction). This vector has then to be transformed into the 3D-space of the body.</returns> protected static VectorD3D GetNormalVector(PointD2D crossSectionPoint, VectorD2D crossSectionNormal, VectorD2D contourNormal, double contourZScale) { return VectorD3D.CreateNormalized ( contourNormal.Y * crossSectionNormal.X * contourZScale, contourNormal.Y * crossSectionNormal.Y * contourZScale, contourNormal.X * (crossSectionNormal.X * crossSectionPoint.X + crossSectionNormal.Y * crossSectionPoint.Y) ); }