Exemplo n.º 1
0
 public Line2D GetNormalLine(Point2D point)
 {
     double c = EqB*point.X - EqA*point.Y;
     var tempLine = new Line2D(-EqB, EqA, c, Normal, point);
     Point2D crossPoint = Geometry.GetCrossing(this, tempLine);
     return new Line2D(crossPoint, point);
 }
Exemplo n.º 2
0
 public Frame2D(double x, double y, Angle angle)
 {
     X = x;
     Y = y;
     Angle = angle;
     Center = new Point2D(x, y);
 }
Exemplo n.º 3
0
 public static bool GetCrossing(Segment2D segment1, Segment2D segment2, out Point2D crossingPoint)
 {
     var line1 = new Line2D(segment1.Start, segment1.Finish);
     var line2 = new Line2D(segment2.Start, segment2.Finish);
     crossingPoint = GetCrossing(line1, line2);
     var p = (crossingPoint.X - segment1.Finish.X) / (segment1.Start.X - segment1.Finish.X);
     return (0 <= p && p <= 1) && (crossingPoint.Y.Equals((p * segment1.Start.Y - (1 - p) * segment1.Finish.Y)));
 }
Exemplo n.º 4
0
 private Line2D(double a, double b, double c, Point2D direction, Point2D start)
 {
     Begin = start;
     End = new Point2D();
     Direction = direction;
     Normal = new Point2D(-direction.Y, direction.X);
     EqA = a;
     EqB = b;
     EqC = c;
     IsEmpty = false;
 }
Exemplo n.º 5
0
 public Line2D(Point2D begin, Point2D end)
 {
     Begin = begin;
     End = end;
     Direction = end - begin;
     Normal = new Point2D(-Direction.Y, Direction.X);
     EqA = Normal.X;
     EqB = Normal.Y;
     EqC = -EqA*begin.X - EqB*begin.Y;
     IsEmpty = Direction.IsEmpty;
 }
Exemplo n.º 6
0
        public void CreateBeachHut(string id, Point2D location, SideColor color)
        {
            var hut = GameObject.CreatePrimitive(PrimitiveType.Cube);

            Point3D size = new Point3D(12, 12, 16);

            hut.transform.position = new Vector3((float)location.X, (float)size.Z / 2, (float)location.Y);
            hut.transform.localScale = new Vector3((float)size.X, (float)size.Z, (float)size.Y);

            hut.GetComponent<Renderer>().material.color = GetDrawingColor(color);
            hut.name = id;
        }
Exemplo n.º 7
0
 /// <summary>
 ///   Формула Герона для вычисления площади треугольника
 /// </summary>
 /// <param name="A"> Вершина А </param>
 /// <param name="B"> Вершина В </param>
 /// <param name="C"> Вершина С </param>
 /// <returns> </returns>
 public static double GetTriangleSquareByGeron(Point2D A, Point2D B, Point2D C)
 {
     if (!A.IsEmpty && !B.IsEmpty && !C.IsEmpty)
     {
         double a = Point2D.GetDistance(A, B);
         double b = Point2D.GetDistance(B, C);
         double c = Point2D.GetDistance(C, A);
         double p = (a + b + c)/2;
         return Math.Sqrt(p*(p - a)*(p - b)*(p - c));
     }
     return 0;
 }
Exemplo n.º 8
0
 public Sector(Circle2D circle2D, Point2D start, Point2D finish) : this()
 {
     if (PointOnCircle(start, circle2D) && PointOnCircle(finish, circle2D))
     {
         Finish = finish;
         Start = start;
         Circle = circle2D;
         Angle = new Triangle2D(Circle.Center, Start, Finish).AngleA;
         if (double.IsNaN(Angle.Radian))
             Angle = Angle.Zero;
         return;
     }
     throw new Exception("Не возможно создать сектор");
 }
Exemplo n.º 9
0
 /// <summary>
 ///   Получить угол дуги окружности, ограниченной точкой (0, 0) и заданной точкой на этой окружности
 /// </summary>
 /// <param name="point"> Точка </param>
 /// <returns> Угол </returns>
 public static Angle GetAngleOfArc(Point2D point)
 {
     return Angle.FromRad(Math.Abs(point.X) <= Double.Epsilon
                              ? Math.PI/2
                              : 2*Math.Atan2(point.Y, point.X)); //????
 }
