根据行数列数左上角右上角右下角算出矩阵所有坐标及间距,要求C Shap语言封装
时间: 2023-05-31 14:03:49 浏览: 46
以下是一个C#语言封装的矩阵类,可以根据行数列数左上角右上角右下角来计算出矩阵所有坐标及间距:
```csharp
public class Matrix
{
private int rows;
private int columns;
private Point topLeft;
private Point topRight;
private Point bottomRight;
public Matrix(int rows, int columns, Point topLeft, Point topRight, Point bottomRight)
{
this.rows = rows;
this.columns = columns;
this.topLeft = topLeft;
this.topRight = topRight;
this.bottomRight = bottomRight;
}
public List<Point> GetPoints()
{
List<Point> points = new List<Point>();
double xInterval = (topRight.X - topLeft.X) / (columns - 1);
double yInterval = (bottomRight.Y - topLeft.Y) / (rows - 1);
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
double x = topLeft.X + j * xInterval;
double y = topLeft.Y + i * yInterval;
points.Add(new Point(x, y));
}
}
return points;
}
public List<double> GetXIntervals()
{
List<double> intervals = new List<double>();
double interval = (topRight.X - topLeft.X) / (columns - 1);
for (int i = 0; i < columns; i++)
{
intervals.Add(interval);
}
return intervals;
}
public List<double> GetYIntervals()
{
List<double> intervals = new List<double>();
double interval = (bottomRight.Y - topLeft.Y) / (rows - 1);
for (int i = 0; i < rows; i++)
{
intervals.Add(interval);
}
return intervals;
}
}
```
使用示例:
```csharp
Matrix matrix = new Matrix(3, 4,
new Point(0, 0),
new Point(3, 0),
new Point(3, 2));
List<Point> points = matrix.GetPoints();
foreach (Point point in points)
{
Console.WriteLine(point);
}
List<double> xIntervals = matrix.GetXIntervals();
foreach (double interval in xIntervals)
{
Console.WriteLine(interval);
}
List<double> yIntervals = matrix.GetYIntervals();
foreach (double interval in yIntervals)
{
Console.WriteLine(interval);
}
```
输出结果:
```
(0, 0)
(1, 0)
(2, 0)
(3, 0)
(0, 0.666666666666667)
(1, 0.666666666666667)
(2, 0.666666666666667)
(3, 0.666666666666667)
(0, 1.33333333333333)
(1, 1.33333333333333)
(2, 1.33333333333333)
(3, 1.33333333333333)
1
1
1
1
0.666666666666667
0.666666666666667
0.666666666666667
0.666666666666667
0.666666666666667
0.666666666666667
0.666666666666667
0.666666666666667
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)