Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
se2aa4_cs2me3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
W. Spencer Smith
se2aa4_cs2me3
Commits
6b153aca
Commit
6b153aca
authored
7 years ago
by
Sepehr Bayat
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
8cf00d93
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tutorials/T04-A2Example/src/TriangleADT.py
+59
-0
59 additions, 0 deletions
Tutorials/T04-A2Example/src/TriangleADT.py
with
59 additions
and
0 deletions
Tutorials/T04-A2Example/src/TriangleADT.py
0 → 100644
+
59
−
0
View file @
6b153aca
## @file TriangleADT.py
# @author Sepehr
# @brief Provides the Triangle CLass for Perimeter Area and existence of triangle
# @date 25 Jan 2018
from
pointT
import
*
##@brief An ADT that respresents a 2D point
class
Triangle
:
## @brief Triangle constructor
# @details Initializes a Triangle with three points a,b,c
# @param a One side of triangle
# @param b One side of triangle
# @param c One side of triangle
def
__init__
(
self
,
p1
,
p2
,
p3
):
self
.
__a
=
p1
self
.
__b
=
p2
self
.
__c
=
p3
self
.
sides
()
## @brief Gets the sides
# @return The sides of the triangle
def
sides
(
self
):
self
.
AB
=
pointT
.
dist
(
self
.
__b
,
self
.
__b
)
self
.
AC
=
pointT
.
dist
(
self
.
__a
,
self
.
__c
)
self
.
BC
=
pointT
.
dist
(
self
.
__b
,
self
.
__c
)
## @brief Inequality theorem
# @return the existence of a triangle
def
inequality_theorem
(
self
):
self
.
sides
()
if
(
self
.
AB
+
self
.
AC
>
self
.
BC
and
self
.
AB
+
self
.
BC
>
self
.
AC
and
self
.
AC
+
self
.
BC
>
self
.
AB
):
return
True
;
elif
(
self
.
__a
.
xcoord
()
==
self
.
__b
.
xcoord
()
==
self
.
__c
.
xcoord
()
or
self
.
__a
.
ycoord
()
==
self
.
__b
.
ycoord
()
==
self
.
__c
.
ycoord
()):
return
False
;
else
:
return
False
;
## @brief perimeter
# @return the perimeter of the triangle
def
perimeter_of_triangle
(
self
):
if
self
.
inequality_theorem
():
return
self
.
AB
+
self
.
AC
+
self
.
BC
else
:
print
(
"
You can
'
t have a triangle with the points
"
)
## @brief area
# @return the area of the triangle
def
area_of_triangle
(
self
):
if
self
.
inequality_theorem
():
P
=
(
self
.
AB
+
self
.
AC
+
self
.
BC
)
/
2
return
sqrt
(
P
*
(
P
-
self
.
AB
)
*
(
P
-
self
.
AC
)
*
(
P
-
self
.
BC
))
else
:
print
(
"
You can
'
t have a triangle with the points
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment