Okay, here's a mat puzzle for you, folks. I'm trying to create a 3d angled sloped wedge. With for loops, on a 3d X,Y,H grid.
The base is a triangle, I know it's a right triangle. I know the length and the height of it. I know the angle at one tip. The wedge is also a right triangle, (well, until I cut off the top at a specified height, but that's just a matter of a simple if H(i,j) > hc, H(i,j)=hc statement) and I know the angle of that slope too.
I want to find the X,Y coordinates of the hypotenuse every step along the length. Well, the X coordinate, since I'm counting along the Y axis. Once I have that, I should be able to increment from that, to the back of the triangle, and calculate the height at each step along there, which should be easy. Famous last words. There's a picture in the cut below
So here's how my thinking's gone. First, an outer For loop to increment along the length. Simple For j=1:Y style loop (yes, I'm using Matlab. And technically, it's y1:mid, since the wedge is supposed to be sloped on both sides, but if one works, then the other should too). So far so good.
Next, to find where the hypotenuse is, to count along the X axis. Since tangent is opposite/adjacent, and my X axis is adjacent to the angle I know, I'm trying to find Z by doing 1/[tan(theta)*j (the opposite)] That should get me 1/1/adjacent, which should come out to adjacent. Somehow, I keep getting divide by zero errors here.
I should just copy/paste the code, huh?
for j=j1:mid;
z=floor(1/(tan(theta)*j)+1; % The +1 is to avoid starting by accessing a 0 point in the matrix.
for i=z:xc1; % z to the back wall.
H(j,z)=tan(2*pi/3)*j-H(j,z); % SHOULD calculate H, then add it to the original H at the base of the slope, to keep the slope constant
if H(j,z) > hc
H(j,z) = hc % Just a simple check to see if it's reached the max height, and cut it there
end % end of the if
end % end of the i loop
end % end of the j loop
Obviously, it's not working. The H array is my initial grid and the height at those points. Obviously, it's not working, which is why I'm posting about it. I think it's the z definition that's not working, but I can't figure out why. It should be, as far as I can tell.
So yeah, any help anybody can offer would be great.