for (i in this.hexCube)转为c语言
时间: 2024-03-19 18:44:08 浏览: 15
这段代码可以转化为以下的 C 语言代码:
```
for(int i = 0; i < sizeof(this.hexCube) / sizeof(this.hexCube[0]); i++) {
hexCubeOrtho[i].x = (this.hexCube[i][1] + this.hexCube[i][0] / 2);
hexCubeOrtho[i].y = this.hexCube[i][2];
hexCubeOrtho[i].z = (this.hexCube[i][0] - this.hexCube[i][1] / 2);
}
```
请注意,这只是一个参考翻译,具体实现可能需要根据上下文和变量类型进行修改。
相关问题
for (i in this.hexCube)
这段代码使用了 JavaScript 中的 for...in 循环语句,其中的 this.hexCube 是一个对象。for...in 循环语句用于遍历对象中的属性,并将属性名存储在变量 i 中。在此例中,for (i in this.hexCube) 将遍历 this.hexCube 对象中的所有属性,并将属性名存储在变量 i 中。在循环体中,可以使用 this.hexCube[i] 来访问 this.hexCube 对象中对应属性名为 i 的属性的值。
for (i in this.hexCube) { hexCubeOrtho[i] = { "x": (this.hexCube[i][1] + this.hexCube[i][0] / 2) * hexR + scrollX, "y": Math.sqrt(3) / 2 * this.hexCube[i][0] * hexR + scrollY, } }翻译成c语言
这段 JavaScript 代码可以翻译成以下的 C 语言代码:
```c
for(int i = 0; i < sizeof(this.hexCube) / sizeof(this.hexCube[0]); i++) {
hexCubeOrtho[i].x = (this.hexCube[i][1] + this.hexCube[i][0] / 2) * hexR + scrollX;
hexCubeOrtho[i].y = sqrt(3) / 2 * this.hexCube[i][0] * hexR + scrollY;
}
```
其中 `sizeof(this.hexCube) / sizeof(this.hexCube[0])` 表示 `this.hexCube` 数组的长度(即元素个数),`sqrt()` 函数用于计算平方根。另外,由于 C 语言中数组下标从 0 开始,因此在循环中使用的变量 i 应该从 0 开始,循环终止条件为 `i < sizeof(this.hexCube) / sizeof(this.hexCube[0])`。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![dmg](https://img-home.csdnimg.cn/images/20210720083646.png)