Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use Polygon.contains ? #48

Closed
yangxing844 opened this issue Sep 14, 2023 · 4 comments
Closed

how to use Polygon.contains ? #48

yangxing844 opened this issue Sep 14, 2023 · 4 comments

Comments

@yangxing844
Copy link

I want to use a Polygon to determine if I should add on site energy or not. but when I use Polygon.contains(x,y) like this

def potential(energy, x, y, sub_id):
        if not rhombus(l / 2).contains(x, y):
            print("out of range")
        return energy

I got the following error

TypeError: contains(): incompatible function arguments. The following argument types are supported:
    1. (self: _pybinding.Shape, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]], z: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[bool[m, 1]]

Invoked with: <pybinding.shape.Polygon object at 0x00000121FFBFF7D0>, array([-8.  , -7.5 , -7.  , -6.5 , -6.  , -5.5 , -5.  , -4.5 , -4.  , 
       -3.5 , -3.  , -2.5 , -2.  , -1.5 , -1.  , -0.5 ,  0.  ,  0.5 ,
        1.  ,  1.5 ,  2.  ,  2.5 ,  3.  , -7.75, -7.25, -6.75, -6.25,
       -5.75, -5.25, -4.75, -4.25, -3.75, -3.25, -2.75, -2.25, -1.75,
       -1.25, -0.75, -0.25,  0.25,  0.75,  1.25,  1.75,  2.25,  2.75,
        3.25, -7.5 , -7.  , -6.5 , -6.  , -5.5 , -5.  , -4.5 , -4.  ,
       -3.5 , -3.  , -2.5 , -2.  , -1.5 , -1.  , -0.5 ,  0.  ,  0.5 ,
        1.  ,  1.5 ,  2.  ,  2.5 ,  3.  ,  3.5 , -7.25, -6.75, -6.25,
       -5.75, -5.25, -4.75, -4.25, -3.75, -3.25, -2.75, -2.25, -1.75,
       -1.25, -0.75, -0.25,  0.25,  0.75,  1.25,  1.75,  2.25,  2.75,
        3.25,  3.75, -7.  , -6.5 , -6.  , -5.5 , -5.  , -4.5 , -4.  ,
       -3.5 , -3.  , -2.5 , -2.  , -1.5 , -1.  , -0.5 ,  0.  ,  0.5 ,
        1.  ,  1.5 ,  2.  ,  2.5 ,  3.  ,  3.5 ,  4.  , -6.75, -6.25,
       -5.75, -5.25, -4.75, -4.25, -3.75, -3.25, -2.75, -2.25, -1.75,
       -1.25, -0.75, -0.25,  0.25,  0.75,  1.25,  1.75,  2.25,  2.75,
        3.25,  3.75,  4.25, -6.5 , -6.  , -5.5 , -5.  , -4.5 , -4.  ,
       -3.5 , -3.  , -2.5 , -2.  , -1.5 , -1.  , -0.5 ,  0.  ,  0.5 ,
        1.  ,  1.5 ,  2.  ,  2.5 ,  3.  ,  3.5 ,  4.  ,  4.5 , -6.25,
       -5.75, -5.25, -4.75, -4.25, -3.75, -3.25, -2.75, -2.25, -1.75,
       -1.25, -0.75, -0.25,  0.25,  0.75,  1.25,  1.75,  2.25,  2.75,
        3.25,  3.75,  4.25,  4.75, -6.  , -5.5 , -5.  , -4.5 , -4.  ,
       -3.5 , -3.  , -2.5 , -2.  , -1.5 , -1.  , -0.5 ,  0.  ,  0.5 ,
        1.  ,  1.5 ,  2.  ,  2.5 ,  3.  ,  3.5 ,  4.  ,  4.5 ,  5.  ,
       -5.75, -5.25, -4.75, -4.25, -3.75, -3.25, -2.75, -2.25, -1.75,
       -1.25, -0.75, -0.25,  0.25,  0.75,  1.25,  1.75,  2.25,  2.75,
        3.25,  3.75,  4.25,  4.75,  5.25, -5.5 , -5.  , -4.5 , -4.  ,
       -3.5 , -3.  , -2.5 , -2.  , -1.5 , -1.  , -0.5 ,  0.  ,  0.5 ,
        1.  ,  1.5 ,  2.  ,  2.5 ,  3.  ,  3.5 ,  4.  ,  4.5 ,  5.  ,
        5.5 , -5.25, -4.75, -4.25, -3.75, -3.25, -2.75, -2.25, -1.75,
       -1.25, -0.75, -0.25,  0.25,  0.75,  1.25,  1.75,  2.25,  2.75,
        3.25,  3.75,  4.25,  4.75,  5.25,  5.75, -5.  , -4.5 , -4.  ,
       -3.5 , -3.  , -2.5 , -2.  , -1.5 , -1.  , -0.5 ,  0.  ,  0.5 ,
        1.  ,  1.5 ,  2.  ,  2.5 ,  3.  ,  3.5 ,  4.  ,  4.5 ,  5.  ,
        5.5 ,  6.  , -4.75, -4.25, -3.75, -3.25, -2.75, -2.25, -1.75,
       -1.25, -0.75, -0.25,  0.25,  0.75,  1.25,  1.75,  2.25,  2.75,
        3.25,  3.75,  4.25,  4.75,  5.25,  5.75,  6.25, -4.5 , -4.  ,
       -3.5 , -3.  , -2.5 , -2.  , -1.5 , -1.  , -0.5 ,  0.  ,  0.5 ,
        1.  ,  1.5 ,  2.  ,  2.5 ,  3.  ,  3.5 ,  4.  ,  4.5 ,  5.  ,
        5.5 ,  6.  ,  6.5 , -4.25, -3.75, -3.25, -2.75, -2.25, -1.75,
       -1.25, -0.75, -0.25,  0.25,  0.75,  1.25,  1.75,  2.25,  2.75,
        3.25,  3.75,  4.25,  4.75,  5.25,  5.75,  6.25,  6.75, -4.  ,
       -3.5 , -3.  , -2.5 , -2.  , -1.5 , -1.  , -0.5 ,  0.  ,  0.5 ,
        1.  ,  1.5 ,  2.  ,  2.5 ,  3.  ,  3.5 ,  4.  ,  4.5 ,  5.  ,
        5.5 ,  6.  ,  6.5 ,  7.  , -3.75, -3.25, -2.75, -2.25, -1.75,
       -1.25, -0.75, -0.25,  0.25,  0.75,  1.25,  1.75,  2.25,  2.75,
        3.25,  3.75,  4.25,  4.75,  5.25,  5.75,  6.25,  6.75,  7.25,
       -3.5 , -3.  , -2.5 , -2.  , -1.5 , -1.  , -0.5 ,  0.  ,  0.5 ,
        1.  ,  1.5 ,  2.  ,  2.5 ,  3.  ,  3.5 ,  4.  ,  4.5 ,  5.  ,
        5.5 ,  6.  ,  6.5 ,  7.  ,  7.5 , -3.25, -2.75, -2.25, -1.75,
       -1.25, -0.75, -0.25,  0.25,  0.75,  1.25,  1.75,  2.25,  2.75,
        3.25,  3.75,  4.25,  4.75,  5.25,  5.75,  6.25,  6.75,  7.25,
        7.75, -3.  , -2.5 , -2.  , -1.5 , -1.  , -0.5 ,  0.  ,  0.5 ,
        1.  ,  1.5 ,  2.  ,  2.5 ,  3.  ,  3.5 ,  4.  ,  4.5 ,  5.  ,
        5.5 ,  6.  ,  6.5 ,  7.  ,  7.5 ,  8.  , -2.75, -2.25, -1.75,
       -1.25, -0.75, -0.25,  0.25,  0.75,  1.25,  1.75,  2.25,  2.75,
        3.25,  3.75,  4.25,  4.75,  5.25,  5.75,  6.25,  6.75,  7.25,
        7.75]), array([-4.47446459, -4.47446459, -4.47446459, -4.47446459, -4.47446459,
       -4.47446459, -4.47446459, -4.47446459, -4.47446459, -4.47446459,
       -4.47446459, -4.47446459, -4.47446459, -4.47446459, -4.47446459,
       -4.47446459, -4.47446459, -4.47446459, -4.47446459, -4.47446459,
       -4.47446459, -4.47446459, -4.47446459, -4.04145188, -4.04145188,
       -4.04145188, -4.04145188, -4.04145188, -4.04145188, -4.04145188,
       -4.04145188, -4.04145188, -4.04145188, -4.04145188, -4.04145188,
       -4.04145188, -4.04145188, -4.04145188, -4.04145188, -4.04145188,
       -4.04145188, -4.04145188, -4.04145188, -4.04145188, -4.04145188,
       -4.04145188, -3.60843918, -3.60843918, -3.60843918, -3.60843918,
       -3.60843918, -3.60843918, -3.60843918, -3.60843918, -3.60843918,
       -3.60843918, -3.60843918, -3.60843918, -3.60843918, -3.60843918,
       -3.60843918, -3.60843918, -3.60843918, -3.60843918, -3.60843918,
       -3.60843918, -3.60843918, -3.60843918, -3.60843918, -3.17542648,
       -3.17542648, -3.17542648, -3.17542648, -3.17542648, -3.17542648,
       -3.17542648, -3.17542648, -3.17542648, -3.17542648, -3.17542648,
       -3.17542648, -3.17542648, -3.17542648, -3.17542648, -3.17542648,
       -3.17542648, -3.17542648, -3.17542648, -3.17542648, -3.17542648,
       -3.17542648, -3.17542648, -2.74241378, -2.74241378, -2.74241378,
       -2.74241378, -2.74241378, -2.74241378, -2.74241378, -2.74241378,
       -2.74241378, -2.74241378, -2.74241378, -2.74241378, -2.74241378,
       -2.74241378, -2.74241378, -2.74241378, -2.74241378, -2.74241378,
       -2.74241378, -2.74241378, -2.74241378, -2.74241378, -2.74241378,
       -2.30940108, -2.30940108, -2.30940108, -2.30940108, -2.30940108,
       -2.30940108, -2.30940108, -2.30940108, -2.30940108, -2.30940108,
       -2.30940108, -2.30940108, -2.30940108, -2.30940108, -2.30940108,
       -2.30940108, -2.30940108, -2.30940108, -2.30940108, -2.30940108,
       -2.30940108, -2.30940108, -2.30940108, -1.87638837, -1.87638837,
       -1.87638837, -1.87638837, -1.87638837, -1.87638837, -1.87638837,
       -1.87638837, -1.87638837, -1.87638837, -1.87638837, -1.87638837,
       -1.87638837, -1.87638837, -1.87638837, -1.87638837, -1.87638837,
       -1.87638837, -1.87638837, -1.87638837, -1.87638837, -1.87638837,
       -1.87638837, -1.44337567, -1.44337567, -1.44337567, -1.44337567,
       -1.44337567, -1.44337567, -1.44337567, -1.44337567, -1.44337567,
       -1.44337567, -1.44337567, -1.44337567, -1.44337567, -1.44337567,
       -1.44337567, -1.44337567, -1.44337567, -1.44337567, -1.44337567,
       -1.44337567, -1.44337567, -1.44337567, -1.44337567, -1.01036297,
       -1.01036297, -1.01036297, -1.01036297, -1.01036297, -1.01036297,
       -1.01036297, -1.01036297, -1.01036297, -1.01036297, -1.01036297,
       -1.01036297, -1.01036297, -1.01036297, -1.01036297, -1.01036297,
       -1.01036297, -1.01036297, -1.01036297, -1.01036297, -1.01036297,
       -1.01036297, -1.01036297, -0.57735027, -0.57735027, -0.57735027,
       -0.57735027, -0.57735027, -0.57735027, -0.57735027, -0.57735027,
       -0.57735027, -0.57735027, -0.57735027, -0.57735027, -0.57735027,
       -0.57735027, -0.57735027, -0.57735027, -0.57735027, -0.57735027,
       -0.57735027, -0.57735027, -0.57735027, -0.57735027, -0.57735027,
       -0.14433757, -0.14433757, -0.14433757, -0.14433757, -0.14433757,
       -0.14433757, -0.14433757, -0.14433757, -0.14433757, -0.14433757,
       -0.14433757, -0.14433757, -0.14433757, -0.14433757, -0.14433757,
       -0.14433757, -0.14433757, -0.14433757, -0.14433757, -0.14433757,
       -0.14433757, -0.14433757, -0.14433757,  0.28867513,  0.28867513,
        0.28867513,  0.28867513,  0.28867513,  0.28867513,  0.28867513,
        0.28867513,  0.28867513,  0.28867513,  0.28867513,  0.28867513,
        0.28867513,  0.28867513,  0.28867513,  0.28867513,  0.28867513,
        0.28867513,  0.28867513,  0.28867513,  0.28867513,  0.28867513,
        0.28867513,  0.72168784,  0.72168784,  0.72168784,  0.72168784,
        0.72168784,  0.72168784,  0.72168784,  0.72168784,  0.72168784,
        0.72168784,  0.72168784,  0.72168784,  0.72168784,  0.72168784,
        0.72168784,  0.72168784,  0.72168784,  0.72168784,  0.72168784,
        0.72168784,  0.72168784,  0.72168784,  0.72168784,  1.15470054,
        1.15470054,  1.15470054,  1.15470054,  1.15470054,  1.15470054,
        1.15470054,  1.15470054,  1.15470054,  1.15470054,  1.15470054,
        1.15470054,  1.15470054,  1.15470054,  1.15470054,  1.15470054,
        1.15470054,  1.15470054,  1.15470054,  1.15470054,  1.15470054,
        1.15470054,  1.15470054,  1.58771324,  1.58771324,  1.58771324,
        1.58771324,  1.58771324,  1.58771324,  1.58771324,  1.58771324,
        1.58771324,  1.58771324,  1.58771324,  1.58771324,  1.58771324,
        1.58771324,  1.58771324,  1.58771324,  1.58771324,  1.58771324,
        1.58771324,  1.58771324,  1.58771324,  1.58771324,  1.58771324,
        2.02072594,  2.02072594,  2.02072594,  2.02072594,  2.02072594,
        2.02072594,  2.02072594,  2.02072594,  2.02072594,  2.02072594,
        2.02072594,  2.02072594,  2.02072594,  2.02072594,  2.02072594,
        2.02072594,  2.02072594,  2.02072594,  2.02072594,  2.02072594,
        2.02072594,  2.02072594,  2.02072594,  2.45373864,  2.45373864,
        2.45373864,  2.45373864,  2.45373864,  2.45373864,  2.45373864,
        2.45373864,  2.45373864,  2.45373864,  2.45373864,  2.45373864,
        2.45373864,  2.45373864,  2.45373864,  2.45373864,  2.45373864,
        2.45373864,  2.45373864,  2.45373864,  2.45373864,  2.45373864,
        2.45373864,  2.88675135,  2.88675135,  2.88675135,  2.88675135,
        2.88675135,  2.88675135,  2.88675135,  2.88675135,  2.88675135,
        2.88675135,  2.88675135,  2.88675135,  2.88675135,  2.88675135,
        2.88675135,  2.88675135,  2.88675135,  2.88675135,  2.88675135,
        2.88675135,  2.88675135,  2.88675135,  2.88675135,  3.31976405,
        3.31976405,  3.31976405,  3.31976405,  3.31976405,  3.31976405,
        3.31976405,  3.31976405,  3.31976405,  3.31976405,  3.31976405,
        3.31976405,  3.31976405,  3.31976405,  3.31976405,  3.31976405,
        3.31976405,  3.31976405,  3.31976405,  3.31976405,  3.31976405,
        3.31976405,  3.31976405,  3.75277675,  3.75277675,  3.75277675,
        3.75277675,  3.75277675,  3.75277675,  3.75277675,  3.75277675,
        3.75277675,  3.75277675,  3.75277675,  3.75277675,  3.75277675,
        3.75277675,  3.75277675,  3.75277675,  3.75277675,  3.75277675,
        3.75277675,  3.75277675,  3.75277675,  3.75277675,  3.75277675,
        4.18578945,  4.18578945,  4.18578945,  4.18578945,  4.18578945,
        4.18578945,  4.18578945,  4.18578945,  4.18578945,  4.18578945,
        4.18578945,  4.18578945,  4.18578945,  4.18578945,  4.18578945,
        4.18578945,  4.18578945,  4.18578945,  4.18578945,  4.18578945,
        4.18578945,  4.18578945,  4.18578945,  4.61880215,  4.61880215,
        4.61880215,  4.61880215,  4.61880215,  4.61880215,  4.61880215,
        4.61880215,  4.61880215,  4.61880215,  4.61880215,  4.61880215,
        4.61880215,  4.61880215,  4.61880215,  4.61880215,  4.61880215,
        4.61880215,  4.61880215,  4.61880215,  4.61880215,  4.61880215])```
I believe those numbers are the x,y arrays, what am I doing wrong?
@yangxing844
Copy link
Author

it seems that you need z argument to make it work even though I don't make use of z since this is 2d

@BertJorissen
Copy link
Collaborator

Hi Yang,
In Python, you can set the specific variable of a function by function(var1=1.). If you leave out a variable in a function that has a default variable in the definition (for example def function(var1, var2=0.) and only calling function(var1=1) it will automatically set var2=0..
On the API for the shape.contains I can see that there isn't a default value for the z-component. I'll maybe add this as zero in a next release. So, for now, just add something in the z-component.
Best
Bert

@yangxing844
Copy link
Author

Hi Yang, In Python, you can set the specific variable of a function by function(var1=1.). If you leave out a variable in a function that has a default variable in the definition (for example def function(var1, var2=0.) and only calling function(var1=1) it will automatically set var2=0.. On the API for the shape.contains I can see that there isn't a default value for the z-component. I'll maybe add this as zero in a next release. So, for now, just add something in the z-component. Best Bert

but we don't know how long the zero array should be, so we really can not set a default value for this kind of parameter? maybe address it in the API documentation is nice

@BertJorissen
Copy link
Collaborator

just put z=y*0 ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants