34 Replies
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
To calculate not only square, but any polygon area, the function is:
It works only if you assign adjacent points coordinates into the array one after the other consistently. Do not mix points coordinates chaotically.
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
You're welcome
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
instead of 0 and 2?
or why 0 and 2?
f because type is float
www.javatpoint.com
Java Float Keyword - Javatpoint
Java Float Keyword with java keywords, java tutorial, features, history, variables, object, class, programs, operators, oops concept, inheritance, array, string, methods, examples etc.
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
just an example
you can write any numbers you like
but be sure that in the end it will be polygon
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
yes
area will be 1
if 4 points
square
but you can use any polygon coordinates.
for example from this picture:

float[][] coord = {{2f, 3f}, {4f, -4f}, {-3f, -2f}, {-4f, 4f}};
in this example the area will be -40.0
minus
but this could be fixed by:
if (area < 0) area = -area;
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
@YavuzSultanEnes An example from website:
https://www.mathopenref.com/coordpolygonarea.html
float[][] coord = {{4f, 10f}, {9f, 7f}, {11f, 2f}, {2f, 2f}};
area will be 45.5
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
yes
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
from our example about square yes
x would be rows
y columns
Here is another example:

float[][] coord = {{3f, 3f}, {4f, 2f}, {3f, 1f}, {2f, -1f}, {1f, 1f}, {-1f, 2f}};
area will be 8.0
On the Internet there is another solution similar, but a bit fifferent:
GeeksforGeeks
Area of a polygon with given n ordered vertices - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
with two arrays
but not bidimensional array
when we say point 2 out of 4
coord 2
it's index is 1
because if you have 4 length array, it's indexes are 0, 1, 2, 3
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
1st is 0, 2nd - 1, 3rd - 2, 4th - 3
3 is Fourth point
4th vertex
or point
@YavuzSultanEnes

coord[n][0] - X coordinate, coord[n][1] - Y coordinate
0 0
2 0
2 2
0 2
square matrix
float[][] coord = {{0f, 0f}, {2f, 0f}, {2f, 2f}, {0f, 2f}};
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
A square as a polygon has 4 vertices. Each vertex has two coordinates - X coordinate and Y coordinate.
Unknown UserOP•3y ago
Message Not Public
Sign In & Join Server To View
Post Closed
This post has been closed by <@257204197013979138>.