public void Impulse(Line force)
 {
     var div = force / Mass;
     var cross = (CenterOfMass - force.Start).Normalize().Dot(div.Normalize());
     DTheta -= div.Length * cross / 3;
     Velocity += div * (1 - cross);
 }
        public override Scene OnLoadScene()
        {
            this.mEngine.RegisterUpdateHandler(new FPSLogger());

            Scene scene = new Scene(1);
            scene.Background = new ColorBackground(0.09804f, 0.6274f, 0.8784f);

            Random random = new Random(RANDOM_SEED);

            for (int i = 0; i < LINE_COUNT; i++)
            {
                float x1 = (float)(random.NextDouble() * CAMERA_WIDTH);
                float x2 = (float)(random.NextDouble() * CAMERA_WIDTH);
                float y1 = (float)(random.NextDouble() * CAMERA_HEIGHT);
                float y2 = (float)(random.NextDouble() * CAMERA_HEIGHT);
                float lineWidth = (float)(random.NextDouble() * 5);

                Line line = new Line(x1, y1, x2, y2, lineWidth);

                line.SetColor((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());

                scene.getLastChild().attachChild(line);
            }

            return scene;
        }
        public override void UpdateDependencies(double currentTime)
        {
            base.UpdateDependencies(currentTime);

            if (Visible)
            {
                if (_line == null)
                {
                    _line = new Line();
                    _circle = new Circle {Radius = Radius};

                    _circle.AttachTo(this, false);
                    _line.AttachTo(_circle, false);
                    _line.RelativePoint1 = new Point3D(0, 0);
                    _line.RelativePoint2 = new Point3D(Radius, 0);
                }

                if (!_added)
                {
                    ShapeManager.AddLine(_line);
                    ShapeManager.AddCircle(_circle);
                    _added = true;
                }
            }

            if (!Visible && _line != null)
            {
                ShapeManager.Remove(_line);
                ShapeManager.Remove(_circle);
                _added = false;
            }
        }
Exemple #4
0
 public override RealHitInfo DelayedHitCalc(Line by, HitInfo hit)
 {
     RealHitInfo realHit = new RealHitInfo();
     realHit.HitStuff = Surface;
     realHit.Pigment = Pigment;
     realHit.Normal = new Line();
     realHit.Normal.Start = by.Project(hit.HitDist);
     realHit.Normal.Direct.Dx = 0;
     realHit.Normal.Direct.Dy = 0;
     realHit.Normal.Direct.Dz = 0;
     switch (hit.SurfaceIndex)
     {
         case 0:
             Point hitLoc2 = inv.Apply(realHit.Normal.Start);
             realHit.Normal.Direct.Dx = hitLoc2.X;
             realHit.Normal.Direct.Dy = hitLoc2.Y;
             realHit.Normal.Direct.Dz = hitLoc2.Z;
             break;
         default:
             throw new InvalidOperationException("Invalid surface index in hitdata");
     }
     Vector before = realHit.Normal.Direct;
     realHit.Normal.Direct = trans.Apply(realHit.Normal.Direct);
     if (realHit.Normal.Direct.Dot(by.Direct) > 0)
     {
         realHit.Normal.Direct.ScaleSelf(-1.0);
     }
     return realHit;
 }
Exemple #5
0
 /// <summary>
 /// Adds string
 /// </summary>
 /// <param name="format"></param>
 /// <param name="args"></param>
 public void Add( Color color, string format, params object[] args )
 {
     Line line = new Line();
     line.text		= string.Format( format, args );
     line.color		= color;
     linesAccum.Add( line );
 }
        public override void UpdateDependencies(double currentTime)
        {
            base.UpdateDependencies(currentTime);

            if (Visible)
            {
                if (_line == null)
                {
                    _line = new Line();
                    _line.AttachTo(this, false);
                    _line.RelativePoint1 = new Point3D(0, 0);
                    _line.RelativePoint2 = new Point3D(Length * ScaleX, 0);
                }

                if (!_added)
                {
                    ShapeManager.AddLine(_line);
                    _added = true;
                }
                if (Math.Abs(_line.RelativePoint2.X - Length * ScaleX) > Double.Epsilon)
                {
                    _line.RelativePoint2.X = Length;
                }
            }

            if (!Visible && _line != null)
            {
                ShapeManager.Remove(_line);
                _added = false;
            }
        }
Exemple #7
0
        public void DataAccess_IOrmModelSingleGet()
        {
            Line line = new Line();
            line = (Line)line.Get<Line>(1);

            Assert.AreEqual(line.Title, "Lemongrass and Lavender");
        }
 public void DrawLine (Line line, ConsoleColor? color = null, LineWidth lineWidth = LineWidth.Single)
 {
     if (line.IsHorizontal)
         DrawHorizontalLine(line.X, line.Y, line.Width, color, lineWidth);
     else if (line.IsVertical)
         DrawVerticalLine(line.X, line.Y, line.Height, color, lineWidth);
 }
Exemple #9
0
 public DrawableLine()
     : base("DrawableLine", Layer.Opaque)
 {
     line = new Line();
     line.StartColor = Color.Yellow;
     line.EndColor = Color.Yellow;
 }
Exemple #10
0
        public void ExecuteCommand()
        {
            barDiameter = TryGetBarDiameter("\nŚrednica pręta [mm] : ");
            if (!barDiameter.HasValue)
                return;

            spanStep = TryGetSpanStep("\nRozstaw [mm] : ");
            if (!spanStep.HasValue)
                return;

            barPoint1 = TryGetPoint("\nPokaż pręt 1 : ");
            if (!barPoint1.HasValue)
                return;

            barPoint2 = TryGetPoint("\nPokaż pręt 2 : ", barPoint1);
            if (!barPoint2.HasValue)
                return;

            firstBarLine = GetRoundBarLine(roundValue);
            if (TryDisplayBarLadder())
            {
                string blockName = CreateBlockRecord();
                Handle handle = InsertBlock(blockName);
                SetXData(handle);
            }
            else
            {
                return;
            }
        }
Exemple #11
0
 public static bool GetClosestPoint(Line line, Vector3F point, out Vector3F closestPointOnLine)
 {
     float parameter;
       GetLineParameter(new LineSegment(line.PointOnLine, line.PointOnLine + line.Direction), point, out parameter);
       closestPointOnLine = line.PointOnLine + parameter * line.Direction;
       return Vector3F.AreNumericallyEqual(point, closestPointOnLine);
 }
        /// <summary>
        /// Devuelve una secuencia de ReadOnlyLine explotando la entidad si es necesario.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="secuenciaOriginal"></param>
        /// <returns></returns>
        public static IEnumerable<ReadOnlyLine> ExplotaAReadOnlyLine(this Entity entidad)
        {
            if (entidad is ReadOnlyLine)
                yield return entidad as ReadOnlyLine;

            if (entidad is ReadOnlyPolygon)
            {
                ReadOnlyPolygon polígono = entidad as ReadOnlyPolygon;

                // Devolvemos primero el contorno exterior como una línea cerrada
                Line línea = new Line(polígono.Codes);
                línea.Points.Add(polígono.Points);
                yield return línea;

                // Devolvemos cada uno de los huecos que son líneas cerradas
                foreach (var hueco in polígono.Holes)
                    yield return hueco;
            }

            if (entidad is ReadOnlyComplex)
            {
                ReadOnlyComplex complejo = entidad as ReadOnlyComplex;

                foreach (var subentidad in complejo.Entities)
                {
                    if (subentidad is ReadOnlyLine)
                        yield return subentidad as ReadOnlyLine;
                }
            }

            yield break;
        }
Exemple #13
0
 ///<summary>
 ///The proportion that, when lerped across the given line, results in the given point.
 ///If the point is not on the line segment, the result is the closest point on the extended line.
 ///</summary>
 public static double LerpProjectOnto(this Vector2d point, Line line)
 {
     return line.NearestT(point, false);
     /*var b = point - line[0];
     var d = line.Delta;
     return (b * d) / (d * d);*/
 }
        public void GivenAnOrderDiscount_WhenApplyToNonOrder_ThenShouldReturnZero()
        {
            var sut = new OrderDiscount("d", 1);
            var line = new Line(new Bike(string.Empty, string.Empty, 1), 1);

            Assert.AreEqual(0, sut.Apply(line));
        }
Exemple #15
0
        public void LineIntersection()
        {
            Line horizontalLine = new Line(new Vector2D(0.0f, 1.0f), new Vector2D(2.0f, 1.0f));
            Line verticalLine = new Line(new Vector2D(1.0f, 0.0f), new Vector2D(1.0f, 2.0f));

            Assert.IsTrue(horizontalLine.TestIntersection(verticalLine));
            Assert.IsTrue(horizontalLine.TestIntersection(horizontalLine));
            Assert.IsTrue(verticalLine.TestIntersection(verticalLine));

            Line offsetHorizontalLine = new Line(new Vector2D(0.0f, 3.0f), new Vector2D(2.0f, 3.0f));

            Assert.IsFalse(offsetHorizontalLine.TestIntersection(horizontalLine));

            Line reverseHorizontalLine = new Line(new Vector2D(2.0f, 1.0f), new Vector2D(0.0f, 1.0f));
            Line reverseVerticalLine = new Line(new Vector2D(1.0f, 2.0f), new Vector2D(1.0f, 0.0f));
            Line reverseOffsetHorizontalLine = new Line(new Vector2D(0.0f, 3.0f), new Vector2D(2.0f, 3.0f));

            Assert.IsTrue(reverseHorizontalLine.TestIntersection(reverseVerticalLine));
            Assert.IsTrue(reverseHorizontalLine.TestIntersection(verticalLine));
            Assert.IsTrue(reverseVerticalLine.TestIntersection(verticalLine));
            Assert.IsTrue(reverseVerticalLine.TestIntersection(reverseVerticalLine));

            Assert.IsFalse(reverseHorizontalLine.TestIntersection(reverseOffsetHorizontalLine));
            Assert.IsFalse(reverseHorizontalLine.TestIntersection(offsetHorizontalLine));
        }
 public static void Run()
 {
     using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
     using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
     {
         long x1 = fs.NextInt(), y1 = fs.NextInt();
         long x2 = fs.NextInt(), y2 = fs.NextInt();
         int n = fs.NextInt();
         Line original = new Line 
         { 
             A = y1 - y2, 
             B = x2 - x1, 
             C = x1 * y2 - x2 * y1 
         };
         long minX = Math.Min(x1, x2), maxX = Math.Max(x1, x2);
         long minY = Math.Min(y1, y2), maxY = Math.Max(y1, y2);
         int count = 0;
         for (int i = 0; i < n; i++)
         {
             Line line = new Line { A = fs.NextInt(), B = fs.NextInt(), C = fs.NextInt() };
             double[] cross = GetIntersection(original, line);
             if (cross[0] >= minX && cross[0] <= maxX &&
                 cross[1] >= minY && cross[1] <= maxY) count++;
         }
         writer.WriteLine(count);
     }
 }
Exemple #17
0
        protected void CalculateLine(int y, [Channel("lines")] out Line line)
        {
            line = new Line(y, width);

            double cy = 1.1*y/height;

            for (int x=0; x<width; x++)
            {
                double cx = 2.5*x/width - 2.0;

                double zx = 0, zy = 0;
                double tx;

                byte i;
                for(i = 255; (i > 0) && (zx*zx + zy*zy < 4); i--)
                {
                    tx = zx;
                    zx = zx*zx-zy*zy + cx;
                    zy = 2.0*tx*zy + cy;
                }

                Color color = Color.FromArgb(i, i, i);
                line.Bitmap.SetPixel(x, 0, color);
            }
        }
Exemple #18
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Input
            Line line = new Line();
            DA.GetData(0, ref line);

            double eModulus = 0.0;
            DA.GetData(1, ref eModulus);

            double area = 0.0;
            DA.GetData(2, ref area);

            double preStress = 0.0;
            if (this.Params.Input[3].SourceCount != 0)
            {
                DA.GetData(3, ref preStress);
            }


            //Create instance of bar
            GoalObject cableElement = new CableGoal(line, eModulus, area, preStress);


            //Output
            DA.SetData(0, cableElement);
        }
