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 AndreasX12 · Apr 06, 2014 at 05:26 PM · meshvertexpointclosestnearest

Boat physics

Hi.

I'm trying to make a boat physics script.. To do so, I have to find the nearest vertex on a mesh.

So how can I find the nearest vertex on a mesh?

For exampel:

Vector3 point = (1,33,7); // The Vector3 from where it should find the nearest vertex on the mesh "mesh".

MeshFilter mesh = OceanGameObject.GetComponent(); // The mesh

Vector3 nearestVertex = The nearest vertex on the mesh "mesh" from "point"

How would this be possible?

Thanks in advance,

Andreas.

Comment
Add comment · Show 3
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 Benproductions1 · Apr 08, 2014 at 11:41 AM 0
Share

Linear search?

avatar image AndreasX12 · Apr 08, 2014 at 12:38 PM 0
Share

Simpply just the nearest vertex on the mesh in Vector3 world space.

avatar image Benproductions1 · Apr 10, 2014 at 07:28 AM 0
Share

Yes, you said that in the question...

2 Replies

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

Answer by Benproductions1 · Apr 10, 2014 at 07:30 AM

Perform a linear search through all the vertices in your mesh, finding the vertex with the least distance to your point in local space. To transform the point from world space to local space, use Transform.InverseTransformPoint.

To speed it up you could use some sort of tree structure instead of a linear search and find the nearest vertex that way, however that might get a little complicated ;)

Comment
Add comment · Show 2 · 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 AndreasX12 · Apr 12, 2014 at 07:08 AM 0
Share

Thanks for your answer. But how exactly do I perform a linear seach? I couldn't find any documentation? Or if possible, could you share some sample code? :)

Thanks in advance.

Andreas.

avatar image Benproductions1 · Apr 14, 2014 at 09:05 AM 0
Share

You couldn't do a google search on the term "linear search"? Are you serious?

avatar image
0

Answer by thomasindustry · Apr 09, 2014 at 06:57 PM

the vertices property on a mesh will give you the local positions of all the vertices of the mesh. You can then use the Transform.TransformPoint method to convert these positions to world space for comparisons with your reference point.

Comment
Add comment · Show 2 · 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 AndreasX12 · Apr 10, 2014 at 05:48 AM 0
Share

Okay, so how do I actually find the nearest mesh vertex?

avatar image Benproductions1 · Apr 10, 2014 at 07:25 AM 0
Share

It would be more efficient to transform the point to local space once, rather than the other way around for every vertex.

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

23 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

Related Questions

how to increase thickness of points? 1 Answer

Why vertex positions appear (0.0, 0.0, 0.0) ? 1 Answer

Vertex colours not blending across triangle face 1 Answer

Rendering Mesh Points on Mobile 0 Answers

Spherical Terraing LOD 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