Thursday, October 9, 2025
HomeData Modelling & AITime required to meet in equilateral triangle

Time required to meet in equilateral triangle

Given length of sides of equilateral triangle (s), and velocities(v) of each animal tagged on the vertices of triangle, find out the time after which they meet, if they start moving towards their right opposite, forming a trajectory.
 

3

Examples: 

Input: s = 2, v = 5
Output: 0.266667

Input: s = 11, v = 556
Output: 0.013189

 

Approach : 
To find the total amount of time taken for the animals to meet, simply take A divided by the initial rate at which two vertices approach each other. Pick any two vertices, and it can be seen that the first point moves in the direction of the second at speed v, while the second moves in the direction of the first (just take the component along one of the triangle edges). 
Reference : StackExchange
 

Below is the implementation of the above approach:

C++




// CPP code to find time
// taken by animals to meet
#include <bits/stdc++.h>
using namespace std;
 
// function to calculate time to meet
void timeToMeet(double s, double v){
 
     double V = 3 * v / 2;
           
     double time = s / V;
      
     cout << time;
}
 
// Driver Code
int main(void) {
     
    double s = 25, v = 56;
     
    timeToMeet(s, v);
     
    return 0;
}


Java




// Java code to find time taken by animals
// to meet
import java.io.*;
 
public class GFG {
 
    // function to calculate time to meet
    static void timeToMeet(double s, double v){
     
        double V = 3 * v / 2;
             
        double time = s / V;
         
        System.out.println((float)time);
    }
     
    // Driver Code
    static public void main (String[] args)
    {
         
        double s = 25, v = 56;
     
        timeToMeet(s, v);
    }
}
 
//This code is contributed by vt_m.


Python3




# Python3 code to find time
# taken by animals to meet
 
# function to calculate
# time to meet
def timeToMeet(s, v):
    V = 3 * v / 2;
     
    time = s / V;
     
    print(time);
 
# Driver Code
s = 25;
v = 56;
     
timeToMeet(s, v);
     
# This code is contributed by mits


C#




// C# code to find time
// taken by animals to meet
using System;
 
public class GFG {
     
    // function to calculate time to meet
    static void timeToMeet(double s, double v){
     
        double V = 3 * v / 2;
             
        double time = s / V;
         
        Console.WriteLine((float)time);
    }
     
    // Driver Code
    static public void Main ()
    {
         
        double s = 25, v = 56;
     
        timeToMeet(s, v);
     
    }
}
 
// This code is contributed by vt_m.


PHP




<?php
// PHP code to find time
// taken by animals to meet
 
// function to calculate
// time to meet
function timeToMeet($s, $v)
{
 
    $V = 3 * $v / 2;
    $time = $s / $V;
    echo $time;
}
 
    // Driver Code
    $s = 25; $v = 56;
    timeToMeet($s, $v);
     
// This code is contributed by anuj_67.
?>


Javascript




<script>
 
// JavaScript code to find time taken by animals
// to meet
 
    // function to calculate time to meet
    function timeToMeet(s , v) {
 
        var V = 3 * v / 2;
 
        var time = s / V;
 
        document.write( time.toFixed(6));
    }
 
    // Driver Code
 
        var s = 25, v = 56;
 
        timeToMeet(s, v);
 
// This code is contributed by todaysgaurav
 
</script>


Output

0.297619

Time complexity: O(1)
Auxiliary space: O(1)

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32346 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11877 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11940 POSTS0 COMMENTS
Shaida Kate Naidoo
6835 POSTS0 COMMENTS
Ted Musemwa
7094 POSTS0 COMMENTS
Thapelo Manthata
6789 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS