- Home /
              This question was 
             closed Mar 14, 2020 at 10:44 PM by 
             ThatBulgarian for the following reason: 
             
 
            Other
 
               Question by 
               ThatBulgarian · Mar 14, 2020 at 01:34 PM · 
                mathangleprojectiontrigonometry  
              
 
              Calculate mid angle position based on three points
Hi,
How can I calculate the position of p4 such that it's always halfway between the angle of p1,2,3?
Thanks!

 
                 
                untitled.jpg 
                (25.5 kB) 
               
 
              
               Comment
              
 
               
              Answer by BBIT-SOLUTIONS · Mar 14, 2020 at 04:14 PM
There's maybe a better fancy mathematical formula also, but i guess, you could just use a temporarily helper GameObject for this purpose.
Herefore you should have to calculate the angle between the 2 vectors and also their average length. Rotate the helper object to this angle and move it to the position. Something like this could maybe work (not tested):
 float angle = Vector3.Angle(p1-p2, p3-p2) / 2f;
 float length = (Vector3.Distance(p1,p2) + Vector3.Distance(p3,p2)) / 2f;
 
 //helper GameObject
 GameObject p4GO = new GameObject("p4");
 p4GO.transform.position = p2;
 p4GO.transform.LookAt(p1);
 p4GO.transform.Rotate(Vector3.up, angle);//maybe use Vector left or forward instead
 p4GO.transform.position += p4GO.transform.forward * length;
 Vector3 p4 = p4GO.transform.position;
 
 //here you can destroy the helper, if only the Vector3 is needed
 Destroy(p4GO);
 
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                