Exemplo n.º 10
0
 public static Angle AngleBetweenVectors(Point2D firstVector, Point2D secondVector) {
     return AngleBetweenVectors(firstVector.ToPoint3D(), secondVector.ToPoint3D());
 }
Exemplo n.º 11
0
 public void CreateWall(Point2D location, Point2D size)
 {
     var wall = GameObject.CreatePrimitive(PrimitiveType.Cube);
     float sizeZ = floorLevel;
     wall.transform.position = new Vector3((float)location.X, sizeZ / 2, (float)location.Y);
     wall.transform.localScale = new Vector3((float)size.X, sizeZ, (float)size.Y);
     wall.GetComponent<Renderer>().material.color = Color.white;
 }
Exemplo n.º 12
0
        public void CreateRock(Point2D location)
        {
            var rock = GameObject.CreatePrimitive(PrimitiveType.Cylinder);

            rock.transform.position = new Vector3((float)location.X, floorLevel, (float)location.Y);
            rock.transform.localScale = new Vector3(60, 4.4f, 60);
            rock.GetComponent<CapsuleCollider>().enabled = false;
            rock.AddComponent<MeshCollider>();
        }
Exemplo n.º 13
0
 public Seashell(Point2D position, SideColor color)
 {
     Position = position;
     Color = color;
 }
Exemplo n.º 14
0
 private static bool PointOnCircle(Point2D point, Circle2D c)
 {
     const double epsilon = 0.000001;
     double actualyR = point.GetDistanceTo(c.Center);
     return (actualyR < c.R + epsilon && actualyR > c.R - epsilon);
 }
Exemplo n.º 15
0
 public double GetDistanceTo(Point2D otherPoint)
 {
     return GetDistance(this, otherPoint);
     //return Math.Sqrt((X-otherPoint.X)*(X-otherPoint.X)+(Y-otherPoint.Y)*(Y-otherPoint.Y));
 }
Exemplo n.º 16
0
 public static double GetDistance(Point2D a, Point2D b)
 {
     return Math.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y));
 }
Exemplo n.º 17
0
 public bool Equals(Point2D other)
 {
     return this == other;
 }
Exemplo n.º 18
0
 public Point3D MultiplyVector(Point2D p)
 {
     return new Point3D(0, 0, X * p.Y - Y * p.X);
 }
Exemplo n.º 19
0
 public static Line2D FromDirection(Point2D begin, Point2D direction)
 {
     return new Line2D(begin, begin + direction);
 }
Exemplo n.º 20
0
 public static Point2D Orthonorm(Point2D vector, Point2D axis) {
     return (vector - Projection(vector, axis)).Normalize();
 }
Exemplo n.º 21
0
        public Segment2D(Point2D start, Point2D finish) : this()

        {
            Finish = finish;
            Start = start;
        }
Exemplo n.º 22
0
 public double MultiplyScalar(Point2D p)
 {
     return X * p.X + Y * p.Y;
 }
Exemplo n.º 23
0
 public Circle2D(Point2D center, double r) : this()
 {
     Center = center;
     R      = r;
 }
Exemplo n.º 24
0
 public Circle2D(Point2D center, double r) : this()
 {
     Center = center;
     R = r;
 }
Exemplo n.º 25
0
        private static Line2D GetBissektor(Point2D startBissector, Point2D leftPoint, Point2D rightPoint)
        {
//			//Достроим треугольник до равнобедренного
//			double alpha = startBissector.GetDistanceTo(leftPoint) / startBissector.GetDistanceTo(rightPoint);
//			Point2D newLeftPoint = startBissector + (1 / alpha) * (leftPoint - startBissector);
//
//			var expected = startBissector.GetDistanceTo(newLeftPoint) - startBissector.GetDistanceTo(rightPoint);
//			Assert.That(expected, Is.LessThan(0.1).And.GreaterThan(-0.1));
//
//			//Теорема. В равнобедренном треугольнике медиана == биссектрисе
//			//Утверждение: найденная медиана и будет нужной нам прямой
//
//			Point2D middle = (newLeftPoint + rightPoint) / 2;
//
//			//Но точка middle не лежит на треугольнике... найдем ту что лежит
//
//			Line2D line = new Line2D(leftPoint, rightPoint);
//			Line2D fakeBissector = new Line2D(startBissector, middle);
//
//			Point2D finishBissector = Geometry.GetCrossing(line, fakeBissector);
//			return new Line2D(startBissector, finishBissector);

            double left = startBissector.GetDistanceTo(leftPoint);
            double right = startBissector.GetDistanceTo(rightPoint);

            double alpha = left/(left + right);

            Point2D finishBissector = leftPoint*(1 - alpha) + rightPoint*alpha;

            return new Line2D(startBissector, finishBissector);
        }
