如何动态创建要使用的点 point[](将计算中的 x、y 值放在 for 循环中)

how to create dynamically Point point[] to use in (place the x, y values from computation within a for loop)

提问人:elwolv 提问时间:11/4/2023 更新时间:11/4/2023 访问量:34

问:

如何动态创建点点[] (将计算中的 x、y 值放在 for 循环中) 然后在带有点数组的 for 循环中的 LineTo GDI+ 中使用? 线到(hdc, point1, point2);

想要从以下位置创建 Point[] points 数组

for (int c = 0; c < N; c++) {
points[c]= ( radius*sin(theta*c), radius*cos(theta*c) );
}

所有尝试创建数组都有错误

找到此代码并尝试将其更改为 GDI+ C++:

https://cpp.hotexamples.com/examples/-/-/lineTo/cpp-lineto-function-examples.html

void rosette(Hdc hdc)
{
int N = 10;
float radius = 100.0;

int N = 100; float radius = 150;   PI = 3.14;
Point *pointlist = new Point[N];
float theta = (2.0f * PI) / N;
float angle = theta / 2;
for (int c = 0; c < N; c++) {
pointlist[c]= (radius*sin(theta*c), radius*cos(theta*c));
}

for (int i = 0; i < N-1; i++) {
MoveTo(hdc,  pointlist[i], NULL);
LineTo(hdc,   pointlist[i+1]);
}
lineTo(hdc,  pointlist[0]);
}

所有尝试创建数组都有错误

找到此代码并尝试将其更改为 GDI+ C++:

C++ 函数 GDI+ GDI line改为

评论

0赞 Thomas Matthews 11/4/2023
仅供参考,如果该变量不打算修改,请将其声明为 .例:constconst double PI = 3.1415269;
0赞 Thomas Matthews 11/4/2023
仅供参考,更喜欢使用标准容器,例如 ,而不是处理您自己的容器。已经过测试。:-)您也可以使用而不用担心内存管理。std::liststd::liststd::vector
0赞 JaMiT 11/4/2023
你得到的错误是什么?删除代码中与错误无关的部分。(参见最小可重复示例。是否有错误?(如果是这样,请删除它后面的所有内容。是否有错误?(如果是这样,请删除它后面的所有内容和它前面的一些内容。如果没有,请简化!浮点 θ = 2.0f;.)是否有错误?(如果没有,请简化!3.0) (简化的)有错误吗?(如果是这样,则减少到点;点 = (3.0, 4.0);。如果没有,请简化!等等。Point *pointlist = new Point[N];float theta = (2.0f * PI) / N;radius*sin(theta*c)pointlist[c]= (3.0, 4.0);

答: 暂无答案