在C#中,Point
结构表示二维平面上的一个点
Point point1 = new Point(3, 4);
Point point2 = new Point(1, 2);
Point result = point1 + point2; // result: (4, 6)
Point point1 = new Point(3, 4);
Point point2 = new Point(1, 2);
Point result = point1 - point2; // result: (2, 2)
Point point1 = new Point(3, 4);
int multiplier = 2;
Point result = point1 * multiplier; // result: (6, 8)
Point point1 = new Point(6, 8);
int divisor = 2;
Point result = point1 / divisor; // result: (3, 4)
Point point1 = new Point(3, 4);
Point point2 = new Point(6, 8);
double distance = point1.DistanceTo(point2); // distance: 5.0
Point point1 = new Point(3, 4);
Point point2 = new Point(1, 2);
int dotProduct = point1.DotProduct(point2); // dotProduct: 11
Point point1 = new Point(3, 4);
Point point2 = new Point(1, 2);
int crossProduct = point1.CrossProduct(point2); // crossProduct: -2
Point point1 = new Point(3, 4);
Point unitVector = point1.UnitVector(); // unitVector: (0.6, 0.8)
Point point1 = new Point(3, 4);
point1.Normalize(); // point1: (0.6, 0.8)
Point point1 = new Point(3, 4);
double angleInDegrees = 90;
Point rotatedPoint = point1.Rotate(angleInDegrees); // rotatedPoint: (-4, 3)
这些操作可以帮助您在二维空间中处理点并执行各种计算。请注意,这些示例使用了自定义的 Point
类。在实际项目中,您可能需要根据您的需求调整这些方法。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: c# attributeusage参数含义