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 DemSec · Apr 08, 2019 at 09:12 AM · angleeuleranglesvectormatrix

On which side of the vector on graph is the origin? [Geometry]

I have a vector on a graph. The position of the vector on the graph is known. The vector value is normalized and is known. If the graph is divided along the vector's position and direction, on which side is the origin, left or right?

 float x = someValue;
 float y = otherValue;
 Vector2 vector = someVector.normalized;
 
 // Find:
 bool originIsOnRight;

Given these variables, how to calculate originIsOnRight?

alt text

notes-190407-191723-b1b-1.jpg (28.9 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

1 Reply

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

Answer by Bunny83 · Apr 08, 2019 at 09:26 AM

The way you specify your input variables is very confusing. First of all a 2d vector is just a pair of two numbers (x and y). So the given values are actually two vectors. One that specify the point (x,y) and one that specify the direction you're interested in. Next keep in mind that vectors themselfs do not have a position. This is all just interpretation. Technically all vectors (whether they are positions or directions) start at the origin. It doesn't have to be the world origin and could be any space they belong to. However this information is not part of the vector itself.


About your issue: All you have to do is check the dot product between the vector from the origin to your point and the perpendicular of your vector / direction. This will tell you if the (world) origin is to the left or right. You get the perpendicular of a 2d vector by simply swapping it's coordinates and negate one of them. Which you negate will determine if you rotate 90° clockwise or counter clockwise.


For example:

 Vector2 p; // our point (x,y)
 Vector2 d; // our direction "vector"
 
 Vector2 normal = new Vector2(-d.y, d.x); // clockwise rotation
 float dot = Vector2.Dot(p, normal);
 if (dot > 0)
 {
     // the origin is to the left of vector
 }
 else if (dot < 0)
 {
     // the origin is to the right of vector
 }
 else
 {
     // the vector passes through the origin
 }

Are you sure this is actually a game development question? This sounds more like a school geometry question. I've moved the question into the help room since it's not really Unity related.

Comment
Add comment · Show 1 · 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 Bunny83 · Apr 08, 2019 at 09:38 AM 0
Share

Ok by looking at your profile you seem to be serious and it's not a "school question" ^^. Btw if you do a counter clockwise rotation like this:

 Vector2 normal = new Vector2(d.y, -d.x); // note the "-" has moved to the second argument

The left / right conditions would be inverted. So in this case if dot is greater than 0 the origin would be on the right, if it's smaller it would be on the left side.


The dot product is one of the cheapest vector operations you can do. The vectors do not need to be normalized. The dot product is simply:

 float Dot(Vector2 a, Vector2 b)
 {
     return a.x * b.x + a.y * b.y;
 }

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

105 People are following this question.

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

Related Questions

How to get vector rotated by specyfic angle? 0 Answers

Quaternion Rotation - AngleAxis/EulerAngle 2 Answers

Calculating Relative angles 1 Answer

Change angle of a moving object but maintain direction of movement? 0 Answers

Get angle between facing direction and a point 0 Answers


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