Exemple #19
0
 public void DataAccess_GenericSingleGet()
 {
     Line line = new Line();
     line = line.Get<Line>(1);
     Console.WriteLine("line {0} title:{1}", line.Line_Pk.ToString(), line.Title);
     Assert.AreEqual(line.Title, "Lemongrass and Lavender");
 }
        private void checkIntersection(Event upper,Event lower, OrderedSet<Event> Q,List<Point> outPoints)
        {
            Line a = new Line(upper.point,segments[upper.segIdx].End);
            Line b = new Line(lower.point,segments[lower.segIdx].End);

            if (HelperMethods.CheckTurn(new Line(a.Start, a.End), b.Start) == HelperMethods.CheckTurn(new Line(a.Start, a.End), b.End)
             || (HelperMethods.CheckTurn(new Line(b.Start, b.End), a.Start) == HelperMethods.CheckTurn(new Line(b.Start, b.End), a.End)))
                return;
            double aa, bb, cc, dd;
            Point interPoint;
            if (Math.Abs(a.Start.X - a.End.X) < Constants.Epsilon)
            {
                bb = (b.Start.Y - b.End.Y) / (b.Start.X - b.End.X);
                dd = b.Start.Y - b.Start.X * bb;
                interPoint = new Point(a.Start.X, (bb * a.Start.X + dd));
            }
            else if (Math.Abs(b.Start.X - b.End.X) < Constants.Epsilon)
            {
                aa = (a.Start.Y - a.End.Y) / (a.Start.X - a.End.X);
                cc = a.Start.Y - a.Start.X * aa;
                interPoint = new Point(b.Start.X, (aa * a.Start.X + cc));
            }
            else
            {
                aa = (a.Start.Y - a.End.Y) / (a.Start.X - a.End.X);
                bb = (b.Start.Y - b.End.Y) / (b.Start.X - b.End.X);
                cc = a.Start.Y - a.Start.X * aa;
                dd = b.Start.Y - b.Start.X * bb;
                double interX = (dd - cc) / (aa - bb);
                interPoint = new Point(interX, (aa * interX + cc));
            }
            Q.Add(new Event(interPoint, PointType.Intersection,-1 ,upper,lower));
            outPoints.Add(interPoint);
        }
 /// <summary>
 /// Constructs a new surface of revolution from a generatrix line and an axis.
 /// <para>This overload accepts a slice start and end angles.</para>
 /// <para>Results can be (truncated) cones, cylinders and circular hyperboloids, or can fail.</para>
 /// </summary>
 /// <param name="revoluteLine">A generatrix.</param>
 /// <param name="axisOfRevolution">An axis.</param>
 /// <param name="startAngleRadians">An angle in radias for the start.</param>
 /// <param name="endAngleRadians">An angle in radias for the end.</param>
 /// <returns>A new surface of revolution, or null if any of the inputs is invalid or on error.</returns>
 public static RevSurface Create(Line revoluteLine, Line axisOfRevolution, double startAngleRadians, double endAngleRadians)
 {
   using (LineCurve lc = new LineCurve(revoluteLine))
   {
     return Create(lc, axisOfRevolution, startAngleRadians, endAngleRadians);
   }
 }
        public void GivenALineDiscount_WhenAppliedToLine_ThenShouldReturnLineTotalTimesPercentage()
        {
            var sut = new LineDiscount("d", 1, 1, 1);
            var line = new Line(new Bike(string.Empty, string.Empty, 100), 2);

            Assert.AreEqual(line.CalculateTotal() * sut.Percentage, sut.Apply(line));
        }
