문제

I am using ray tracing and at the beginning I assumed a plane surface so I used the equation of the plane surface which is :

Ax + BY + CZ +d = 0 

while A,B and C are the component of the normal vector of the Plane Normal = [A B C] and using the Ray equation : Ray = Source + t*Direction And then solve it for t and I can find the intersection points.

My question now that I have function in matlab to read the surface of the object but the object may not be plane surface and I am getting the data of the surface [X Y Z] of the surface but I don't know which equation should I use to find t and then the intersection point. And I even have a function to give me the normal vector at each point

If you can edit the tags the get the right ones please do it.

도움이 되었습니까?

해결책 3

If you can get the X Y Z of the surface and you said you can get the normal vector in each point so what is your problem now?

The X Y Z of the surface are the intersection points and if you have the normal vector in each point so you can calculate whatever you want ( the reflected or the refracted rays).

I think you have no troubles at all

다른 팁

It might not be a plane, but you can always calculate a normal vector at each point. You'll just have to work harder to do it. Take two partial derivatives in planar coordinates, cross those vectors, and that's the normal at the point.

If your surface is defined as a height Z on a some X-Y grid, you can solve it easily using fzero. This would exclude some complex shapes, but might work for standard optics problems like a ray hitting a lens. Assume that X, Y and Z are 2-d matrices with the same shape. You can then do a 2d interpolation like

z_interp = interp2(X,Y,Z,x_interp,y_interp)

If this is not the case, you should try to define your own function that can calculate z based on x and y.

For the line, we have

x_ray = x_source + t * x_dir
y_ray = y_source + t * y_dir
z_ray = z_source + t * z_dir

So you can now define a function that calculates the height above the surface as a function of t as

height_above_plane = @(t) z_source + t * z_dir - interp2(X, Y, Z, ...
    x_source + t*x_dir, y_source + t*y_dir)

Note that this might not be the shortest distance from the point to the plane, it is just the height measured along the z-direction. The time the ray hits the surface can now be found by searching for the t for which the height is zero. This can be done for arbitrary functions using fzero:

t_intercept = fzero(height_above_plane, 0);

This should work well for simple cases where the function defining the surface is relatively smooth and the ray crosses the surface only once. It might be possible to transform cases with more complex geometry into such a simple case.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top