Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. float[] vertices = triangle.getTransformedVertices();
  2. float distance = Intersector.distanceLinePoint(vertices[2], vertices[3], vertices[4], vertices[5], vertices[0], vertices[1]);
  3.  
  4. Vector2 vertex0 = new Vector2(vertices[0], vertices[1]);
  5. Vector2 vertex1 = new Vector2(vertices[2], vertices[3]);
  6. Vector2 vertex2 = new Vector2(vertices[4], vertices[5]);
  7. Vector2 nearest = new Vector2();
  8. Intersector.nearestSegmentPoint(vertex1, vertex2, vertex0, nearest);
  9.  
  10. Vector3 v = new Vector3(vertex2, 0).sub(vertex0.x, vertex0.y, 0).nor();
  11. v.scl(v.dot(new Vector3(vertex1.sub(vertex0), 0)));
  12. v.sub(new Vector3(vertex1.sub(vertex0), 0).nor());
  13. System.out.println("d:"+distance +", nearest:"+nearest.nor() + ", another d: " + Math.sqrt(Math.pow(nearest.x - vertex0.x, 2)+Math.pow(nearest.y - vertex0.y, 2)));
  14. System.out.println(v);
  15.  
  16.  
  17.  
  18. Console:
  19. d:45.254833, nearest:[0.3846154:0.9230769], another d: 373.55147054776813
  20. 0.40613845,0.9138115,0.0
  21. d:28.62167, nearest:[0.5098024:0.8602915], another d: 372.1809403175402
  22. 0.5547002,0.83205026,0.0
  23. d:22.627417, nearest:[0.98724115:0.15923244], another d: 519.9225805360841
  24. 0.97014254,0.24253564,0.0
  25. d:22.627417, nearest:[0.98257023:0.18589166], another d: 614.5327782895729
  26. 0.98893636,0.14834045,0.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement