Skip to main content

A simple package for creating geometric objects and

Project description

README

This project enables the creation of different geometric objects, on which we can perform different operations, like calculation of their perimeter.

Features

  • Create and visualise various geometric objects: Triangle, Rectangle, Polygon, Circle and Ellipse
  • Calculate their perimeter and their area
  • Check if two shapes intersect
  • Save and load geometric shapes from json files

Installation

Download the zip file and insert the Shapes.py function, located in the SimpleShape subfolder, to location of choice or use pip install SimpleShape.

1. Instructions

To start using this project, create the Geometric object using the available classes and perform different methods (see section 1.1). You can also check example.py, located in the SimpleShape subfolder, for a quick overwiev on how to use this package.

This package also provides various simple functions, as described in section 1.2.

1.1 Geometric Classes and Methods

Class Geometry(coordinates):

Parent class for creating geometric objects. Here, coordinates is nx2 tuple or array (n > 3) of 1x2 tupples or arrays that represent coordinates in x-y plane. Note though that this initialization differs for circles and ellipses.

This class has following methods:
  • __init__(self, coordinates): Initialization method for the object.
  • __str__(self): String representation of the objects, obtained using print(object)
  • area(self) -> float: Returns the area of geometric object
  • perimeter(self) -> float: Returns the perimeter of the geometric object
  • to_json(self) -> json: Converts a geometric object to .json format
  • from_json(cls, json_data) -> object: Creates the geometric object from .json format
  • save_shapes(shapes, filename): Save json_data to a file
  • load_shapes(filename): Creates json_data from a file
  • intersect(self, other) -> bool: Check if two objects intersect
  • visualize(self) -> None: Visualize the object using matplotlib module
Class Triangle(coordinates):

A class for creating triangle objects. Here, Coordinates is a 3x2 aray or tupple of arrays or tupples. If the array or tuple is larger, only the initial 3x2 array is taken, while error is returned if array is smaller than that.

Class Rectangle(coordinates):

A class for creating rectangle objects. Here, coordinates is a 4x2 aray or tupple of 1x2 arrays or tupples that should be inserted in clockwise or counter clockwise direction. If the array or tuple is larger, only the initial 4x2 array is taken, while error is returned if array is smaller than that.

Class Polygon(coordinates):

A class for creating (simple) polygon objects. where Coordinates is a nx2 aray or tupple of 1x2 arrays of tuples that should be inserted in fixed order. n has to be equal or larger than 3.

Class Circle(r, center):

A class for creating circle objects. Here, r is radius and center (default value (0,0)) is 1x2 array or tuple that represents center of the circle on x-y plane.

Class Ellipse(a, b, f, center):

A class for creating ellipse objects. Here, a is the major axis, b is the minor axis, f is the rotation in counter-clockwise direction (in degrees, default value 0) and center is 1x2 array or tuple that represents center on x-y plane (default value (0,0)).

1.2 Functions

random_shape(shape): Create a geometric object of random dimensions. If the shape parameter is not specified, a arbitrary shape will be returned. Otherwise, insert one of the following: "Rectangle", "Triangle", "Circle", "Ellipse", "Polygon". intersect(A,B,C,D): Check if two line segments (AB and CD, where each letter represents 1x2 tuple or array of coordinates) intersect parallel(A,B,C,D): Check if two line segments (AB and CD, where each letter represents 1x2 tuple or array of coordinates) are parallel Line_Intersect_Circle(A, B, c, r): Check if line segment AB intersect or touches a circle with radious r and central point c (1x2 array or tuple)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SimpleShape-1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file SimpleShape-1.1-py3-none-any.whl.

File metadata

  • Download URL: SimpleShape-1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for SimpleShape-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 504102e9e9a694185b32e3b1b05572d1ef2299978189156f87383588ce4fe916
MD5 78578d4ab31ff9a15f8a925fae1f6496
BLAKE2b-256 cff2a2636172f3b881c2c2ec6d294e73cd8fa1a64b8728dd0bb2af8dde810229

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page