# How to find the intersection point of a vector and a radius?

**URL:** <https://forums.unrealengine.com/t/how-to-find-the-intersection-point-of-a-vector-and-a-radius/1138579>\
**Category:** XR Development\
**Tags:** unreal-engine, question, Blueprint\
**Created:** [April 23, 2023, 9:07pm UTC](https://forums.unrealengine.com/t/how-to-find-the-intersection-point-of-a-vector-and-a-radius/1138579 "2023-04-23T21:07:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnnyBichevski](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JohnnyBichevski](https://forums.unrealengine.com/u/JohnnyBichevski)\
**Post date:** [April 23, 2023, 9:07pm UTC](https://forums.unrealengine.com/t/how-to-find-the-intersection-point-of-a-vector-and-a-radius/1138579/1 "2023-04-23T21:07:34Z")

</div>

Hello! I am trying to spawn an actor on a certain distance from a player, while determining the location by shooting a vector from a controller. How do I find the coordinates of an intersection point of the vector from controller and a radius around the player?

 ![question](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/f/1/df1328028e3e6f327d6130cbe1f9618de8354ebb.png)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [April 24, 2023, 6:35am UTC](https://forums.unrealengine.com/t/how-to-find-the-intersection-point-of-a-vector-and-a-radius/1138579/2 "2023-04-24T06:35:13Z")

</div>

You can get the angle between two vectors with

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/e/7/de73e17d359010302ac165732298d727fd18b0e7.png)

and if you know the distance of the controller from the player, then it’s Pythagoras ( if you mean in front of the player ).

---

<div class="post-metadata">

**Author:** ![L1z4rD89](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/l1z4rd89/32/1194537_2.png) [@L1z4rD89](https://forums.unrealengine.com/u/L1z4rD89)\
**Post date:** [April 25, 2023, 4:36pm UTC](https://forums.unrealengine.com/t/how-to-find-the-intersection-point-of-a-vector-and-a-radius/1138579/3 "2023-04-25T16:36:50Z")

</div>

Hey @JohnnyBichevski

you can use 2 methods to achieve this:

1. Use the law of sines and from here calculate all values for a triangle  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/0/7/907b097a31fe347f63aaccd957c24cef106d89a1.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/1/d/91dfd3e2952f99b96bd0533e2e97bd49ec42da57.png)  
[Triangle Calculator](https://www.calculator.net/triangle-calculator.html)  
Start would be the triangle with g f h and then g f i

```auto
int main(){
    
    double xa,xb,xc,ya,yb,yc,za,zb,zc,r,dot,lenSq1,lenSq2,angle,intersect;
    r=6;

    cout << "Enter triangle coordinates\n";
    cout << "Point A: ";
    cin >> xa;
    cin >> ya;
    cin >> za;
    cout << "Enter triangle coordinates\n";
    cout << "Point B: ";
    cin >> xb;
    cin >> yb;
    cin >> zb;
    cout << "Enter triangle coordinates\n";
    cout << "Point C: ";
    cin >> xc;
    cin >> yc;
    cin >> zc;
    
    vector<double> v1 { xb-xa,yb-ya,zb-za};
    vector<double> v2 { xc-xa,yc-ya,zc-za};
    
    dot = v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
    lenSq1 = v1[0]*v1[0] + v1[1]*v1[1] + v1[2]*v1[2];
    lenSq2 = v2[0]*v2[0] + v2[1]*v2[1] + v2[2]*v2[2];
    angle = abs(acos(dot/sqrt(lenSq1 * lenSq2)));
    
    intersect = sin(3.14159265358979323846-angle-asin(sqrt(v2[0]*v2[0]+v2[1]*v2[1]+v2[2]*v2[2])*sin(angle)/r))*r/sin(angle);
    intersect = sqrt((intersect*intersect)/(v1[0]*v1[0]+v1[1]*v1[1]+v1[2]*v1[2]));
    cout << intersect;
}

```

1. Use the equations for the circle and the vector in paramteric form to create an quadratic equation and then solve this to get 0, 1 or 2 solutions / points / intersections.  
[Get location of vector/circle intersection? - Mathematics Stack Exchange](https://math.stackexchange.com/questions/311921/get-location-of-vector-circle-intersection)  
[Quadratic equation - Wikipedia](https://en.wikipedia.org/wiki/Quadratic_equation#Alternative_quadratic_formula)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/0/4/30446478ad80ebc339c96fdeb14f756e84c6c7d9.png)

```auto
int main() {
    double a,b,c,xa,xb,ya,yb,xc,yc,r,s,t,dx,dy;

    cout << "Enter triangle coordinates\n";
    cout << "Point A: ";
    cin >> xa;
    cin >> ya;
    cout << "Enter triangle coordinates\n";
    cout << "Point B: ";
    cin >> xb;
    cin >> yb;
    cout << "Enter triangle coordinates\n";
    cout << "Point C: ";
    cin >> xc;
    cin >> yc;
    
    r=6;
      
    
    a=pow((xb-xa),2)+pow((yb-ya),2);
    b=2*(xb-xa)*(xa-xc)+2*(yb-ya)*(ya-yc);
    c=pow((xa-xc),2)+pow((ya-yc),2)-pow(r,2);
    
    dx=xb-xa;
    dy=yb-ya;
    
    if(b*b-4*a*c==0){
        s=(b*(-1)+sqrt(b*b-4*a*c))/(2*a);
        cout << xa+s*dx << ", " << ya+s*dy;
    }
    else if(b*b-4*a*c>0){
        s=(b*(-1)+sqrt(b*b-4*a*c))/(2*a);
        t=(b*(-1)-sqrt(b*b-4*a*c))/(2*a);
        if(s>=0){
            cout << xa+s*dx << ", " << ya+s*dy << "\n";
            }
        if(t>=0){
            cout << xa+t*dx << ", " << ya+t*dy << "\n";
            }

        
    }
    else{
       cout << "No intersection";
    }
    
}

```

[427Intersection.zip](https://forums.unrealengine.com/uploads/short-url/3zs6rpLNyyKOhZDzPBNox5rl6Y3.zip) (188.2 KB)  
[503Intersection.zip](https://forums.unrealengine.com/uploads/short-url/tmwGP430XHaaR6RgmUNQlWieeuh.zip) (209.6 KB)  
[511Intersection.zip](https://forums.unrealengine.com/uploads/short-url/s31N2SEZsjslmfze0ZPMVig4qPM.zip) (215.8 KB)
