protected MatrixSet(Vector vector) { Val = new double[vector.Dimension][]; for (int i = 0; i < vector.Dimension; i++) { Val[i] = new double[1]; Val[i][0] = vector[i]; } row = vector.Dimension; col = 1; }
public Line2D(Vector v) { if (v.Dimension != 3) { throw (new ArgumentException()); } if (v[0] == 0 && v[1] == 0) { throw (new ArgumentException()); } vector[0] = v[0]; vector[1] = v[1]; vector[2] = v[2]; }
public LinearSystem(SquaredMatrix coe, Vector v) { if (coe.Size != v.Dimension) { throw (new ArgumentException()); } Vector[] vectors = new Vector[coe.Size + 1]; for (int i = 0; i < coe.Size; i++) { vectors[i] = coe.Cols[i]; } vectors[coe.Size] = v; this.LMatrix = new Matrix(vectors); this.size = this.LMatrix.Col - 1; }
/// <summary> /// Get the intersect point of the two lines. /// </summary> /// <param name="line">the other line.</param> /// <returns>the point.</returns> public Point2D Intersects(Line2D line) { if (this.GetPosition(line) != Position.Intersect) { //throw (new ArgumentException("The two lines cannot Intersects!")); return new Point2D(double.PositiveInfinity, double.PositiveInfinity); } Vector v1 = null; Vector v2 = null; if (Math.Abs(this.A) > Math.Abs(line.A)) { v1 = new Vector(this.vector); v2 = new Vector(line.vector); } else { v1 = new Vector(line.vector); v2 = new Vector(this.vector); } Vector v3 = new Vector(v1); v1 = Vector.Multiply(v2[0] / v1[0], v1); v1 = Vector.Subtract(v1, v2); v1 = Vector.Multiply(1/v1[1], v1); Point2D point = new Point2D(new Line2D(v3).GetX(-v1[2]), -v1[2]); if (!this.Contains(point) || !line.Contains(point)) { throw (new ArgumentException()); } return point; }
/// <summary> /// Discribe the position of the two lines. /// </summary> /// <param name="line">the other line.</param> /// <returns>the position.</returns> public Position GetPosition(Line2D line) { if (this.A == 0 && line.A == 0) { if (this.B * line.C != this.C * line.B) { return Position.Parallel; } else { return Position.Superposition; } } if (this.B == 0 && line.B == 0) { if (this.A * line.C != this.C * line.A) { return Position.Parallel; } else { return Position.Superposition; } } Vector v1 = null; Vector v2 = null; if (Math.Abs(this.A) > Math.Abs(line.A)) { v1 = new Vector(this.vector); v2 = new Vector(line.vector); } else { v1 = new Vector(line.vector); v2 = new Vector(this.vector); } v1 = Vector.Multiply(v2[0] / v1[0], v1); v1 = Vector.Subtract(v1,v2); if (Math.Abs(v1[1]) < Line2D.ZeroTolerance && Math.Abs(v1[2]) < Line2D.ZeroTolerance) { return Position.Superposition; } else if (Math.Abs(v1[1]) < Line2D.ZeroTolerance) { return Position.Parallel; } else { return Position.Intersect; } }
public Matrix(Vector[] vectors) : base(vectors) { }
public Matrix(Vector vector) : base(vector) { }
/// <summary> /// Subtracts a vector from a point to produce a new point. /// </summary> /// <param name="a">A point.</param> /// <param name="b">A vector.</param> /// <returns>The point <paramref name="a"/> - <paramref name="b"/>.</returns> public static Point Subtract(PointSet a, Vector b) { return Subtract(a, b.ToPoint()).ToPoint(); }
private Matrix2D(Vector[] vectors) : base(vectors) { }
/// <summary> /// Subtracts a matrix from a matrix to produce a new matrix. /// </summary> /// <param name="a">The first matrix.</param> /// <param name="b">The second matrix.</param> /// <returns>The matrix <paramref name="a"/> - <paramref name="b"/>.</returns> public static Matrix Subtract(MatrixSet a, MatrixSet b) { if (a.Dimension != b.Dimension) { throw (new DimensionsNotEqualException()); } Vector[] vectors = new Vector[a.Col]; for (int i = 0; i < a.Col; i++) { vectors[i] = new Vector(a.Cols[i] - b.Cols[i]); } return new Matrix(vectors); }
/// <summary> /// Multiplies a matrix by a scalar to produce a new matrix. /// </summary> /// <param name="a">A scalar.</param> /// <param name="b">A matrix.</param> /// <returns>The matrix <paramref name="a"/>*<paramref name="b"/>.</returns> public static Matrix Multiply(double a, MatrixSet b) { Vector[] vectors = new Vector[b.Col]; for (int i = 0; i < b.Col; i++) { vectors[i] = new Vector(a * b.Cols[i]); } return new Matrix(vectors); }
/// <summary> /// Multiplies a vector by a scalar to produce a new vector. /// </summary> /// <param name="a">A scalar.</param> /// <param name="b">A vector.</param> /// <returns>The vector <paramref name="a"/>*<paramref name="b"/>.</returns> public static Vector Multiply(double a, VectorSet b) { Vector v = new Vector(b.Dimension); for (int i = 0; i < b.Dimension; i++) { v[i] = b[i] * a; } return v; }
/// <summary> /// Adds two vectors to produce a new vector. /// </summary> /// <param name="a">The first vector.</param> /// <param name="b">The second vector.</param> /// <returns>The vector <paramref name="a"/> + <paramref name="b"/>.</returns> public static Vector Add(VectorSet a, VectorSet b) { if (a.Dimension != b.Dimension) { throw (new DimensionsNotEqualException()); } Vector v = new Vector(a.Dimension); for (int i = 0; i < ((VectorSet)a).Dimension; i++) { v[i] = a[i] + b[i]; } return v; }
public void Fitting() { GhostWeb ghostWeb = new GhostWeb(this.sourcePolygon, this.ghostTriangles); Vector[] vectors = new Vector[this.sourcePolygon.PointCount]; for (int i = 0; i < vectors.Length; i++) { vectors[i] = new Vector(vectors.Length); vectors[i][i] = 1; if (i < this.sourcePolygon.VertexCount || this.sourcePolygon.isOnEdge(this.sourcePolygon.GetPoint(i))) { continue; } else { vectors[i][i] = 0; WebNode webNode = ghostWeb.webNodes[i]; while (webNode!= null) { vectors[i][i] ++; vectors[i][webNode.firstIndex] = -1; vectors[i][webNode.secondIndex] = -1; webNode = webNode.Next; } } } Vector valx = new Vector(this.sourcePolygon.PointCount); Vector valy = new Vector(this.sourcePolygon.PointCount); for (int i = 0; i < this.targetPolygon.VertexCount; i++) { valx[i] = this.targetPolygon.GetPoint(i).X; valy[i] = this.targetPolygon.GetPoint(i).Y; } for (int i = this.sourcePolygon.VertexCount; i <this.sourcePolygon.PointCount; i++) { Point2D point = this.sourcePolygon.GetPoint(i); if(this.sourcePolygon.isOnEdge(point)) { int x = this.sourcePolygon.OnEdge(point); LineSegment2D line = this.sourcePolygon.GetEdge(x); double pos = line.GetPosition(point); line = this.targetPolygon.GetEdge(x); Point2D newPoint = line.GetPoint(pos); valx[i] = newPoint.X; valy[i] = newPoint.Y; } } Matrix m = new Matrix(vectors).Translate(); UpdateStatus(this, "Constructing..."); LinearSystem lsx = new LinearSystem(new Matrix(m), valx); UpdateStatus(this, "Done"); lsx.UpdateStatus += new Microsoft.VS.Akira.Triangulations.LinearSystem.ShowStatus(UpdateStatus); lsx.Gaussian(this.sourcePolygon.VertexCount); LinearSystem lsy = new LinearSystem(new Matrix(m), valy); lsy.UpdateStatus += new Microsoft.VS.Akira.Triangulations.LinearSystem.ShowStatus(UpdateStatus); lsy.Gaussian(this.sourcePolygon.VertexCount); Polygon2DEditor pe = new Polygon2DEditor(this.targetPolygon); UpdateStatus(this, "AddInner.."); for (int i = this.sourcePolygon.VertexCount; i < this.sourcePolygon.PointCount; i++) { Point2D point = new Point2D(lsx.Value[i], lsy.Value[i]); pe.AddInnerPoint(point); } UpdateStatus(this, "Done"); }
/// <summary> /// Move a point to a new place throught a vector. /// </summary> /// <param name="v">The vector specified the path to move.</param> /// <returns>The new site of this point.</returns> public Point MoveForward(Vector v) { Add(this, v).Values.CopyTo(this.Values, 0); return (Point)this; }
/// <summary> /// Move a point back to a previous place throught a vector /// </summary> /// <param name="v">The vector specified the path to move.</param> /// <returns>The new site of this point.</returns> public Point MoveBack(Vector v) { Subtract(this, v).Values.CopyTo(this.Values, 0); return (Point)this; }
private SquaredMatrix(Vector[] vectors) : base(vectors) { }
protected MatrixSet(Vector[] vectors) { col = vectors.Length; row = vectors[0].Dimension; Val = new double[row][]; for (int i = 0; i < row; i++) { Val[i] = new double[col]; } int j = 0; foreach (Vector vector in vectors) { for (int i = 0; i < vector.Dimension; i++) { Val[i][j] = vector[i]; } j++; } }
/// <summary> /// Convert a Vector to a Vector2D. /// </summary> /// <param name="vector">the vector.</param> /// <returns>the vector2D.</returns> public static Vector2D ConvertFromVector(Vector vector) { if (vector.Dimension == 2) { return new Vector2D(vector.Values); } else { return null; } }
/// <summary> /// Adds a point and a vector to produce a new point. /// </summary> /// <param name="a">A point.</param> /// <param name="b">A vector.</param> /// <returns>The point <paramref name="a"/> + <paramref name="b"/>.</returns> public static Point Add(PointSet a, Vector b) { return Vector.Add(a.ToVector(), b).ToPoint(); }