Java實現Lagan法射線追蹤(lagan.java)
import java.io.*;
class laganRayTracing{
private float pi = 3.141592653f;
private int nx,nz,nshot,nray,ngrid;
private float dx,dz,s,dangle,fangle;
private float[] v0;
private String raypath;
laganRayTracing(){
nx = nz = 301;
dx = dz = 5f;
s = 0.5f;
fangle = 0f;
dangle = 4f;
nray = 2;
ngrid = nx * nz;
raypath = "raypath.txt";
v0 = new float [ngrid];
for(int i=0;i<ngrid;i++){
v0[i] = 2000.0f;
if(i>150*nz)v0[i] = 3000f;
}
}
public void makeRay()throws java.io.IOException{
float p_x,p_z,n_x,n_z,l_x,l_z;
float p_xend,p_zend;
float n_xnew,n_znew;
float p_x0, p_z0, dip;
int ip_lux,ip_ldx,ip_rux,ip_rdx;
int ip_luz,ip_ldz,ip_ruz,ip_rdz;
int irayon,ishot;
float angle,time,v;
p_x0 = (nx-1)*dx / 3;
p_z0 = (nz-1)*dz / 2;
p_x = p_x0;
p_z = p_z0;
Writer rayfp = new FileWriter(raypath);
for(int iray = 0; iray < nray; iray++){
p_x = p_x0;
p_z = p_z0;
angle = fangle + iray*dangle;
angle = angle*pi/180.0f;
//System.out.println(angle);
n_x = (float)Math.cos(angle);
n_z = (float)Math.sin(angle);
time = 0.0f;
do{
/* cal_gridpoint */
ip_lux = (int)(p_x/dx);
ip_luz = (int)(p_z/dz);
ip_ldx = ip_lux;
ip_ldz = ip_luz+1;
ip_rux = ip_lux+1;
ip_ruz = ip_luz;
ip_rdx = ip_lux+1;
ip_rdz = ip_luz+1;
/* cal_gridvel */
float l_x1 = (v0[ip_rux*nz + ip_ruz]-v0[ip_lux*nz + ip_luz])/dx;
float l_x2 = (v0[ip_rdx*nz + ip_rdz]-v0[ip_ldx*nz + ip_ldz])/dx;
l_x = ( l_x1+l_x2 ) / 2.0f;
float l_z1=(v0[ip_ldx*nz + ip_ldz]-v0[ip_lux*nz + ip_luz])/dz;
float l_z2=(v0[ip_rdx*nz + ip_rdz]-v0[ip_rux*nz + ip_ruz])/dz;
l_z=(l_z1+l_z2)/2.0f;
v=v0[ip_rux*nz + ip_ruz]+v0[ip_lux*nz + ip_luz]+v0[ip_rdx*nz + ip_rdz]
+v0[ip_ldx*nz + ip_ldz];
v=v/4.0f;
//System.out.println(v);
/* cal_path */
float dotmult_ln=l_x*n_x+l_z*n_z;
float dotmult_ll=l_x*l_x+l_z*l_z;
p_xend=p_x+n_x*s*(1f+dotmult_ln*0.5f*s/v)-0.5f*l_x*s*s/v
-n_x*s*s*s*(dotmult_ll-dotmult_ln*dotmult_ln)/(6.0f*v*v);
p_zend=p_z+n_z*s*(1f+dotmult_ln*0.5f*s/v)-0.5f*l_z*s*s/v
-n_z*s*s*s*(dotmult_ll-dotmult_ln*dotmult_ln)/(6.0f*v*v);
n_xnew=n_x*(1f+dotmult_ln*s/v)-l_x*s/v
-n_x*s*s*(dotmult_ll-dotmult_ln*dotmult_ln)/(2.0f*v*v);
n_znew=n_z*(1f+dotmult_ln*s/v)-l_z*s/v
-n_z*s*s*(dotmult_ll-dotmult_ln*dotmult_ln)/(2.0f*v*v);
time+=s/v*(1f+s*s*(dotmult_ll+dotmult_ln*dotmult_ln)
/(6f*v*v)-dotmult_ln*s/(2f*v));
/* buffer */
p_x = p_xend;
p_z = p_zend;
n_x = n_xnew;
n_z = n_znew;
rayfp.write(p_x+" "+p_z+" \n");
//System.out.println(p_x+" "+p_z+" ");
}while((p_xend>=0.0f)&&(p_xend<((nx-1f)*dx))&&(p_zend>=0.0f)&&(p_zend<(nz-1f)*dz));
rayfp.write("-999999.9 -999999.9 \n");
}
rayfp.close();
}
public static void main(String[]args)throws java.io.IOException{
laganRayTracing l = new laganRayTracing();
l.makeRay();
}
}
相關文章
- [MetalKit]44-Raytracing with Metal射線追蹤
- [MetalKit]10-Ray-tracing-in-a-Swift-playground射線追蹤Swift
- 用 Rust 實現簡單的光線追蹤Rust
- 如何在 HDRP 中實現光線追蹤?
- 在WebGL中使用GLSL實現光線追蹤Web
- [MetalKit]25-Ray-tracing-in-a-Swift-playground6射線追蹤6Swift
- [MetalKit]14-Ray-tracing-in-a-Swift-playground5射線追蹤5Swift
- [MetalKit]13-Ray-tracing-in-a-Swift-playground4射線追蹤4Swift
- [MetalKit]12-Ray-tracing-in-a-Swift-playground3射線追蹤3Swift
- [MetalKit]11-Ray-tracing-in-a-Swift-playground2射線追蹤2Swift
- 如何追蹤Java動態Java
- RTX顯示卡實時光線追蹤技術解析 英偉達RTX顯示卡的光線追蹤技術是什麼?
- VR先驅研製眼球追蹤 未來VR頭顯將實現眼球追蹤VR
- Go - 實現專案內鏈路追蹤Go
- SQL追蹤和事件追蹤SQL事件
- 把遊戲變成現實,光線追蹤技術到底有多神?遊戲
- 視覺技術的聖盃:光線追蹤如何再現真實世界?視覺
- Go - 實現專案內鏈路追蹤(二)Go
- log4j MDC實現日誌追蹤
- Java動態追蹤技術探究Java
- Oracle執行語句跟蹤 使用sql trace實現語句追蹤OracleSQL
- Asp.Net Core&Jaeger實現鏈路追蹤ASP.NET
- 分散式鏈路追蹤框架的基本實現原理分散式框架
- 利用Spring Boot實現微服務的鏈路追蹤Spring Boot微服務
- 日誌追蹤
- 程式碼追蹤
- C 實現射線檢測多邊形碰撞
- 詳解ElasticAPM實現微服務的鏈路追蹤(NET)AST微服務
- 用HTML5 Geolocation實現一個距離追蹤器HTML
- 【數值方法-Python實現】Crout分解+追趕法實現Python
- go-kit 微服務 服務鏈路追蹤 (jaeger 實現)(2)Go微服務
- go-kit 微服務 服務鏈路追蹤 (jaeger 實現)(1)Go微服務
- 一文詳解|Go 分散式鏈路追蹤實現原理Go分散式
- 三星Gear VR最大亮點:將實現手勢追蹤VR
- 透過鉤子函式+Traceid實現Flask鏈路追蹤函式Flask
- 光線追蹤往事:十年技術輪迴
- 從零開始的簡單光線追蹤示例
- TGDC | 向陽而生 —— 光線追蹤的專案應用