Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by GarretLawrence · Jan 21, 2017 at 02:15 PM · c#vector3math

Check if a point is on the right or left of a vector?

alt text

I have vector BA and a point C ( in a 3D world but assume they all have same Y).

How do i check if C is on the right or the left of vector BA

untitled-1.jpg (31.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by tanoshimi · Jan 21, 2017 at 02:23 PM

You could calculate this by testing the sign of the Cross Product between the vectors BA and BC. Or if you're only operating in 2D space, try this...

 bool IsLeft(Vector2 A, Vector2 B)
 {
     return -A.x * B.y + A.y * B.x < 0);
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MarekM2 · Dec 08, 2018 at 08:42 AM 2
Share

What do you mean by testing the sign of cross product?

avatar image The_Pied_Shadow · Dec 28, 2020 at 05:23 PM 0
Share

How is this the answer? The formula doesn't even include point C, how could it test if it's on the left or right of anything?

avatar image
1

Answer by The_Pied_Shadow · Dec 29, 2020 at 02:00 PM

To do this it's safe to assume we're thinking about these points in 2D space. If you want to determine a left or right of line you have to define what exactly left or right means. Is left positive y? positive z? Unity considers 'left' to be in the negative x direction and 'right' in the positive x direction whether in world or local space. For this answer I'll assume the same I just wanted to make note of it so if someone was operating on a different 2D plane assumption they would need to adjust the formula accordingly.


 Vector3 vec = A.position - B.position;
 Vecotr3 dir = C.position - B.position;
 
 Vector3 cross = Vector3.Cross(vec, dir);

Here 'vec' represents a the vector you want to test the location relative to. 'Dir' is a vector from the origin position of 'vec' to the point you want to check.


In this case, the y value of the variable 'cross' will be positive when on the right side of the line and negative when on the left. This is relative to the direction of the line (in this case from point B looking at point A). So in the diagram you showed, if you plugged the positions of all these points in then the cross product would have a negative value for C.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Calculate arithmetic problem from text 1 Answer

Get a Vector3 to always have a radius of 1 from 0, 0, 0 2 Answers

How to Use Accelerometer to Move Object by Tilting Phone? 1 Answer

Quick question with a Camera Following script 1 Answer

How to call Random.insideUnitSphere.x Once 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges