/// /// Applies the specified transformation to this polygon. /// /// <b>Note:</b> if the applied transformation performs a mirror operation /// the vertex order of this polygon is reversed. /// /// <param name="transform">the transformation to apply</param> /// /// <returns>this polygon</returns> /// public Polygon transform(Transform transform) { this.vertices.ForEach( (v) => { v.transform(transform); } ); IVector3d a = this.vertices[0].pos; IVector3d b = this.vertices[1].pos; IVector3d c = this.vertices[2].pos; this._csg_plane.normal = b.minus(a).crossed(c.minus(a)).normalized(); this._csg_plane.dist = this._csg_plane.normal.dot(a); this.plane = CSharpVecMath.Plane. fromPointAndNormal(centroid(), _csg_plane.normal); vertices.ForEach((vertex) => { vertex.normal = plane.getNormal(); }); if (transform.isMirror()) { // the transformation includes mirroring. flip polygon flip(); } return(this); }
/// <summary> /// Flips this polygon. /// </summary> /// <returns>this polygon</returns> /// public Polygon flip() { vertices.ForEach((vertex) => { vertex.flip(); }); vertices.Reverse(); _csg_plane.flip(); this.plane = plane.flipped(); return(this); }
/// <summary> /// Constructor. Creates a new polygon that consists of the specified /// vertices. /// /// <b>Note:</b> the vertices used to initialize a polygon must be coplanar /// and form a convex loop. /// </summary> /// <param name="vertices">polygon vertices</param> /// public Polygon(List <Vertex> vertices) { this.vertices = vertices; this._csg_plane = Plane.createFromPoints( vertices[0].pos, vertices[1].pos, vertices[2].pos); this.plane = CSharpVecMath.Plane. fromPointAndNormal(centroid(), _csg_plane.normal); validateAndInit(vertices); }
/// <summary> /// Translates this polygon. /// </summary> /// <param name="v">the vector that defines the translation</param> /// <returns>this polygon</returns> /// public Polygon translate(IVector3d v) { vertices.ForEach((vertex) => { vertex.pos = vertex.pos.plus(v); }); IVector3d a = this.vertices[0].pos; IVector3d b = this.vertices[1].pos; IVector3d c = this.vertices[2].pos; // TODO plane update correct? this._csg_plane.normal = b.minus(a).crossed(c.minus(a)); this.plane = CSharpVecMath.Plane. fromPointAndNormal(centroid(), _csg_plane.normal); return(this); }