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
1
Question by sdgd · Mar 10, 2014 at 02:35 PM · c#mathpythonoafa

How to convert Python in to C#? Maths or find Shortest distance between two skew lines in 3D space.

I think it'll be enough if I understand what

 np.linalg.norm(A)
 np.linalg.det([t, _A, cross])
 np.cross(_A, _B)

does

Python code founded here 6. answer by @Fnord

I was looking at their doc, but I couldn't understand a thing it's even worst than in MSDN doc

EDIT:

I deleted my code as my assumptions were totally incorrect.

even if my original Question wasn't answered my original problem was solved.

Problem:

how to find 2 closest points between two skew lines in 3D

this gr8 tutorial could've helped me IF I'd understood how to learn programmatically what t and s is.

Also I found this Q/A before but it doesn't work correctly.

Comment
Add comment · Show 2
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 suribe · Mar 10, 2014 at 03:56 PM 0
Share

This is definitely not a Unity question, you should try on some C# forum...

avatar image robertbu · Mar 10, 2014 at 04:02 PM 1
Share

@suribe - actually his question is how to translate the vector math functions in the Phyton code into Unity vector math functions. This seems like a reasonable Unity question since it is primarily about Unity's vector class (and maybe their matrix classes).

1 Reply

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

Answer by sdgd · Mar 10, 2014 at 04:56 PM

ok someone helped me and solved my original problem:

 //Two non-parallel lines which may or may not touch each other have a point on each line which are closest
 //to each other. This function finds those two points. If the lines are not parallel, the function 
 //outputs true, otherwise false.
 public static bool ClosestPointsOnTwoLines(out Vector3 closestPointLine1, out Vector3 closestPointLine2, Vector3 linePoint1, Vector3 lineVec1, Vector3 linePoint2, Vector3 lineVec2){
 
     closestPointLine1 = Vector3.zero;
     closestPointLine2 = Vector3.zero;
 
     float a = Vector3.Dot(lineVec1, lineVec1);
     float b = Vector3.Dot(lineVec1, lineVec2);
     float e = Vector3.Dot(lineVec2, lineVec2);
 
     float d = a*e - b*b;
 
     //lines are not parallel
     if(d != 0.0f){
 
         Vector3 r = linePoint1 - linePoint2;
         float c = Vector3.Dot(lineVec1, r);
         float f = Vector3.Dot(lineVec2, r);
 
         float s = (b*f - c*e) / d;
         float t = (a*f - c*b) / d;
 
         closestPointLine1 = linePoint1 + lineVec1 * s;
         closestPointLine2 = linePoint2 + lineVec2 * t;
 
         return true;
     }
 
     else{
         return false;
     }
 }

posting this as it probably will help others.

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 robertbu · Mar 10, 2014 at 05:37 PM 2
Share

To give credit where credit is due, this code appears to be pulled from the $$anonymous$$ath3d class in the Unity Wiki.

http://wiki.unity3d.com/index.php/3d_$$anonymous$$ath_functions

avatar image sdgd · Mar 10, 2014 at 07:49 PM 0
Share

Interesting, ... didn't know it was there, ... +1

could be someone that helped me was getting data from there, ...

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

21 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Pyke, IronPython and Unity 5 0 Answers

Set the speed of an object by its distance with another object 1 Answer

Checking which thruster to fire. Need help with the math 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