Longitud de la diagonal de un paralelogramo usando los lados adyacentes y el ángulo entre ellos

Dados dos enteros a y b donde a y b representan la longitud de los lados adyacentes de un paralelogramo y un ángulo 0 entre ellos, la tarea es encontrar la longitud de la diagonal del paralelogramo.

Ejemplos:

Entrada: a = 6, b = 10, 0 =30
Salida: 6,14
 

Entrada: a = 3, b = 5, 0 =45
Salida: 3,58

Enfoque: considere un paralelogramo ABCD con lados a y b , ahora aplique la regla del coseno en el ángulo A en el triángulo ABD para encontrar la longitud de la diagonal p , de manera similar encuentre la diagonal q del triángulo ABC.

Por lo tanto, las diagonales están dadas por:
 

Diagonal (P)=\sqrt{a^2+b^2-2ab.cos(\theta)}
 

C++

// C++ program to find length
// Of diagonal of a parallelogram
// Using sides and angle between them.
#include <bits/stdc++.h>
using namespace std;
#define PI 3.147
 
// Function to return the length
// Of diagonal of a parallelogram
// using sides and angle between them.
double Length_Diagonal(int a, int b, double theta)
{
    double diagonal = sqrt((pow(a, 2) + pow(b, 2)) -
                      2 * a * b * cos(theta * (PI / 180)));
 
    return diagonal;
}
 
// Driver Code
int main()
{
 
    // Given sides
    int a = 3;
    int b = 5;
 
    // Given angle
    double theta = 45;
 
    // Function call
    double ans = Length_Diagonal(a, b, theta);
 
    // Print the final answer
    printf("%.2f", ans);
}
 
// This code is contributed by Amit Katiyar

Java

// Java program to find length
// Of diagonal of a parallelogram
// Using sides and angle between them.
class GFG{
 
// Function to return the length
// Of diagonal of a parallelogram
// using sides and angle between them.
static double Length_Diagonal(int a, int b,
                              double theta)
{
    double diagonal = Math.sqrt((Math.pow(a, 2) +
                                 Math.pow(b, 2)) -
                                 2 * a * b *
                                 Math.cos(theta *
                                 (Math.PI / 180)));
 
    return diagonal;
}
 
// Driver Code
public static void main(String[] args)
{
     
    // Given sides
    int a = 3;
    int b = 5;
 
    // Given angle
    double theta = 45;
 
    // Function call
    double ans = Length_Diagonal(a, b, theta);
 
    // Print the final answer
    System.out.printf("%.2f", ans);
}
}
 
// This code is contributed by amal kumar choubey

Python3

# Python3 Program to find length
# Of diagonal of a parallelogram
# Using sides and angle between them.
 
import math 
   
# Function to return the length
# Of diagonal of a parallelogram
# using sides and angle between them. 
def Length_Diagonal(a, b, theta): 
   
    diagonal = math.sqrt( ((a**2) + (b**2))
    - 2 * a*b * math.cos(math.radians(theta)))
     
    return diagonal 
   
# Driver Code
 
# Given Sides
a = 3
b = 5
 
# Given Angle
theta = 45
   
# Function Call 
ans = Length_Diagonal(a, b, theta) 
   
# Print the final answer
print(round(ans, 2))

C#

// C# program to find length
// Of diagonal of a parallelogram
// Using sides and angle between them.
using System;
 
class GFG{
 
// Function to return the length
// Of diagonal of a parallelogram
// using sides and angle between them.
static double Length_Diagonal(int a, int b,
                              double theta)
{
    double diagonal = Math.Sqrt((Math.Pow(a, 2) +
                                 Math.Pow(b, 2)) -
                                 2 * a * b *
                                 Math.Cos(theta *
                                (Math.PI / 180)));
 
    return diagonal;
}
 
// Driver Code
public static void Main(String[] args)
{
     
    // Given sides
    int a = 3;
    int b = 5;
 
    // Given angle
    double theta = 45;
 
    // Function call
    double ans = Length_Diagonal(a, b, theta);
 
    // Print the readonly answer
    Console.Write("{0:F2}", ans);
}
}
 
// This code is contributed by amal kumar choubey

Javascript

<script>
 
// javascript program to find length
// Of diagonal of a parallelogram
// Using sides and angle between them.
 
// Function to return the length
// Of diagonal of a parallelogram
// using sides and angle between them.
function Length_Diagonal(a , b,theta)
{
    var diagonal = Math.sqrt((Math.pow(a, 2) +
                                 Math.pow(b, 2)) -
                                 2 * a * b *
                                 Math.cos(theta *
                                 (Math.PI / 180)));
 
    return diagonal;
}
 
// Driver Code
 
// Given sides
var a = 3;
var b = 5;
 
// Given angle
var theta = 45;
 
// Function call
var ans = Length_Diagonal(a, b, theta);
 
// Print the final answer
document.write(ans.toFixed(2));
 
// This code is contributed by 29AjayKumar
 
</script>
Producción: 

3.58

 

Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por divyamohan123 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *