MehemmedSettarli's blog

By MehemmedSettarli, history, 2 hours ago, In English

I have given 6 triangle indexes in 2D and I don't know how to calculate the area of this triangle example (1 1, 2 4, 3 2) are equal to 2.5. Can anyone help me, please? I am keen to write it in C++.

»
2 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

A = (1/2) |x1(y2 − y3) + x2(y3 − y1) + x3(y1 − y2)|

A => Area of Triangle

»
115 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

First, we can calculate the length of AB, AC, and BC using:

$$$AB = \sqrt{(B_x - A_x)^2 + (B_y - A_y)^2}$$$,

$$$AC = \sqrt{(C_x - A_x)^2 + (C_y - A_y)^2}$$$,

$$$BC = \sqrt{(C_x - B_x)^2 + (C_y - B_y)^2}$$$

Let's call $$$p = \frac{AB + AC + AD}{2}$$$

Area of triangle will $$$S = \sqrt{p\times(p-AB)\times(p-AC)\times(p-BC)}$$$

»
115 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks a lot also i want to ask that how I can find the point lies on a segment or not?

  • »
    »
    96 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Let's say that you want to check whether the point $$$C$$$ lies on the segment $$$AB$$$. Point will lie on the segment if and only if area of triangle $$$ABC$$$ will be $$$0$$$ and $$$|A_x-C_x|+|C_x-B_x|=|A_x-B_x|$$$.