Find the value of x where f(x)=max(|Px|,|Py|,|Pz|), where P=(V1+(V2−V1)x) returns the smallest value

18 Views Asked by At

Question:

Given two 3d vector V1 and V2, find the value x where f(x) returns the smallest number expressed by V1 and V2.

$$f(x)=max(\;|P_x|,\;|P_y|,\;|P_z|\;)\\Where\\P=(V_1+(V_2-V_1)x)$$

I have broken it down to this: (Not 100% sure it's correct)

$$f(x)=\Big|\;(|P_x+P_y|+|P_x-P_y|)\div2+P_z\;\Big|+\Big|\;(|P_x+P_y|+|P_x-P_y|)\div2-P_z\;\Big|\div2\\ where\\ P=(V_1+(V_2-V_1)x)$$

And I just need to find the "Break" point (or test point) where the solution could be at. But I'm stuck here... What are the value I could test to find the smallest number? I think there are either 8 or 12 of them??? Any tips will be helpful!

Side notes: This is related to a question I poorly asked before, hoping that I could figure it out myself if I could just simpifiy the function.

This is for a quick AABB and ray collision detection, where the AABB is always at the (0,0,0) point and the ray is discribed by two points V1 and V2. I did the same with 2D detection and worked it out but I am stuck at trying to make it 3D.

related: Is there a way to simplify $\Big|\;|x+y|+|x-y|+z\;\Big|+\Big|\;|x+y|+|x-y|-z\;\Big|=r$?