当前位置:首页 » 编程语言 » c语言旋转矩阵

c语言旋转矩阵

发布时间: 2025-03-07 13:15:25

① c璇瑷鐜鐟拌姳绋嫔簭

```html

C璇瑷缁桦埗鐜鐟拌姳锲炬堢殑绠瑕佹傝堪


瑕佸垱寤轰竴涓狢璇瑷绋嫔簭锛岀敤浜庣粯鍒朵竴涓缇庝附镄勭帿鐟拌姳锲炬堬纴鎴戜滑闇瑕佷竴浜涘熀链镄勬暟瀛﹀嚱鏁板拰鐭╅樀镎崭綔銆备互涓嬫槸绋嫔簭镄勫叧阌閮ㄥ垎锛屽寘𨰾镞嬭浆鐭╅樀銆佸悜閲忔搷浣滃拰鍏夌収妯″瀷锛



mat3 rotationXY(float x, float y) {
vec2 c, s = {sin(x), sin(y)};
mat3 m = {
c.y, 0.0f, -s.y,
s.y * s.x, c.x, c.y * s.x,
s.y * c.x, -s.x, c.y * c.x
};
return m;
}



鎺ョ潃鏄鐢ㄤ簬鎻忕粯鑺辩摚杈圭紭镄勫嚱鏁瘿sdPetal`鍜屾椠灏勫嚱鏁瘿map`锛屼互鍙婅$畻姊搴︾殑`gradient`鍑芥暟锛屽畠浠鍦ㄧ粯鍒惰繃绋嬩腑璧峰埌鍏抽敭浣灭敤锛

涓轰简鐢熸垚鐜鐟拌姳镄3D鏁堟灉锛屾垜浠杩橀渶瑕佽$畻鍏夌嚎鏂瑰悜锛坄ray_dir`锛夊拰镀忕礌鍏夌収锛坄f`锛夛纴链钖庡湪涓诲嚱鏁瘿main`涓灏呜繖浜涚粍浠剁粨钖堣捣𨱒ョ敓鎴愬浘镀忥细



vec3 ray_dir(float fov, vec2 pos) {
vec3 r = {pos.x, pos.y, -tan((90.0 - fov * 0.5) * DEG_TO_RAD)};
return normalize3(r);
}


float f(vec2 fragCoord) {
vec3 dir = ray_dir(45.0, fragCoord);
vec3 eye = {0.0f, 0.0f, 4.5f};
dir = mul(rotationXY(angle, pitch), dir);
eye = mul(rotationXY(angle, pitch), eye);
float depth = ray_marching(eye, dir, 0.0, clip_far);
if (depth >= clip_far) return 0.0f;
return shading(pos, gradient(pos), eye);
}


int main() {
for (int y = 0; y < 80; y++) {
for (int x = 0; x < 160; x++) {
char pixel = " .,-:;+=*#@"[(int)(f(make2((x / 160.0 - 0.5) * 2.0f, (y / 80.0 - 0.5f) * -2.0f)) * 12.0f)];
printf("%c", pixel);
}
printf(" ");
}
}



杩欎釜C璇瑷绋嫔簭阃氲繃宸у欑殑鐭╅樀鍙樻崲鍜屽厜镦ц$畻锛屾瀯寤哄嚭涓涓缁呜吇镄勭帿鐟拌姳锲炬堬纴灏嗘暟瀛︿箣缇庝笌缂栫▼镩烘湳瀹岀编铻嶅悎銆傛疮涓镀忕礌镄勭敓鎴愰兘渚濊禆浜庡嶆潅镄勫悜閲忓拰鐭╅樀杩愮畻锛屽𪾢绀轰简绋嫔簭锻桦瑰嚑浣曞拰鍏夌収镄勭悊瑙c傚湪瀹为檯缂栫▼涓锛屼綘鍙浠ユ牴鎹闇瑕佽皟鏁村弬鏁板拰鍑芥暟缁呜妭锛屼互鍒涘缓鍑烘洿澶氩彉鍖栫殑鐜鐟拌姳鏁堟灉銆

c语言 旋转矩阵算法

#include <stdlib.h>
#include <stdio.h>
#define N 5

int min(int a,int b,int c,int d)
{
a=a<b?a:b;
a=a<c?a:c;
a=a<d?a:d;
return a;
}

int main()
{
int arr[N][N],i,j;
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
arr[i][j]=min(i,j,N-1-i,N-1-j);
printf("%d ",arr[i][j]);
}
printf("\n");
}
system("pause");
return 0;
}

热点内容
scratch少儿编程课程 发布:2025-04-16 17:11:44 浏览:642
荣耀x10从哪里设置密码 发布:2025-04-16 17:11:43 浏览:368
java从入门到精通视频 发布:2025-04-16 17:11:43 浏览:89
php微信接口教程 发布:2025-04-16 17:07:30 浏览:311
android实现阴影 发布:2025-04-16 16:50:08 浏览:794
粉笔直播课缓存 发布:2025-04-16 16:31:21 浏览:346
机顶盒都有什么配置 发布:2025-04-16 16:24:37 浏览:213
编写手游反编译都需要学习什么 发布:2025-04-16 16:19:36 浏览:818
proteus编译文件位置 发布:2025-04-16 16:18:44 浏览:369
土压缩的本质 发布:2025-04-16 16:13:21 浏览:594