在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
類。在實際項目中,您可能需要根據您的需求調整這些方法。