public static bool PointIsBetween(Point point, Shape.Line line) { var crossproduct = (point.Y - line.StartY) * (line.EndX - line.StartX) - (point.X - line.StartX) * (line.EndY - line.StartY); if (Math.Abs(crossproduct) > 0.000000001) { return(false); } var dotproduct = (point.X - line.StartX) * (line.EndX - line.StartX) + (point.Y - line.StartY) * (line.EndY - line.StartY); if (dotproduct < 0) { return(false); } var squaredlengthba = (line.EndX - line.StartX) * (line.EndX - line.StartX) + (line.EndY - line.StartY) * (line.EndY - line.StartY); if (dotproduct > squaredlengthba) { return(false); } return(true); }
/// <summary> /// 根据点列表生成直线列表 /// </summary> /// <param name="listPoint"></param> /// <param name="isAddToGlobal">判断线段要不要加到全局的变量中,true要</param> /// <returns></returns> public List <BaseShape> addLine(List <PointF> listPoint, bool isAddToGlobal) { List <BaseShape> listLine = new List <BaseShape>(); for (int i = 0; i < listPoint.Count; i++) { if (i == listPoint.Count - 1) { Line line = new Shape.Line(listPoint[i], listPoint[0]); if (isAddToGlobal) { //line.ShapeID = CADInterface.globalID; //CADInterface.globalID = CADInterface.globalID + 1; } listLine.Add(line); } else { Line line = new Shape.Line(listPoint[i], listPoint[i + 1]); if (isAddToGlobal) { //line.ShapeID = CADInterface.globalID; //CADInterface.globalID = CADInterface.globalID + 1; } listLine.Add(line); } } return(listLine); }
public override void onUpdate() { checkInput(); if (movingup) { imagey--; } string imagepath = Environment.CurrentDirectory + @"\..\..\res\demoimage.png"; //this is /bin/Debug/ btw Prop demoimage = new Prop(new Bitmap(imagepath), 150, 150); scene.render(demoimage, 0, imagey); Rect rect1 = new Rect(0, 0, 60, 60); Rect rect2 = new Rect(10, 10, 40, 40); if (rect1.intersects(rect2)) { //Console.WriteLine("intersecting!"); } Shape.Triangle tri = new Shape.Triangle(50, 50, false); Shape.Rectangle rect = new Shape.Rectangle(45, 80, true); Shape.Ellipse ell = new Shape.Ellipse(30, 50); Shape.Line li = new Shape.Line(600, 400, 650, 350); scene.render(tri, 100, 100, 2, Brushes.Blue); scene.render(rect, 300, 300, 1, Brushes.Green); scene.render(ell, 50, 50, 3, Brushes.Red); scene.render(li, 4, Brushes.Yellow); int mx = scene.getMouseX(); int my = scene.getMouseY(); scene.render(mx.ToString(), 0, 0); scene.render(my.ToString(), 0, 10); scene.render("Vector result: " + vector.ToString(), 200, 100); //THIS CODE DEMOS BACKGROUNDS //BUT ALSO MAKES THE WINDOW MORE CLUTTERED (BAD FOR THE DEMO) //scene.renderBackground(demoimage, true); particles.addParticle(particleProp); particles.addParticle(particleProp2); particles.step(); scene.render(particles, 400, 300); }
public static Shape.Line MoveLine(Shape.Line line, Point location) { line.StartX = line.StartX - location.X; line.StartY = line.StartY - location.Y; return(line); }
public static void LogMoving(Shape.Line line, StatusBarPanel statusBP) { statusBP.Text = ($"\"{line.Name}\" got a new position: start ({line.StartX}, {line.StartY}), end ({line.EndX}, {line.EndY})"); }