Exemple #23
0
        private static void WriteTuples()
        {
            Write(ValueTuple.Create(1, 2, 3, "abc", "def"));
            Console.WriteLine();

            Write(new Point(10, 20));
            Console.WriteLine();

            Write(new Person(123, "abc def", "東京都千代田区千代田1-1"));
            Console.WriteLine();

            var x = (ITuple)new Student(999, "あwせdrftgy ふじこ", "千葉県浦安市舞浜1-1", 5, 2).Value;

            Write(x);
            Console.WriteLine();

            x[0] = 1;
            x[1] = "a";
            x[2] = "b";
            x[3] = 2;
            x[4] = 3;
            Write(x);
            Console.WriteLine();

            var line = new Line(new Point(1, 2), new Point(3, 4));
            var lineClone = line.DeepClone();

            line.A.X = 10;
            line.A.Y = 20;
            line.B.X = 30;
            line.B.Y = 40;

            Write(line);
            Write(lineClone);
        }
 public MyCuboidSide()
 {
     Lines[0] = new Line();
     Lines[1] = new Line();
     Lines[2] = new Line();
     Lines[3] = new Line();
 }
Exemple #25
0
 static void Main(string[] args)
 {
     Shape myShape = new Line(new Coordinate(0, 0, 0), 10);
     myShape.Render();
     myShape = new Arc(new Coordinate(1,1,1),5,20);
     myShape.Render();
 }
