samedi 22 décembre 2018

How can I evaluate the intersection's volume of a circle and the area above a line. I also would like to apply it. - Python

This is using Python.

I tried to post an image, but failed... So it may be difficult to understand.

I call the intersection of a part inside a circle (of which center is (0, 0) and the radius is 1) and a part above a line (y = x).I call it yellow part.

I would like to evaluate the area of the yellow part with random numbers and without for statement or while statement, but I don't know how to do it.

Plus, I also apply it to 3-D.That is, the intersection of a part inside an ellipse (2x^2+3y^2+z^2-4=0) and a part above plane(x+y+2z-1=0). But this is an additional question. It would be easy to do it if I can do it in 2-D.

I'd like to calculate some of volumes in my experiment. I have tried some of my codes, but they don't work. I appreciate it if you would answer my question.

What I coded↓

import numpy as np
size = 10000

if y - x > 0:
    x = np.random.uniform(-1, 1, size)
    y = np.random.uniform(-1, 1, size)
area = x**2 + y**2
print(len(area[area < 1])/size)

The area of the yellow part would be expected from this code.




Aucun commentaire:

Enregistrer un commentaire