# Given a mesh, a point on the mesh, a direction and a distance, compute the face+barycentric coordinates of point at that geodesic distance

I am a beginner at graphics. I am given a triangular mesh (assume a manifold mesh). I want to sample a square on a mesh that is independent of the triangulation.

I am following these steps

• Sample a triangle (based on the areas of the triangles)
• Sample a point uniformly on the triangle
• Sample a random direction

Now all corners of the square can be computed using that point as the origin (and the direction as the x-axis) on a 2D plane trivially. I want to get (Face, barycentric coordinates) of corners of the square on the mesh efficiently (preferably in C++/python) since I'll need to sample a random square again and again. I am looking at libraries such as Polyscope or pygeodesic that use the heat method to compute the geodesic distance between vertices of the mesh, but I am not sure how to get points at an arbitrary geodesic distance from another point.
{"ft_lang_label":"__label__en","ft_lang_prob":0.9402345,"math_prob":0.977495,"size":870,"snap":"2023-40-2023-50","text_gpt3_token_len":200,"char_repetition_ratio":0.13510393,"word_repetition_ratio":0.0,"special_character_ratio":0.21149425,"punctuation_ratio":0.048484847,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99386734,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-02T16:25:49Z\",\"WARC-Record-ID\":\"<urn:uuid:29c93351-2b2f-42a8-b4c8-b94d913bc3ef>\",\"Content-Length\":\"150465\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:db075ffa-083b-4024-aeac-d84915c7a157>\",\"WARC-Concurrent-To\":\"<urn:uuid:7c9a4be6-e7d2-4fef-9a89-70f9da8d4d73>\",\"WARC-IP-Address\":\"104.18.43.226\",\"WARC-Target-URI\":\"https://computergraphics.stackexchange.com/questions/12485/given-a-mesh-a-point-on-the-mesh-a-direction-and-a-distance-compute-the-face\",\"WARC-Payload-Digest\":\"sha1:TWORSTIOV3XBLAHBTSQUPKP2YINKCI5Z\",\"WARC-Block-Digest\":\"sha1:A4LALZEEQVRREQL72LPQKZSG3A2YB4AK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100427.59_warc_CC-MAIN-20231202140407-20231202170407-00426.warc.gz\"}"}