# 2D perpendicular vector

This topic is 3891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello. I am writing a generic Matrix / Vector library for the C# language. I am not especially great at math and that is partly why I am doing this as an exercise. One of the methods I would like is to calculate the 2D perpendicular vector to another. I wrote the following code which seems to do that just fine.
        public Vector3D getPrependicular()
{
float mx = this.Y / this.X;
mx = -1 / mx;

float y = (this.X * mx);

return new Vector3D(this.X, y, 1);
}

However when I draw the perpendicular vector, although the angle is 90 degrees, its distance is scaled drastically. I would like the length of the perendicular vector to be that of the original vector. How would I go about doing that? Thanks in advance!

##### Share on other sites
You can just swap the x and y, and then flip the sign on one of them.

##### Share on other sites
I believe I did that

            float mx = this.Y / this.X;            mx = -1 / mx;

What I need to know is how to scale my perpendicular vector back to the size of the original vector.

Thanks!

##### Share on other sites
Oh I see what you mean!

        public Vector3D getPrependicular()        {            return new Vector3D(this.Y, -this.X, 1);        }

Thanks again!

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 42
• ### Forum Statistics

• Total Topics
632635
• Total Posts
3007559
• ### Who's Online (See full list)

There are no registered users currently online

×