private static bool smethod_10( Vector2D dp01, Vector2D dp12, Vector2D dp23, Vector2D dp03, double epsilonSquared) { double lengthSquared = dp03.GetLengthSquared(); if (1.0 / 9.0 * lengthSquared <= epsilonSquared) { if (dp01.GetLengthSquared() <= epsilonSquared && dp12.GetLengthSquared() <= epsilonSquared) { return(dp23.GetLengthSquared() <= epsilonSquared); } return(false); } double num = epsilonSquared * lengthSquared; if (ShapeTool.smethod_6(Vector2D.CrossProduct(dp01, dp03)) <= num) { return(ShapeTool.smethod_6(Vector2D.CrossProduct(dp23, dp03)) <= num); } return(false); }
public void Vector2D2x2() { var vector1 = new Vector2D(2, 3); var vector2 = new Vector2D(4, 5); vector1.CrossProduct(vector2).AssertEquals(0, 0, -2); }
public void Vector2D2x3() { var vector2D = new Vector2D(4, 5); var vector3D = new Vector3D(1, 2, 3); vector2D.CrossProduct(vector3D).AssertEquals(15, -12, 3); }
// Per https://stackoverflow.com/questions/11907947/how-to-check-if-a-point-lies-on-a-line-between-2-other-points public static bool IsOn(this Point2D point, LineSegment2D segment) { Vector2D toPoint = segment.StartPoint.VectorTo(point); Vector2D toEnd = segment.ToVector2D(); var cross = toPoint.CrossProduct(toEnd); // TODO Luke to determine best way to calculate collinearity tolerance if (Math.Abs(cross) > 1e-5) { return(false); } if (Math.Abs(toEnd.X) >= Math.Abs(toEnd.Y)) { return((toEnd.X > 0) ? segment.StartPoint.X <= point.X && point.X <= segment.EndPoint.X : segment.EndPoint.X <= point.X && point.X <= segment.StartPoint.X); } else { return((toEnd.Y > 0) ? segment.StartPoint.Y <= point.Y && point.Y <= segment.EndPoint.Y : segment.EndPoint.Y <= point.Y && point.Y <= segment.StartPoint.Y); } }
private double testBetter(double k1, Point2D p0, Point2D p1) { Vector2D G = p1 - p0; Point2D p21 = new Point2D(GetCoord(k1)[0], GetCoord(k1)[1]); Vector2D T1 = p21 - p0; return(Math.Abs(G.CrossProduct(T1))); }
public Point2D CalculateIntersection(LineSegment2D another) { //https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect Vector2D q = new Vector2D(P1.X, P1.Y); Vector2D p = new Vector2D(another.P1.X, another.P1.Y); Vector2D r = new Vector2D(P2.X - P1.X, P2.Y - P1.Y); Vector2D s = new Vector2D(another.P1.X - another.P2.X, another.P1.Y - another.P2.Y); var v = q - p; var rxs = r.CrossProduct(s); var qpxr = v.CrossProduct(r); double t = v.CrossProduct(s) / (r.CrossProduct(s)); double u = (p - q).CrossProduct(r) / (r.CrossProduct(s)); if (rxs == 0 && qpxr != 0) { return(null); } else if (rxs != 0 && t >= 0 && t <= 1 && u >= 0 && u <= 1) { var tr = t * r; return(new Point2D(P1.X + tr.X, P1.Y + tr.Y)); } else if (rxs == 0 && qpxr == 0) { var t0 = (q - p) * r / (r * r); var t1 = t0 + (s * r) / (r * r); if ((s * r) < 0) { var temp = t1; t1 = t0; t0 = t1; } if ((t0 >= 0 && t0 <= 1) || (t1 >= 0 && t1 <= 1)) { var res = (s - q) * t0; return(new Point2D(res.X, res.Y)); //colinear lines.... } } return(null); }
public void CrossProduct2DExample() { var vector1 = new Vector2D(6, 3); var vector2 = new Vector2D(4, 5); IVector <double> vector = vector1.CrossProduct(vector2); Assert.AreEqual(0, vector[0]); Assert.AreEqual(0, vector[1]); Assert.AreEqual(18, vector[2]); }
public void Vector2D2x2() { var vector1 = new Vector2D(2, 3); var vector2 = new Vector2D(4, 5); IVector <double> vector = vector1.CrossProduct(vector2); Assert.AreEqual(0, vector[0]); Assert.AreEqual(0, vector[1]); Assert.AreEqual(-5, vector[2]); }
public void Vector2D2x3() { var vector2D = new Vector2D(4, 5); var vector3D = new Vector3D(1, 2, 3); IVector <double> vector = vector2D.CrossProduct(vector3D); Assert.AreEqual(15, vector[0]); Assert.AreEqual(-12, vector[1]); Assert.AreEqual(3, vector[2]); }
public void Vector2D2x2_Returns_Non_Zero_Vector_When_Left_Y_Is_0() { var vector1 = new Vector2D(2, 0); var vector2 = new Vector2D(4, 5); vector1.CrossProduct(vector2).AssertEquals(0, 0, 10); vector1 = new Vector2D(2, 4); vector2 = new Vector2D(4, 0); vector1.CrossProduct(vector2).AssertEquals(0, 0, -16); }
public void IVector2x2() { var vector2D = new Vector2D(2, 3); var vectorN = new VectorN(2); vectorN.SetValues(4, 5); var vector = vector2D.CrossProduct(vectorN); Assert.AreEqual(0, vector[0]); Assert.AreEqual(0, vector[1]); Assert.AreEqual(-5, vector[2]); }
public void IVector2x3() { var vector2D = new Vector2D(4, 5); var vectorN = new VectorN(3); vectorN.SetValues(1, 2, 3); var vector = vector2D.CrossProduct(vectorN); Assert.AreEqual(15, vector[0]); Assert.AreEqual(-12, vector[1]); Assert.AreEqual(3, vector[2]); }
private double[] SolveBetter(double k1, double k2, Point2D p0, Point2D p1, double offset = 0) { Vector2D G = p1 - p0; Vector2D CDir1 = new Vector2D(GetDir(k1)[0], GetDir(k1)[1]).Rotate(Angle.FromDegrees(90)); Vector2D CDir2 = new Vector2D(GetDir(k2)[0], GetDir(k2)[1]).Rotate(Angle.FromDegrees(90)); Point2D p21 = new Point2D(GetCoord(k1)[0], GetCoord(k1)[1]) + CDir1 * offset; Point2D p22 = new Point2D(GetCoord(k2)[0], GetCoord(k2)[1]) + CDir2 * offset; Vector2D T1 = p21 - p0; Vector2D T2 = p22 - p0; if (T1.DotProduct(T2) == 0) { throw new Exception("重合点无法求解"); } if (Math.Abs(G.CrossProduct(T1)) < Math.Abs(G.CrossProduct(T2))) { return(new[] { k1, 0.5 * (k1 + k2) }); } else { return(new[] { 0.5 * (k1 + k2), k2 }); } }
private bool method_0( double epsilon, Point2D segmentLastPoint2D, Point2D segmentFirstPoint2D, LinkedListNode <Point2D> segmentFirstPoint) { if (MathUtil.AreApproxEqual(segmentLastPoint2D.X, segmentFirstPoint2D.X) && MathUtil.AreApproxEqual(segmentLastPoint2D.Y, segmentFirstPoint2D.Y)) { double num = epsilon * epsilon; LinkedListNode <Point2D> linkedListNode = segmentFirstPoint; bool flag = true; for (int index = 1; index < this.int_0; ++index) { linkedListNode = linkedListNode.Next; Point2D point2D = linkedListNode.Value; if (new Vector2D(point2D.X - segmentFirstPoint2D.X, point2D.Y - segmentFirstPoint2D.Y).GetLengthSquared() > num) { flag = false; break; } } return(flag); } Vector2D u = new Vector2D(segmentLastPoint2D.X - segmentFirstPoint2D.X, segmentLastPoint2D.Y - segmentFirstPoint2D.Y); double length = u.GetLength(); double num1 = epsilon * length; LinkedListNode <Point2D> linkedListNode1 = segmentFirstPoint; bool flag1 = true; for (int index = 1; index < this.int_0; ++index) { linkedListNode1 = linkedListNode1.Next; Point2D point2D = linkedListNode1.Value; Vector2D v = new Vector2D(point2D.X - segmentFirstPoint2D.X, point2D.Y - segmentFirstPoint2D.Y); if (System.Math.Abs(Vector2D.CrossProduct(u, v)) > num1) { flag1 = false; break; } } return(flag1); }
private static bool smethod_9( Vector2D dp01, Vector2D dp12, Vector2D dp02, double epsilonSquared) { double lengthSquared = dp02.GetLengthSquared(); if (0.25 * lengthSquared <= epsilonSquared) { if (dp01.GetLengthSquared() <= epsilonSquared) { return(dp12.GetLengthSquared() <= epsilonSquared); } return(false); } double num = epsilonSquared * lengthSquared; return(ShapeTool.smethod_6(Vector2D.CrossProduct(dp01, dp02)) <= num); }
public Class92(Arc2D arc) { double num1 = arc.endAngle - arc.startAngle; if (num1 < 0.0 || num1 > 2.0 * System.Math.PI) { double num2 = System.Math.Floor(num1 / (2.0 * System.Math.PI)); num1 -= 2.0 * num2 * System.Math.PI; } int num3 = (int)System.Math.Ceiling(2.0 * num1 / System.Math.PI) + 1; if (num3 >= 5) { num3 = 4; num1 = 2.0 * System.Math.PI; } double num4 = num1 / (double)num3; this.point2D_0 = new Point2D[1 + 3 * num3]; double startAngle = arc.StartAngle; Vector2D u = arc.Radius * new Vector2D(System.Math.Cos(startAngle), System.Math.Sin(startAngle)); this.point2D_0[0] = arc.Center + u; int num5 = 0; for (int index = 0; index < num3; ++index) { startAngle += num4; Vector2D v = arc.Radius * new Vector2D(System.Math.Cos(startAngle), System.Math.Sin(startAngle)); this.point2D_0[num5 + 3] = arc.Center + v; double lengthSquared = u.GetLengthSquared(); double num2 = lengthSquared + Vector2D.DotProduct(u, v); double num6 = Vector2D.CrossProduct(u, v); double num7 = 4.0 / 3.0 * (System.Math.Sqrt(2.0 * lengthSquared * num2) - num2) / num6; this.point2D_0[num5 + 1] = new Point2D(arc.Center.X + u.X - num7 * u.Y, arc.Center.Y + u.Y + num7 * u.X); num5 += 3; this.point2D_0[num5 - 1] = new Point2D(arc.Center.X + v.X - num7 * v.Y, arc.Center.Y + v.Y + num7 * v.X); u = v; } }
public void ExcetionNullVector3D() { var vector = new Vector2D(); vector.CrossProduct((Vector3D)null); }
public Class462(Polyline3D polyline) { this.polyline3D_0 = polyline; this.ilist_0 = Class455.smethod_3(polyline, out this.point2D_0, out this.point2D_1); this.double_0 = 0.0; int count = polyline.Count; List <Point3D> point3DList = new List <Point3D>(3); if (count > 0) { Point3D point3D1 = polyline[count - 1]; point3DList.Add(point3D1); if (count == 2) { Point3D point3D2 = polyline[0]; if (point3D2.X != point3D1.X || point3D2.Y != point3D1.Y) { point3DList.Add(point3D2); } } else { Point3D point3D2 = point3D1; Vector2D?nullable1 = new Vector2D?(); Vector2D?nullable2 = new Vector2D?(); for (int index = 0; index < count; ++index) { Point3D point3D3 = polyline[index]; this.double_0 += point3D2.X * point3D3.Y - point3D3.X * point3D2.Y; Vector2D vector2D = (Vector2D)(point3D3 - point3D1); double length = vector2D.GetLength(); if (length > 0.0) { Vector2D v = vector2D / length; if (!nullable1.HasValue) { nullable1 = new Vector2D?(v); point3DList.Add(point3D3); } else if (!nullable2.HasValue && System.Math.Abs(Vector2D.CrossProduct(nullable1.Value, v)) > 1E-06) { nullable2 = new Vector2D?(v); point3DList.Add(point3D3); } } point3D2 = point3D3; } this.double_0 *= 0.5; } if (point3DList.Count > 2) { Vector3D vector3D1 = point3DList[1] - point3DList[0]; Vector3D vector3D2 = point3DList[2] - point3DList[0]; double num = vector3D2.X * vector3D1.Y - vector3D1.X * vector3D2.Y; this.double_1 = (vector3D2.Z * vector3D1.Y - vector3D1.Z * vector3D2.Y) / num; this.double_2 = (vector3D1.Z * vector3D2.X - vector3D2.Z * vector3D1.X) / num; } else if (point3DList.Count == 2) { Vector3D vector3D = point3DList[1] - point3DList[0]; if (System.Math.Abs(vector3D.X) >= System.Math.Abs(vector3D.Y)) { this.double_1 = vector3D.Z / vector3D.X; this.double_2 = 0.0; } else { this.double_1 = 0.0; this.double_2 = vector3D.Z / vector3D.Y; } } else { double num = 0.0; this.double_2 = 0.0; this.double_1 = num; } this.double_3 = point3D1.Z - this.double_1 * point3D1.X - this.double_2 * point3D1.Y; } else { double num1 = 0.0; this.double_2 = 0.0; double num2 = num1; double num3 = 0.0; this.double_1 = num2; this.double_3 = num3; } this.bool_0 = this.double_0 == 0.0; }
public double CrossProduct() { return(P1.CrossProduct(P2)); }
public static LuaVector2D CrossProduct(LuaVector2D a, LuaVector2D b) { return(new LuaVector2D(Vector2D.CrossProduct(a.vec, b.vec))); }
public void ExceptionNullVector3D() { var vector = new Vector2D(); Assert.Throws <ArgumentNullException>(() => vector.CrossProduct((Vector3D)null)); }