Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:06:48+00:00 2026-06-15T13:06:48+00:00

I am trying to implement wall following steering behaviour in C# . For that

  • 0

I am trying to implement wall following steering behaviour in C#. For that I have a point and a line segment. All I need is a perpendicular point C so that line segment CD is perpendicular to AB. http://puu.sh/1xrxQ This is the scenario. The point is moving so I need to calculate it every time. I am new to c# so I don’t know how it works.

This is what I have tried till now to get it working.

private double DotProduct(Point pointA, Point pointB, Point pointC)
{
    Point AB = new Point();
    Point BC = new Point();
    AB.X = pointB.X - pointA.X;
    AB.Y = pointB.Y - pointA.Y;
    BC.X = pointC.X - pointB.X;
    BC.Y = pointC.Y - pointB.Y;
    double dot = AB.X * BC.X + AB.Y * BC.Y;

    return dot;
}

//Compute the cross product AB x AC
private double CrossProduct(Point pointA, Point pointB, Point pointC)
{
    Point AB = new Point();
    Point AC = new Point();
    AB.X = pointB.X - pointA.X;
    AB.Y = pointB.Y - pointA.Y;
    AC.X = pointC.X - pointA.X;
    AC.Y = pointC.Y - pointA.Y;
    double cross = AB.X * AC.Y - AB.Y * AC.X;
    return cross;
}

//Compute the distance from A to B
double Distance(Point pointA, Point pointB)
{
    double d1 = pointA.X - pointB.X;
    double d2 = pointA.Y - pointB.Y;

    return Math.Sqrt(d1 * d1 + d2 * d2);
}

//Compute the distance from AB to C
//if isSegment is true, AB is a segment, not a line.
double LineToPointDistance2D(Point pointA, Point pointB, Point pointC, bool isSegment)
{
    double dist = CrossProduct(pointA, pointB, pointC) / Distance(pointA, pointB);
    if (isSegment)
    {
        double dot1 = DotProduct(pointA, pointB, pointC);
        if (dot1 > 0)
            return Distance(pointB, pointC);

        double dot2 = DotProduct(pointB, pointA, pointC);
        if (dot2 > 0)
            return Distance(pointA, pointC);

     }
     return Math.Abs(dist);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:06:49+00:00Added an answer on June 15, 2026 at 1:06 pm

    Not tested, but mathematically this should work

    Point intersectionPoint(Point A, Point B, Point C) {
        //check for slope of 0 or undefined
        if (A.Y == B.Y) return new Point (C.X, A.Y);
        if (A.X == B.X) return new Point (A.X, C.Y);
        //slope = (y1 - y2) / (x1 - x2)
        double slopeAB = (A.Y - B.Y) / (A.X - B.X);
        //perpendicular slope is the negative reciprocal
        double slopeCD = -1 / slopeAB;
        //solve for b in y = mx + b of each line
        //  b = y - mx
        double bAB = A.Y - slopeAB * A.X;
        double bCD = C.Y - slopeCD * C.X;
        double dX, dY;
        //intersection of two lines is m1x + b1 = m2x + b2
        //solve for x: x = (b2 - b1) / (m1 - m2)
        //find y by plugging x into one of the equations
        dX = (bCD - bAB) / (slopeAB - slopeCD);
        dY = slopeAB * dX + bAB;
        return new Point(dX, dY);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement the following behavior on an iPad. I have a map-centric application
Trying to implement a timer for my game that I'm making. I have a
Trying to implement a simple print in SL4. I have a DataGrid that I
I am trying to implement facebook login and wall post in Android, so I
I am trying to implement example of visitor pattern, but I have trouble with
I have an older VB6 project that I'm trying to add unit tests for.
Trying to implement following queries in NHibernate QueryOver. SQL SELECT SUM(GrossChargeAmount) FROM Charges INNER
In trying to implement the Twitter code at http://www.voiceoftech.com/swhitley/?p=681 I am getting a compile
I am trying to implement Facebook in my iPhone app and I have successfully
I am trying to implement A* in Java but i have hit a brick

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.