By courtesy of ‘Hellium’ at StackOverflow I was able to solve this quite easily. I also thank @x4637x for solving this as well.
If I understand your problem correctly,
X is a “random” point inside your
circle whose position is known : X =
(X.x, X.y).
Supposing you want to know X1 and X2
on the circle so that (X1X2) is a
vertical line. You know the absicca of
those points which is X.x.
You surely know that the coordinates
of a point on a circle can be defined
as : A = (O.x + r * cos θ, O.y + r *
sin θ) where :
O is the origin of the circle r is the
radius of your circle θ is an angle in
radians. Thus,
X1 = (O.x + r * cos θ1, O.y + r * sin
θ1) = (X.x, O.y + r * sin θ1) which
means
X.x = O.x + r * cos θ1 <=> cos θ1 = (X.x - O.x) / r <=> θ1 = arcos( (X.x - O.x) / r ) Once you know θ1, computing sin θ1 and X1.y is a piece
of cake.
Computing X2 is very easy, you just
have to invert the ordinate.
If (X1X2) is an horizontal line, you
know the ordinates of X1 and X2 :
X1 = (O.x + r * cos θ1, O.y + r * sin
θ1) = (O.x + r * cos θ1, X.y)
X.y = O.y + r * sin θ1 <=> sin θ1 = (X.y - O.y) / r <=> θ1 = arcsin( (X.y - O.y) / r ) Here, to get X2 you
have to invert the absicca.
His understanding of the question was on point and therefore I was able to do :
public IEnumerator FindRoute()
{
Vector3 O = attachedTarget.transform.parent.position;
Vector3 X = attachedTarget.transform.position;
float thetaOne;
if (attachedTarget.GetComponent<LinkEnd>().feedDirection == LinkEnd.FeedDirection.Horizontal)
{
thetaOne = Mathf.Asin((X.y - O.y) / maxRange);
pointA = new Vector3(O.x + (maxRange + 1) * Mathf.Cos(thetaOne), X.y, 0);
pointB = new Vector3(O.x + -((maxRange + 1) * Mathf.Cos(thetaOne)), X.y, 0);
yield return null;
}
if (attachedTarget.GetComponent<LinkEnd>().feedDirection == LinkEnd.FeedDirection.Vertical)
{
thetaOne = Mathf.Acos((X.x - O.x) / maxRange);
pointA = new Vector3(X.x, O.y + (maxRange + 1) * Mathf.Sin(thetaOne), 0);
pointB = new Vector3(X.x, O.y + -((maxRange + 1) * Mathf.Sin(thetaOne)), 0);
yield return null;
}
}