Exemple #26
0
        public static void DrawDepthLine(float width, Line [] lines, float depth)
        {
            DrawLines(width, lines, Color.FromArgb(100, Color.Orange));

            if (depth < 0)
            {
                float w = width * (depth / max_cut_depth);
                if (w > width)
                {
                    w = width;
                }
                DrawLines(w, lines, Color.FromArgb(255, Color.OrangeRed));
            }
            if (depth < max_cut_depth)
            {
                float w = width * (depth / max_rout_depth);
                if (w > width)
                {
                    w = width;
                }
                DrawLines(w, lines, Color.FromArgb(200, Color.DarkRed));
            }
            if (depth > 0)
            {
                float w = width * (depth / max_move_height);
                if (w > width)
                {
                    w = width;
                }
                DrawLines(w, lines, Color.FromArgb(50, Color.Green));
            }
        }
Exemple #27
0
			public Bracket (Line x, Line y, Line z, Line a, Line b) {
				this.x = x;
				this.y = y;
				this.z = z;
				this.a = a;
				this.b = b;
			}
        public void Setup()
        {
            m_LineOne = new Line(0,
                                 0.0,
                                 10.0,
                                 100.0,
                                 10.0);
            m_LineTwo = new Line(0,
                                 0.0,
                                 50.0,
                                 100.0,
                                 50.0);

            m_NodeIndexToLineConverter = Substitute.For <INodeIndexToLineConverter>();
            m_NodeIndexToLineConverter.Line.Returns(LineForIndex);

            m_Manager = Substitute.For <ILinesSourceManager>();
            m_Manager.Lines.Returns(new[]
                                    {
                                        m_LineOne,
                                        m_LineTwo
                                    });

            m_Helper = new NodeIndexHelper(m_Manager,
                                           m_NodeIndexToLineConverter);
        }
 /// <summary>
 /// Makes a plane that includes a line and a vector and goes through a bounding box.
 /// </summary>
 /// <param name="lineInPlane">A line that will lie on the plane.</param>
 /// <param name="vectorInPlane">A vector the direction of which will be in plane.</param>
 /// <param name="box">A box to cut through.</param>
 /// <returns>A new plane surface on success, or null on error.</returns>
 public static PlaneSurface CreateThroughBox(Line lineInPlane, Vector3d vectorInPlane, BoundingBox box)
 {
   IntPtr ptr = UnsafeNativeMethods.RHC_RhinoPlaneThroughBox(ref lineInPlane, vectorInPlane, ref box);
   if (IntPtr.Zero == ptr)
     return null;
   return new PlaneSurface(ptr, null);
 }
Exemple #30
0
        public static ObservableCollection<Line> parseXMLForLine(string xmlFile)
        {
            XDocument xdoc = XDocument.Parse(xmlFile);

            var temp_lines = from temp_line in xdoc.Descendants("line")
                             select new
                             {
                                 name = temp_line.Element("name").Value,
                                 info = temp_line.Element("info").Value,
                                 stats = temp_line.Element("stats").Value,
                             };
            ObservableCollection<Line> lines = new ObservableCollection<Line>();
            foreach (var temp_line in temp_lines)
            {
                Line line = new Line();
                line.LineName = temp_line.name;
                line.Info = temp_line.info;
                ObservableCollection<Station> stats = new ObservableCollection<Station>();
                foreach (string stat in temp_line.stats.Split(';'))
                {
                    stats.Add(new Station(stat));
                }
                line.Stats = stats;
                lines.Add(line);
            }

            return lines;
        }