- Home /
find furthest point in relative to 2 others
Hi! Here is diagram of my problem:

I need to find point, which is 14m away from point A, and as far as possible, from point B.
Brutforce way, I can simply check radius of circle of point A for every angle:
double x = 14f * Math.Cos(Mathf.Deg2Rad * angle);
double y = 14f * Math.Sin(Mathf.Deg2Rad * angle);
and then compare (x,y) distance to point B.
But is it very long and stupid solution, like I'll need to run it 360 times for every angle.
What is the most elegant way, using vector math?
"as far as possible, from point B"
So the point would be always 14m behinde A relative to B, right?
Relative to A, point is always 14m away. But relative to B, it should be as far as possible.
I.e. point is always somewhere on a circle, with center in point A and radisu 14m
Oh, sorry... so the point can be more than 14m away from A?
edit: Or did you mean the opposite?
as far as possible will be only one point in which 3 of point will be in a line means AB + 14. You can check for a line .
So the point would always be from a the inverse direction from b?
Answer by tanoshimi · Nov 04, 2014 at 02:54 PM
Attach this to your target point:
#pragma strict
var A : Transform;
var B : Transform;
function Update () {
transform.position = A.position + (A.position - B.position).normalized * 14;
}
For the explanation, the point you are after lies on the circle C with center A and radius 14 since all point at distance 14 from A makes a circle.
Now wherever B may be, you are looking for the point that is pretty much opposite of B onto C. And this point HAS to be the point lying on the ray from B towards A.
So you get :
B -> A (a.position - b.position)
you normalized because we only want the direction
Starting from A you extend by 14 to find that point on the circle
point = A.position + (A.position - B.position).normalized * 14;
And tadaa.
Your answer
Follow this Question
Related Questions
Vector3.Project, how to? 2 Answers
Getting vectors on an object every so many units 0 Answers
Working out which vector 3 is closest 1 Answer
Enemy Jitters when i want him to stop a certain distance 0 Answers