c#问题? [英] c# question ?
本文介绍了c#问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
喜。我需要一些大约2平方的代码和他们彼此之间的意外。首先,我需要有关于点和线的类的代码。然后用''''如果''''方法我应该将两个方块相互组合并理解事故点的位置。
hi. i need some codes about 2 square and the accidents that they have with each other.first of all, i need to have codes about a class for point and line. then with ''''if'''' method i should combine two square with each other and understand the position of the accident''s points.
推荐答案
I相信你所指的是碰撞检测。
这个 [ ^ <来自MSDN的小教程可以帮助你。
我在Q& A中也发现了这个问题你可以参考:如何分析矩形是否与另一个矩形重叠 [ ^ ]
I believe what you are referring to is called "Collision Detection".
This[^] small tutorial from MSDN may help you along your way.
I also found this question in Q&A you can refer to: how to analyze whether a rectangle is overlap another rectangle[^]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Square_Point_Line
{
public class Point
{
public Point()
{
}
public Point(double x,double y)
{
this.X = x;
this.Y = y;
}
public double X { get; set; }
public double Y { get; set; }
/// <summary>
/// This Function Shows the Coordinates of the Point
/// </summary>
public void ShowPoint()
{
Console.WriteLine("\t\n [x={0},y={1}]",X,Y);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Square_Point_Line
{
public class Line
{
public Line()
{
}
public Line(Point a,Point b)
{
this.A = a;
this.B = b;
}
public double Length
{
get
{
return Math.Sqrt(Math.Pow(A.X - B.X, 2) + Math.Pow(A.Y - B.Y, 2));
}
}
public Point A { get; set; }
public Point B { get; set; }
/// <summary>
/// This Function Shows the Length of Line
/// </summary>
public void DisplayLine()
{
Console.WriteLine("LengthOfLine={0}",this.Length);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Square_Point_Line
{
public class Square
{
public Square()
{
}
public Square(Line ab,Line bc,Line cd,Line da)
{
this.AB = this.BC = this.CD = this.DA = ab;
}
public Square(Point a,Point b,Point c,Point d)
{
this.A = a;
this.B = b;
this.C = c;
this.D = d;
}
public Line AB { get; set; }
public Line BC { get; set; }
public Line CD { get; set; }
public Line DA { get; set; }
public Point A { get; set; }
public Point B { get; set; }
public Point C { get; set; }
public Point D { get; set; }
}
}
}
这篇关于c#问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文