Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity get distance between line and point

public Vector2 FindNearestPointOnLine(Vector2 origin, Vector2 end, Vector2 point)
{
    //Get heading
    Vector2 heading = (end - origin);
    float magnitudeMax = heading.magnitude;
    heading.Normalize();

    //Do projection from the point but clamp it
    Vector2 lhs = point - origin;
    float dotP = Vector2.Dot(lhs, heading);
    dotP = Mathf.Clamp(dotP, 0f, magnitudeMax);
    return origin + heading * dotP;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: toLocalIsoString() vs toIsoString() 
Csharp :: c# code to check anagram 
Csharp :: c# xunit theory classdata model 
Csharp :: unity easing out 
Csharp :: Reading emails from Gmail in C# 
Csharp :: count number of rows in a table in c# 
Csharp :: Get location in Xamarin - NAYCode.com 
Csharp :: unity c# image invisible 
Csharp :: c# builder pattern fluent example 
Csharp :: rgb to console color 
Csharp :: Test for even Number 
Csharp :: asp.net listbox disable selection 
Csharp :: how prevent user remove file linux 
Csharp :: c# reflection get property value array 
Csharp :: datagridview column index 
Csharp :: base c# 
Csharp :: c# external execute batch 
Csharp :: unity save scene at runtime 
Csharp :: linq c# where condition 
Csharp :: c# comments 
Csharp :: c# if else 
Csharp :: restrictions 
Csharp :: out c# 
Csharp :: what is int.parse in c# 
Csharp :: calculate textbox value c# 
Csharp :: active form 
Csharp :: how to c# 
Csharp :: c++ printwindow chrome 
Csharp :: windows forms change double buffer during runtime 
Csharp :: close an open form when you open it again c# 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =