public bool passesZero() { float lineCenterX = (P1.X + P2.X) / 2; float lineCenterY = (P1.Y + P2.Y) / 2; float lineCenterZ = (P1.Z + P2.Z) / 2; var lineCenter = new Point3f(lineCenterX, lineCenterY, lineCenterZ); return(ZERO == lineCenter); }
public bool Equals(Point3f p) { // If parameter is null return false: if ((object)p == null) { return(false); } // Return true if the fields match: return((X == p.X) && (Y == p.Y) && (Z == p.Z)); }
public override bool Equals(object obj) { if (!(obj is Point3f)) { return(false); } Point3f p = (Point3f)obj; return(p == this); }
private void Border_MouseMove(object sender, MouseEventArgs e) { Point pos = e.GetPosition(sender as IInputElement); pos.X = (pos.X / (sender as Shape).Width) * 2 - 1; pos.Y = (pos.Y / (sender as Shape).Height) * 2 - 1; if (e.LeftButton == MouseButtonState.Pressed) { first = indexToPoint(indexFromObject(sender), pos); coordinatesChanged(); } if (e.RightButton == MouseButtonState.Pressed) { second = indexToPoint(indexFromObject(sender), pos); coordinatesChanged(); } }
private static Point3f[] getPointsWherePlaneCrossesEdges(Plain3D plain) { var list = new Point3f[EDGE_COUNT]; var i = 0; foreach (var c1 in EDGE_POSSIBLE_COORDINATES) { foreach (var c2 in EDGE_POSSIBLE_COORDINATES) { // will occur 4 times var x = (c1 * (plain.P3.X * plain.P2.Z - plain.P2.X * plain.P3.Z) + c1 * (plain.P2.X * plain.P3.Y - plain.P3.X * plain.P2.Y)) / (plain.P3.Y * plain.P2.Z - plain.P2.Y * plain.P3.Z); var y = (c1 * (plain.P2.Y * plain.P3.Z - plain.P3.Y * plain.P2.Z) + c2 * (plain.P2.X * plain.P3.Y - plain.P3.X * plain.P2.Y)) / (plain.P2.X * plain.P3.Z - plain.P3.X * plain.P2.Z); var z = (c1 * (plain.P2.Y * plain.P3.Z - plain.P3.Y * plain.P2.Z) + c2 * (plain.P2.Z * plain.P3.X - plain.P2.X * plain.P3.Z)) / (plain.P3.X * plain.P2.Y - plain.P2.X * plain.P3.Y); if (Math.Abs(x) <= 1) { list[i++] = new Point3f(x, c1, c2); } if (Math.Abs(y) <= 1) { list[i++] = new Point3f(c1, y, c2); } if (Math.Abs(z) <= 1) { list[i++] = new Point3f(c1, c2, z); } } } var result = new Point3f[i]; Array.Copy(list, result, i); return(result); }
private static List <List <Point3f> > calculateBestPaths(Point3f from, Point3f[] through, Point3f to) { var paths = new List <List <Point3f> >(); foreach (var p1 in through) { if (isOnOneEdge(from, p1)) { // three edge case if (isOnOneEdge(p1, to)) { var newList = new List <Point3f>(MAX_PATH_SIZE); newList.Add(from); newList.Add(p1); newList.Add(to); paths.Add(newList); } else { foreach (var p2 in through) { if (p1 != p2 && isOnOneEdge(p1, p2) && isOnOneEdge(p2, to)) { var newList = new List <Point3f>(MAX_PATH_SIZE); newList.Add(from); newList.Add(p1); newList.Add(p2); newList.Add(to); paths.Add(newList); break; } } } } } filterLongPaths(paths); return(paths); }
public List <List <Point3f> > getPath(Point3f from, Point3f to) { // 1 edge case if (isOnOneEdge(from, to)) { var lists = new List <List <Point3f> >(); var list = new List <Point3f>(new Point3f[] { from, to }); lists.Add(list); return(lists); } else if (new Line3D(from, to).passesZero()) { // TODO the case has my dick on it return(null); } else // multi edge { var plain = new Plain3D(from, to); var points = getPointsWherePlaneCrossesEdges(plain); return(calculateBestPaths(from, points, to)); } }
private static bool isOnOneEdge(Point3f from, Point3f to) { return(Math.Abs(from.X) == 1 && from.X == to.X || Math.Abs(from.Y) == 1 && from.Y == to.Y || Math.Abs(from.Z) == 1 && from.Z == to.Z); }
public Line3f(Point3f p1, Point3f p2, Point3f color) { this.p1 = p1; this.p2 = p2; this.color = color; }
public Line3f(Point3f p1, Point3f p2) : this(p1, p2, new Point3f(1.0f, 1.0f, 0.0f)) { }
/// <summary> /// P1 is always (0,0,0) /// </summary> /// <param name="p2"></param> /// <param name="p3"></param> public Line3D(Point3f p1, Point3f p2) { this.P1 = p1; this.P2 = p2; }
/// <summary> /// P1 is always (0,0,0) /// </summary> /// <param name="p2"></param> /// <param name="p3"></param> public Plain3D(Point3f p2, Point3f p3) { this.P1 = new Point3f(0, 0, 0); this.P2 = p2; this.P3 = p3; }
public Point3f Subtract(Point3f other) { return(new Point3f(this.X - other.X, this.Y - other.Y, this.Z - other.Z)); }
public Point3f Add(Point3f other) { return(new Point3f(this.X + other.X, this.Y + other.Y, this.Z + other.Z)); }