Last active
January 16, 2020 12:01
-
-
Save inoook/cfda1cbf1065114af622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector3 p0 = new Vector3(-1,0,0); | |
Vector3 p1 = new Vector3(1,0,0); | |
Vector3 p2 = new Vector3(0,-1,0); | |
Vector3 p3 = new Vector3(0,1,0); | |
Gizmos.DrawLine(p0, p1); | |
Gizmos.DrawLine(p2, p3); | |
Vector3 pt = getCrossPoint(p0, p2, p1, p3); | |
Gizmos.DrawWireSphere( pt, 0.1f); | |
// http://imagingsolution.blog107.fc2.com/blog-entry-137.html | |
// http://www.mztm.jp/2010/08/05/clossline/ | |
Vector3 getCrossPoint(Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4){ | |
float S1 = ((P4.x-P2.x)*(P1.y-P2.y)-(P4.y-P2.y)*(P1.x-P2.x))*0.5f; | |
float S2 = ((P4.x-P2.x)*(P2.y-P3.y)-(P4.y-P2.y)*(P2.x-P3.x))*0.5f; | |
Vector3 crossPoint = new Vector3(0,0,0); | |
crossPoint.x = P1.x + (P3.x-P1.x)*(S1/(S1 + S2)); | |
crossPoint.y = P1.y + (P3.y-P1.y)*(S1/(S1 + S2)); | |
return crossPoint; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment