• 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 DanS · Dec 22, 2011 at 10:10 PM · vector3angle

Calculate a point from a Vector3 by X units in Y direction

I'm trying to draw a triangle on the end of a line to create an arrow, but I'm struggling to figure out how to calculate the points for it.

I've obviously got the Vector2s for the start and end of the line and I use one of them for the as the start point for the arrow, then I need two more points either side of the line. I'm sure there's a simple solution to this but my grasp of manipulating co-ordinates isn't strong enough to figure it out.

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 · Dec 23, 2011 at 12:41 AM

I'm not sure what exactly you need. Do you have 2d points or 3d points? Do you want to draw in 2d (GUI?)

I'll assume you have Vector2 points (like you've mentioned) since that's easier ;)

// I'll use C# since that's my language and you didn't specify which one you want to use ;)

Vector2 P1; // start point vector2 P2; // end point

Vector2 direction = (P2-P1).normalized; // normalized direction

Vector2 right = new Vector2(direction.y,-direction.x); // vector rotated clockwise 90°

Vector2 Pright = P2 + right*halfSide; Vector2 Pleft = P2 - right*halfSide;

// To make an "equilateral triangle" you just have to go //into "direction" by sqrt(3)halfSide Vector2 Pahead = P2 + direction halfSide * 1.7320508f;

See the height(altitude) of an Equilateral Triangle on wikipedia if you're interested.

Comment
Add comment · Show 5 · 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 DanS · Dec 23, 2011 at 10:09 AM 0
Share

That was perfect, thanks!

(I'm drawing in 3D, but on a flat plane (only X and Z change), so while they're Vector3s I'm treating them as Vector2s)

avatar image ks13 · Dec 23, 2011 at 10:54 AM 0
Share

Just wanted to add that there is a convenient $$anonymous$$oveTowards method for VectorXs :)

avatar image Bunny83 · Dec 23, 2011 at 01:04 PM 0
Share

@ks13: Sure, but how does this help in this situation? He needs the normal vector of the line. Do you want to use it for the Pahead-point calculation? Also $$anonymous$$oveTowards is designed to perform a s$$anonymous$$dy movement (at the speed of maxDistanceDelta) towards the target. I don't see any reason in this case to use $$anonymous$$oveTowards. Did i miss something? ;)

avatar image ks13 · Dec 23, 2011 at 07:18 PM 0
Share

Sorry, my bad, mixed this with another method, or maybe not. I remember one bein able to give you a point from a starting point going in a direction for some distance. That way you only have to get the direction and use it to get the 2 wanted points from the end of the line. But i suppose your method is simpler.

avatar image Bunny83 · Dec 24, 2011 at 01:17 AM 0
Share

@ks13: I think you don't understand the question ;) He wants to form an arrow-shape (triangle) at one end of his line. The two bottom points of the triangle doesn't lie on the line. However, the function you had in $$anonymous$$d was "lerp" (linear interpolation). But it usually clamps the t-parameter between 0 and 1 so you can't go beyond the two points.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

How to calculate a Vector3 point having three given Vector3 points and an angle of 90 degrees? 1 Answer

change angle of vector3 0 Answers

Angle between two vector3 relative to a certain point 1 Answer

Find Vector3 from a starting Vector3, angle, and distance. 1 Answer

Average of Normals 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