Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Chrisg · Apr 24, 2011 at 10:24 AM · 2drotationvectorvector2

Vector rotation

I have 3 values which I want to represent on a bar graph like display. The catch is I want the bars to come out rotated around a central point, to form a triangular shape. The values are variable, but the total is limited. Something like this.

The values are a, b and c, along vectors o-e, o-g, o-f.

My issue is the math behind it. I can follow the formula easy enough, but have yet to figure out how to apply it correctly in this instance. I'm trying to place point a at the correct distance, then rotate it by 120 degrees(circle/3) to get my three vectors. However, they all shoot off at random angles.

I assume my problem is a) Not getting the direction vectors correct and b) not extending along these correctly. I've looked at wolfram, even the wolfire blog linked in another answer, but can't wrap my head around where I'm going wrong.

Relevant code attached.

var oPos : Vector2 = Vector2(5, 5); var oAng : Vector2;

var currentAng : float = 0; var theta : float = 120.0;

var aPos : Vector2; var aAng : Vector2; var aDist : int = 7;

var bPos : Vector2; var bAng : Vector2; var bDist : int = 7;

var cPos : Vector2; var cAng : Vector2; var cDist : int = 7;

private var newAng : Vector2; private var newPos : Vector2;

function Start() {
oAng = Vector2(0, 0); aPos = oPos + Vector2(aDist, aDist);

 bPos = oPos + Vector2(bDist, bDist);
 bPos.x = (bPos.x * Mathf.Cos(theta)) - (bPos.y * Mathf.Sin(theta));
 bPos.y = (bPos.x * Mathf.Sin(theta)) + (bPos.y * Mathf.Cos(theta));


 cPos = oPos + Vector2(cDist, cDist);
 cPos.x = (cPos.x * Mathf.Cos(theta*2)) - (cPos.y * Mathf.Sin(theta*2));
 cPos.y = (cPos.x * Mathf.Sin(theta*2)) + (cPos.y * Mathf.Cos(theta*2));

}

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
0
Best Answer

Answer by Peter G · Apr 24, 2011 at 11:59 AM

Unity has a convenient operator for rotating Vector's.

var distFromCenter : float;

var firstPoint : Vector3 = Vector3.up; var secondPoint : Vector3 = Vector3.up; var thirdPoint : Vector3 = Vector3.up;

var rotationAngle : float = 120.0;

function Start() { var rotation : Quaternion = Quaternion.AngleAxis(rotationAngle, Vector3.forward);

   firstPoint *= rotation;
   firstPoint *= distFromCenter;

   secondPoint *= rotation;
   secondPoint *= distFromCenter;

   thirdPoint *= rotation;
   thirdPoint *= distFromCenter;

}

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 Chrisg · Apr 28, 2011 at 06:19 PM 0
Share

Sorry it took so long to reply.

The Point *= rotation; lines don't work, took me this long to get the google search right to find this thread: http://forum.unity3d.com/threads/36737-Vector3-rotation

Worked once I changed "Point = rot" to "Point = rot Point".

Otherwise perfect - ta muchly.

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

No one has followed this question yet.

Related Questions

Z Axis look at another object direction 1 Answer

2 fingers sprite rotation 1 Answer

Rotate an object around another object at an angle from the X axis? 1 Answer

Basic 2D movement C# - Key presses cancel eachother out 4 Answers

Making sprites just rotate and not tilt. 3 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