Home > Back-end >  Find a point perpendicular to the middle of a line LineRenderer
Find a point perpendicular to the middle of a line LineRenderer

Time:10-21

enter image description here

CodePudding user response:

To find the midpoint of two points (your 'start' and 'end' points), you can just add the points together and then divide by 2:

var mid = ( start   end ) / 2;
var direction = end - start;
var perp = Vector2.Perpendicular(direction);

You'll now have a vector that is perpendicular to your line segment. Now you'll just have to determine how far along that perpendicular you'd like to travel, and reposition it to start at the mid point:

var apex = (perp.normalized * height)   mid;

Where apex here is 'C' in your example diagram, and height is a value you define.

  • Related