GithubHelp home page GithubHelp logo

parisaarbab / overlapping-ellipses Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.38 MB

This code estimates the area where two ellipses overlap by simulating random points within a specific area and checking how many of these points fall inside both ellipses. It leverages classes to represent points and ellipses in 2D space and uses a pseudo-random number generator for the simulation.

Python 100.00%
classes-and-objects geometry monto-carlo pseudo-random-generator monto-carlo-simulation

overlapping-ellipses's Introduction

Overlapping-Ellipses

This code estimates the area where two ellipses overlap by simulating random points within a specific area and checking how many of these points fall inside both ellipses. It leverages classes to represent points and ellipses in 2D space and uses a pseudo-random number generator for the simulation. Calculating Min, Max, and Mean Min and Max: These are the smallest and largest numbers generated in the 10,000 numbers. Mean: This is the average of all 10,000 numbers, calculated by adding them all up and dividing by 10,000.

init (within Point and Ellipse classes): These are constructor methods used to initialize new instances of the Point and Ellipse classes. For a Point, it stores x and y coordinates. For an Ellipse, it stores two focal points (f1, f2) and the width of the long axis, and calculates its area upon initialization.

compute_area (within Ellipse class): This method calculates the area of an ellipse. If the ellipse is actually a circle (both foci at the same point), it calculates the area using the formula for a circle's area. If it's an ellipse, it approximates the area using the major axis (width) and the distance between the foci to find the minor axis, then applies the standard area formula for ellipses.

is_inside_ellipse: This function determines whether a given point is inside a specific ellipse. It calculates the sum of the distances from the point to each of the ellipse's foci. If this sum is less than or equal to the ellipse's width (the major axis length), the point is considered inside the ellipse.

computeOverlapOfEllipses: This function estimates the overlap area between two ellipses using the Monte Carlo method. It randomly generates points within a predefined bounding box and counts how many of these points fall inside both ellipses. The ratio of points inside both ellipses to the total number of points generated, multiplied by the area of the bounding box, gives an estimate of the overlap area.

overlapping-ellipses's People

Contributors

parisaarbab avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.