I
I
IQI2020-11-30 03:10:53
C++ / C#
IQI, 2020-11-30 03:10:53

How to determine the coordinates of the vertex C of a triangle so that the area of ​​the triangle ABC is minimal?

Hello! I have the following task:
Let the given coordinates of the vertices A = (0,0), B = (a, b) in the triangle ABC, where a and
b are integers entered by the user. Develop a function (method) that
determines the following goals for the coordinates of the vertex C = (x, y) so that the area of ​​the triangle ABC is
minimal (among are not equal to zero). There should be either two functions (methods) in total
(CalcMinOfSquares and CalcTriangleSquareByPoints), or three (when calculating
the area using the Heron formula, also introduce the CalcSideLength function (method), which
converts the coordinates of the ends of the side into its length). The search for the minimum
area is done by enumerating the possible coordinates of the point C.
I used 2 methods (CalcTriangleSquareByPoints and CalcSideLength) but I can't figure out how to complete it
Here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 123
{
    class Program
    {
        static double CalcSideLength(int x1, int y1, int x2, int y2)
        {
            return Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
        }
         static double CalcTriangleSquareByPoints(int x1, int y1, int x2, int y2, int x3, int y3)
        {
            double a = CalcSideLength(x1,y1,x2,y2);
            double b = CalcSideLength(x3,y3,x2,y2);
            double c = CalcSideLength(x1,y1,x3,y3);
            double p = (a + b + c) / 2;
            return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
        }
         static double CalcMinOfSquares(int x1, int y1, int x2, int y2, int x3, int y3) 
         {

         }
         static void Main(string[] args)
        {

        }
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IQI, 2020-12-02
@IQI

How to write it into the program? Cycles? I've been scratching my head for 3 days now

D
Dmitry Gordinskiy, 2020-11-30
@DmitriyGordinskiy

The problem does not say that x and y must be integers.
If you place point C on segment AB, then move it in any of the directions by any non-zero value, you will get a triangle. Decreasing the offset value will reduce the area of ​​the final triangle. In total, when the value of the offset tends to zero, the value of the area will also tend to zero.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question