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 RyuMaster · Nov 04, 2014 at 02:09 PM · vector3distance

find furthest point in relative to 2 others

Hi! Here is diagram of my problem:

alt text

I need to find point, which is 14m away from point A, and as far as possible, from point B.

Brutforce way, I can simply check radius of circle of point A for every angle:

 double x = 14f * Math.Cos(Mathf.Deg2Rad * angle);
 double y = 14f * Math.Sin(Mathf.Deg2Rad * angle);

and then compare (x,y) distance to point B.

But is it very long and stupid solution, like I'll need to run it 360 times for every angle.

What is the most elegant way, using vector math?

diagramm.png (51.2 kB)
Comment
Add comment · Show 5
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 Hullu · Nov 04, 2014 at 02:45 PM 0
Share

"as far as possible, from point B"

So the point would be always 14m behinde A relative to B, right?

avatar image RyuMaster · Nov 04, 2014 at 02:46 PM 0
Share

Relative to A, point is always 14m away. But relative to B, it should be as far as possible.

I.e. point is always somewhere on a circle, with center in point A and radisu 14m

avatar image Hullu · Nov 04, 2014 at 02:48 PM 0
Share

Oh, sorry... so the point can be more than 14m away from A?

edit: Or did you mean the opposite?

avatar image Mayank Ghanshala · Nov 04, 2014 at 02:55 PM 0
Share

as far as possible will be only one point in which 3 of point will be in a line means AB + 14. You can check for a line .

avatar image Tepei · Nov 04, 2014 at 02:59 PM 0
Share

So the point would always be from a the inverse direction from b?

1 Reply

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

Answer by tanoshimi · Nov 04, 2014 at 02:54 PM

Attach this to your target point:

 #pragma strict
 
 var A : Transform;
 var B : Transform;
 
 function Update () {
     transform.position = A.position + (A.position - B.position).normalized * 14;
 }


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 fafase · Nov 04, 2014 at 03:00 PM 0
Share

For the explanation, the point you are after lies on the circle C with center A and radius 14 since all point at distance 14 from A makes a circle.

Now wherever B may be, you are looking for the point that is pretty much opposite of B onto C. And this point HAS to be the point lying on the ray from B towards A.

So you get :

 B -> A (a.position - b.position)
 you normalized because we only want the direction
 Starting from A you extend by 14 to find that point on the circle
 point = A.position + (A.position - B.position).normalized * 14;

And tadaa.

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

29 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

Related Questions

Vector3.Project, how to? 2 Answers

Getting vectors on an object every so many units 0 Answers

Working out which vector 3 is closest 1 Answer

Enemy Jitters when i want him to stop a certain distance 0 Answers

How do I find the farthest verts of a mesh relative to its object position and store them in an array 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