- Home /
Question by
Ixniy · Jan 22, 2018 at 10:22 AM ·
anglevector2perpendicular
How to build a perpendicular of a certain length for a segment rotated to some angle?
How to build a perpendicular of a certain length for a segment rotated to some angle?
I'm particularly interested in the coordinates of point C
без-имени-1.png
(59.5 kB)
Comment
Best Answer
Answer by hrishihawk · Jan 22, 2018 at 02:23 PM
You can use the concept of vectors to get the perpendicular line.Referring the following website Perpendicular Vector I have made a method that returns the coordinates of C.
/*
This funcion return the coordinates of C
start = Start point of the line segment (A in your case)
end = end point of the line segment (B)
origin = from which point you wan to draw a perpendicular (A in your case)
length = length of the perpendicular
*/
private Vector2 perpendicularVector2(Vector2 start, Vector2 end,Vector2 origin,int length)
{
Vector2 direction = (end - start).normalized;
Vector2 perpendicularDirection = new Vector2(-1*direction.y,direction.x).normalized;
Vector2 requiredLengthVector2 = perpendicularDirection * length;
Vector2 resulVector2 =new Vector2( requiredLengthVector2.x + origin.x , requiredLengthVector2.y+origin.y);
return resulVector2;
}
Thanks for the answer! I'll check your solution in the near future, thank you again.