the angle of the corner: wall = 0 for straight, positive inside the angle of the molding: slant = 0 for vertical, positive out from wall 38 is the predominant angle between the molding and wall the crosscut angle: rake = 0 for square, miter = 90 for square >90 for undercut <90 for overcut the bevel angle: bevel = 0 for square, positive for overcut included = 90 for square < 90 for overcut the ceiling-wall edge for the left wall 0,1,0 the molding lateral vector sin(slope),0,cos(slope) the ceiling-wall edge for the right wall sin(wall),cos(wall),0 the molding lateral vector sin(slope)cos(slope)-sin(slope)sin(wall),0,cos(slope) L is unit normal vector for molding on left or on 1,0,0 or x=0 wall R is unit normal vector for molding on right or cos(wall),-sin(wall),0 wall i j k L = 0 1 0 sin(slope) 0 cos(slope) i j k R = sin(wall) cos(wall) 0 sin(slope)cos(wall) -sin(slope)sin(wall) cos(slope) the edge between the moldings is the vector cross product of L and R: L X R = = ( -cos(slope)sin(slope)sin(wall), cos(slope)sin(slope)(cos(wall)-1), -cos(slope)cos(slope)sin(wall) ) unit(L X R) = (L X R) / (cos**2(slope)*(sin**2(wall) + sin**2(slope)(1-cos(wall))**2) the y component of unit(L x R) is cos(rake) or arc tangent of the y component over the hypotenuse of the x and z component hypotenuse = sqrt( sin**2(slope)sin**2(wall) + cos**2(slope)sin**2(wall)) = sin(wall) rake = atan( sin(slope)*(cos(wall)-1) / sin(wall) ) when wall is positive rake is 0 for square and positive for top edge shorter than bottom edge when wall is negative rake is 0 for square and positive top edge longer than bottom edge cos(rake) = (1-cos(wall)) / (sin**2(wall)/sin**-2(slant)+(1-cos(wall)**2)**0.5 L dot R = cos**2(slant)*cos(wall) + sin**2(slant) bevel is 0 for square and positive for back longer than front bevel = 0.5 acos(L dot R)