Reputation: 3987
There is an object A. I want to create a object B. I'm trying to avoid that A covers B:
I have thinking how to achieve that. Take a look of the following drawing:
I have been thinking in a solution in a math - geometry way before searching for some Unity3D function to solve the problem. I have realise A and B would be on the same surface if the camera is within a sphere with radius c-A. So I guess the solution can be related to get a point at a B at a distance A-B from A on the surface of the sphere with radius c-A. Does it has sense? Any other idea? How to do it with maths and Unity?
Upvotes: 0
Views: 1334
Reputation: 15035
What you are describing is a ring on the sphere's surface whose plane is perpendicular to the direction c-A
.
This is fairly simple to compute. First we need to find 2 perpendicular vectors to c-A
(we'll call this d
):
"c-A" = d
, the radius of the sphere R = abs(d)
and the distance "A-B" = D
.d.X / R < 0.5
, set a temporary vector w = X
, else set w = Y
.u = normalize(cross(w, d))
.v = normalize(cross(d, u))
.The center point of this ring is given by c + d * cos(D / R)
. From here we can generate any point on the ring with
p(t) = c + d * cos(D / R) + u * cos(t) + v * sin(t) , 0 ≤ t ≤ 2π
UPDATE:
Upvotes: 3