Need help with perimeter of polygon

First I need a function that can calculate the perimeter/circumference of a polygon by any given x,y coordinates.
Then I need to make a script that uses that function and loads coordinates from txt file and again calculates the perimeter.
How do i set this up?

4 commentaires

John D'Errico
John D'Errico le 25 Sep 2020
So what have you tried? If nothing, then you need to learn MATLAB. Start with the OnRamp tutorial.
Start by learning how to read a file. There are god knows how many ways to load in information from a file. It depends on the file what you might do, but many things can and will work. Why not read the help for tools like load, textread? But many other tools will do the job too.
Once you understand how to read in your data, then you need to work with it. How is the polygon defined? Are these just random points, and no order is given? If so, then you need to figure out the order. Is the polygon convex? Then a convex hull will be simplest. If the polygon can be some completely general one, and you don'y have a clue about the order of a scattered set of points, then you probably need to learn a tool like the CRUST algorithm. You can find one from the file exchange as I recall.
If the points are already stored in a specific sequence to define the polygon, then it is simple. You compute the distance between each paitr of points, then add up the lengths of each line segment. Again, this is simple, at least unless you have not a clue. And then you need to learn MATLAB.
It sounds like you need to start by learning MATLAB. We cannot teach you an entire course here from the basics though, and much of that is already written.
Rik
Rik le 25 Sep 2020
Why did you edit away your question? That is very rude.
Rena Berman
Rena Berman le 8 Oct 2020
(Answers Dev) Restored edit
Rik
Rik le 8 Oct 2021
Copy of the question in case you decide to edit it away for the third time:
Need help with perimeter of polygon
First I need a function that can calculate the perimeter/circumference of a polygon by any given x,y coordinates.
Then I need to make a script that uses that function and loads coordinates from txt file and again calculates the perimeter.
How do i set this up?

Connectez-vous pour commenter.

Réponses (2)

Rik
Rik le 25 Sep 2020

0 votes

Step by step. Split up your problems in manageable parts.
If you have the coordinates of all corners of your polygon, you can use the Pythagorean theorem to calculate the distance from point to point and sum the results to get the perimeter length.
You script only needs to parse the text file to a list of coordinates. You can then call the function you created.
Which specific step is causing you trouble?
If this isn't homework and you're using R2017b or later you can also use polyshape and perimeter.
Bjorn Gustavsson
Bjorn Gustavsson le 25 Sep 2020

0 votes

Have a look at the help and documentation of the convhull function.
HTH

Catégories

Commenté :

Rik
le 8 Oct 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by