Exemplo n.º 26
0
        public void CreateFish(string id, Point2D location, SideColor color)
        {
            var fish = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            fish.transform.position = new Vector3((float)location.X, floorLevel + 5, (float)location.Y);
            fish.transform.localScale = new Vector3(5.3f, 5.3f, 9.7f);

            fish.GetComponent<Renderer>().material.color = GetDrawingColor(color);

            fish.AddComponent<Rigidbody>();
            fish.GetComponent<Rigidbody>().drag = fish.GetComponent<Rigidbody>().angularDrag = 4;
            fish.GetComponent<Rigidbody>().useGravity = true;
            fish.GetComponent<Rigidbody>().mass = 0.3f;
            fish.name = id;
        }
Exemplo n.º 27
0
 /// <summary>
 /// Возвращает точку пересечения луча и треугольника p0p1p2
 /// </summary>
 /// <param name="p0">Вершина</param>
 /// <param name="p1">Вершина</param>
 /// <param name="p2">Вершина</param>
 /// <param name="ray">Луч</param>
 /// <returns></returns>
 public static Point3D? IntersectTriangle(Point3D p0, Point3D p1, Point3D p2, Ray ray)
 {
     var plane = new ePlane(p0, p1, p2); //Плоскость содержащая треугольник
     Point3D? point1 = IntersectPlane(plane, ray);
     if (point1 == null)
     {
         return null;
     }
     else
     {
         int i = ProjectPlane(plane); //Определяем куда проецировать треугольник
         Point2D point = ProjectPoint(i, point1.Value);
         Point2D v0 = ProjectPoint(i, p0);
         Point2D v1 = ProjectPoint(i, p1);
         Point2D v2 = ProjectPoint(i, p2);
         Point2D[] regionPoints = new Point2D[] {v0, v2, v1};
         return Geometry.IsFromRegion(point, regionPoints) ? point1 : null;
     }
 }
Exemplo n.º 28
0
        public void CreateSeashell(string id, Point2D location, SideColor color)
        {
            var seashell = GameObject.CreatePrimitive(PrimitiveType.Cylinder);

            var locationZ = Math.Abs(location.X) > 120 && location.Y < -70 ? floorLevel + 6 : floorLevel;
            seashell.transform.position = new Vector3((float)location.X, locationZ, (float)location.Y);
            seashell.transform.localScale = new Vector3(7.62f, 2.5f, 7.62f);

            seashell.GetComponent<Renderer>().material.color = GetDrawingColor(color);

            seashell.GetComponent<CapsuleCollider>().enabled = false;
            seashell.AddComponent<MeshCollider>();
            seashell.GetComponent<MeshCollider>().convex = true;

            seashell.AddComponent<Rigidbody>();
            seashell.GetComponent<Rigidbody>().drag = seashell.GetComponent<Rigidbody>().angularDrag = 4;
            seashell.GetComponent<Rigidbody>().useGravity = true;
            seashell.GetComponent<Rigidbody>().mass = 0.3f;

            seashell.name = id;
        }
Exemplo n.º 29
0
 /// <summary>
 ///   Получить радиус окружности, касающейся оси Х в (0, 0) и проходящей через заданную точку
 /// </summary>
 /// <param name="point"> Точка </param>
 /// <returns> Радиус </returns>
 public static double GetRadiusOfCircle(Point2D point)
 {
     return Math.Abs(0.5*(point.X*point.X + point.Y*point.Y)/point.Y);
 }
Exemplo n.º 30
0
 public Triangle2D(Point2D vertexA, Point2D vertexB, Point2D vertexC) : this()
 {
     VertexC = vertexC;
     VertexB = vertexB;
     VertexA = vertexA;
 }
Exemplo n.º 31
0
 public static bool AreCollinear(Point2D a, Point2D b) {
     return Math.Abs(a.MultiplyVector(b).Norm() - 0) < Epsilon;
 }