Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jigyasa Watwani
/
growth-pattern-control
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
07690244
authored
Jan 08, 2024
by
Jigyasa Watwani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug in perimeter calculation
parent
a4b8cfc4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
25 deletions
convergence_extension/perimeter_long_axis.py
convergence_extension/perimeter_long_axis.py
View file @
07690244
...
...
@@ -2,27 +2,13 @@ import numpy as np
import
matplotlib.pyplot
as
plt
import
pandas
as
pd
from
matplotlib.widgets
import
Slider
from
scipy.spatial
import
ConvexHull
def
perimeter
(
X
,
Y
,
n
):
# Initialize perimeter
perimeter
=
0
# Calculate distance between each pair of consecutive points
for
j
in
range
(
n
):
# Get current point
x1
,
y1
=
X
[
j
],
Y
[
j
]
# Get next point (if i is the last index, get the first point)
if
j
==
n
-
1
:
x2
,
y2
=
X
[
0
],
Y
[
0
]
else
:
x2
,
y2
=
X
[
j
+
1
],
Y
[
j
+
1
]
# Calculate distance between points and add to perimeter
perimeter
+=
np
.
sqrt
((
x2
-
x1
)
**
2
+
(
y2
-
y1
)
**
2
)
return
perimeter
def
perimeter
(
X
,
Y
):
points
=
np
.
column_stack
((
X
,
Y
))
hull
=
ConvexHull
(
points
)
value
=
sum
(
np
.
linalg
.
norm
(
points
[
hull
.
vertices
[
i
]]
-
points
[
hull
.
vertices
[(
i
+
1
)
%
len
(
hull
.
vertices
)]])
for
i
in
range
(
len
(
hull
.
vertices
)))
return
value
def
long_axis
(
x
,
y
):
x_diff
=
x
[:,
None
]
-
x
...
...
@@ -31,13 +17,16 @@ def long_axis(x, y):
return
np
.
max
(
distances
)
# NOTE: check perimeter and long_axis functions on known shapes
# x = np.array([0, 1, 0, -1])
# y = np.array([2, 0, -2, 0])
# print(x, y)
# x = np.array([1, 0, -1, 0])
# y = np.array([0, 2, 0, -2])
# print(long_axis(x, y))
# points = np.column_stack((x, y))
# hull = ConvexHull(points)
# print(long_axis(x, y))
# raise SystemExit
file
=
np
.
loadtxt
(
'xy_coordinates_movie1.txt'
)
file
=
np
.
loadtxt
(
'xy_coordinates_movie1
5
.txt'
)
number_of_pixels
=
file
.
shape
[
0
]
time_points
=
file
.
shape
[
1
]
time_array
=
np
.
arange
(
0
,
5
*
int
(
time_points
/
2
),
5
)
...
...
@@ -95,7 +84,7 @@ plt.show()
perimeter_array
=
np
.
zeros
(
int
(
time_points
/
2
))
for
k
in
range
(
0
,
int
(
time_points
/
2
)):
perimeter_array
[
k
]
=
perimeter
(
x
[
k
],
y
[
k
]
,
number_of_pixels
)
perimeter_array
[
k
]
=
perimeter
(
x
[
k
],
y
[
k
])
plt
.
plot
(
time_array
,
perimeter_array
,
marker
=
'o'
,
linestyle
=
'None'
)
plt
.
xlabel
(
'Time'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment