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 AronTD · Feb 06, 2014 at 02:21 AM · axisdistancecustomlocal axis

How can I get the distance from point a to point b on a custom axis? (Includes pictures)

Trying to find the distance from point a to point b given a custom axis. I have some pictures to help me better explain:

alt text

I'm trying to find the distance from red to pink (or gray) on two custom axes. The axis from red to green (axis RG) and the axis from red to blue (axis RB). The colored lines are just to help show where the points are in 3D space. The "points" are located at the bottom of the colored lines shown. These colored lines just point straight up in the air for reference.

Here's a link to a few more pictures for clarification.

I'll give you a free copy of my game when it's finished if you can help me out.

unity2.png (232.6 kB)
unity1.png (271.6 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 sooncat · Feb 06, 2014 at 02:52 AM 0
Share

I'm confused that the red and pink is two lines not points. if you means "the point red/pink line crossed with the plane" Vector3.Distance is useful.(use point.transform.position as parameter)

avatar image robertbu · Feb 06, 2014 at 03:18 AM 0
Share

Even with all the drawings, I'm confused by your question. What defines the two points you want to measure from? Are you looking for the closest point on the two lines or something else? Are the two axes always parallel? Are you looking for the shortest distance between the two lines?

avatar image AronTD · Feb 06, 2014 at 03:42 AM 0
Share

@sooncat the lines are just to help point out the points in 3D space. The "points" are located at the bottom of the red and pink lines. These lines just point straight up in the air for reference.

@robertbu trying to implement something like this. I'm measuring (horizontally only) from the red point (known) to the pink point (known) relative to my axes. The two axes are never parallel and they're never perpendicular.

avatar image robertbu · Feb 06, 2014 at 04:12 AM 0
Share

Take a look at the $$anonymous$$ath3D script in the Unity Wiki. There are several things that may help you in there. In particular, you may be looking for ClosestPointsOnTwoLines(). Given the two point, you can calculate the distance between them.

avatar image Scribe · Feb 06, 2014 at 05:40 AM 1
Share

I'm not certain I understand your question but it looks like you want to measure from the red point to the point on an axis that is closest to the pink point: alt text

If that is the case then you can do it quite simply like:

 var point1 : Vector3;
 var point2 : Vector3;
 private var pointVector : Vector3;
 
 var axis1 : Vector3;
 var axis2 : Vector3;
 
 pointVector = point2-point1;
 
 distance from axis1 is: Vector3.Project(pointVector, axis1).magnitude
 distance from axis2 is: Vector3.Project(pointVector, axis2).magnitude


Scribe

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by alok1974 · Feb 06, 2014 at 04:37 AM

Here's the psuedocode:

let v_rp be Vector from red to pink then, v_rp = transform.poition of pink - transform.position of red

let d_rp be distance between red to pink then, d_rp = v_rp.magnitude

ler v_rg be Vector from red to green then, v_rg = transform.poition of green - transform.position of red

let theta be angle between v_rp and v_rg then, theta = Vector3.Angle(v_rg, v_rp)

convert theta to radians theta *= Mathf.Deg2Rad

then distance d between red to pink projected on the axis of red to green is given by:

d = d_rp / Mathf.Cos(theta)

That's it. Now to get the same for on red to blue axis, just replace green by blue in the above pseudo code.

Rest remains the same.

Cheers!

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

22 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

Related Questions

A node in a childnode? 1 Answer

Checking camera distance between object in a AR game 1 Answer

Fog only working on light sources? 1 Answer

Unity or Custom Engine? 1 Answer

Wrong Camera axis after "zoom" to GameObject 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