Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

I am trying to integrate a function over a planar polygon in 3D. In 2D, this is fairly straightforward, using either answer from this questionthis question (I use the second answer). If we use an equilateral triangle centered at the origin as our polygon:

f[pos_List] := 1 basetri={{1/2,- (1/6) Sqrt[3],0},{0,1/3 Sqrt[3],0},{-(1/2),- (1/6) Sqrt[3],0}} inPolyQ[poly_,pt_]:=2.π==Total[VectorAngle@@@Transpose@{#,RotateRight[#]}]&@(#-pt&/@poly) 

we can integrate our function f (in this case, this function will return the area of the triangle):

NIntegrate[ f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,Min@basetri[[;;,1]],Max@basetri[[;;,1]]}, {y,Min@basetri[[;;,2]],Max@basetri[[;;,2]]} ] (* Out[]:= 0.43265 *) 

which is pretty close to the exact value of Sqrt[3]/4 (~0.433013). (Yes, the are a bunch of errors thrown.) This can also be done over infinite bounds (see this answerthis answer):

NIntegrate[f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,-Infinity,Infinity},{y,-Infinity,Infinity} ] (* Out[]:= 0.433321 *) 

which is also pretty close to the exact value. (I'll leave alone for now the question of which bounds should give better results...)

The problem arises when doing this in 3D:

NIntegrate[ f[{x,y,z}] Boole[inPolyQ[basetri, {x, y, z}]], {x, -Infinity,Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity} ] (* Out[]:= 0 *) 

It gives this error:

NIntegrate::izero: Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option.

Increasing MinRecursion doesn't help. I suspect that because this is a planar polygon, it has trouble figuring out exactly where that infinitesimally-thin plane is that satisfies the inequality actually is.

So, how can I integrate a function over an arbitrarily-oriented planar polygon in 3D? For what it's worth, at the very least it would be an acceptable answer for my current problem if it just works with a triangular region (in 3D), but I figured I'd leave the question more general if there's a way to do it.

I am trying to integrate a function over a planar polygon in 3D. In 2D, this is fairly straightforward, using either answer from this question (I use the second answer). If we use an equilateral triangle centered at the origin as our polygon:

f[pos_List] := 1 basetri={{1/2,- (1/6) Sqrt[3],0},{0,1/3 Sqrt[3],0},{-(1/2),- (1/6) Sqrt[3],0}} inPolyQ[poly_,pt_]:=2.π==Total[VectorAngle@@@Transpose@{#,RotateRight[#]}]&@(#-pt&/@poly) 

we can integrate our function f (in this case, this function will return the area of the triangle):

NIntegrate[ f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,Min@basetri[[;;,1]],Max@basetri[[;;,1]]}, {y,Min@basetri[[;;,2]],Max@basetri[[;;,2]]} ] (* Out[]:= 0.43265 *) 

which is pretty close to the exact value of Sqrt[3]/4 (~0.433013). (Yes, the are a bunch of errors thrown.) This can also be done over infinite bounds (see this answer):

NIntegrate[f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,-Infinity,Infinity},{y,-Infinity,Infinity} ] (* Out[]:= 0.433321 *) 

which is also pretty close to the exact value. (I'll leave alone for now the question of which bounds should give better results...)

The problem arises when doing this in 3D:

NIntegrate[ f[{x,y,z}] Boole[inPolyQ[basetri, {x, y, z}]], {x, -Infinity,Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity} ] (* Out[]:= 0 *) 

It gives this error:

NIntegrate::izero: Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option.

Increasing MinRecursion doesn't help. I suspect that because this is a planar polygon, it has trouble figuring out exactly where that infinitesimally-thin plane is that satisfies the inequality actually is.

So, how can I integrate a function over an arbitrarily-oriented planar polygon in 3D? For what it's worth, at the very least it would be an acceptable answer for my current problem if it just works with a triangular region (in 3D), but I figured I'd leave the question more general if there's a way to do it.

I am trying to integrate a function over a planar polygon in 3D. In 2D, this is fairly straightforward, using either answer from this question (I use the second answer). If we use an equilateral triangle centered at the origin as our polygon:

f[pos_List] := 1 basetri={{1/2,- (1/6) Sqrt[3],0},{0,1/3 Sqrt[3],0},{-(1/2),- (1/6) Sqrt[3],0}} inPolyQ[poly_,pt_]:=2.π==Total[VectorAngle@@@Transpose@{#,RotateRight[#]}]&@(#-pt&/@poly) 

we can integrate our function f (in this case, this function will return the area of the triangle):

NIntegrate[ f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,Min@basetri[[;;,1]],Max@basetri[[;;,1]]}, {y,Min@basetri[[;;,2]],Max@basetri[[;;,2]]} ] (* Out[]:= 0.43265 *) 

which is pretty close to the exact value of Sqrt[3]/4 (~0.433013). (Yes, the are a bunch of errors thrown.) This can also be done over infinite bounds (see this answer):

NIntegrate[f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,-Infinity,Infinity},{y,-Infinity,Infinity} ] (* Out[]:= 0.433321 *) 

which is also pretty close to the exact value. (I'll leave alone for now the question of which bounds should give better results...)

The problem arises when doing this in 3D:

NIntegrate[ f[{x,y,z}] Boole[inPolyQ[basetri, {x, y, z}]], {x, -Infinity,Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity} ] (* Out[]:= 0 *) 

It gives this error:

NIntegrate::izero: Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option.

Increasing MinRecursion doesn't help. I suspect that because this is a planar polygon, it has trouble figuring out exactly where that infinitesimally-thin plane is that satisfies the inequality actually is.

So, how can I integrate a function over an arbitrarily-oriented planar polygon in 3D? For what it's worth, at the very least it would be an acceptable answer for my current problem if it just works with a triangular region (in 3D), but I figured I'd leave the question more general if there's a way to do it.

Tweeted twitter.com/#!/StackMma/status/348306732767916032
added a function
Source Link
Eli Lansey
  • 7.6k
  • 3
  • 39
  • 73

I am trying to integrate a function over a planar polygon in 3D. In 2D, this is fairly straightforward, using either answer from this question (I use the second answer). If we use an equilateral triangle centered at the origin as our polygon:

f[pos_List] := 1 basetri={{1/2,- (1/6) Sqrt[3],0},{0,1/3 Sqrt[3],0},{-(1/2),- (1/6) Sqrt[3],0}} inPolyQ[poly_,pt_]:=2.π==Total[VectorAngle@@@Transpose@{#,RotateRight[#]}]&@(#-pt&/@poly) 

we can integrate our function f (in this case, this function will return the area of the triangle):

NIntegrate[  f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,Min@basetri[[;;,1]],Max@basetri[[;;,1]]}, {y,Min@basetri[[;;,2]],Max@basetri[[;;,2]]} ] (* Out[]:= 0.43265 *) 

which is pretty close to the exact value of Sqrt[3]/4 (~0.433013). (Yes, the are a bunch of errors thrown.) This can also be done over infinite bounds (see this answer):

NIntegrate[Boole[inPolyQ[basetriNIntegrate[f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,-Infinity,Infinity},{y,-Infinity,Infinity}  ] (* Out[]:= 0.433321 *) 

which is also pretty close to the exact value. (I'll leave alone for now the question of which bounds should give better results...)

The problem arises when doing this in 3D:

NIntegrate[  f[{x,y,z}] Boole[inPolyQ[basetri, {x, y, z}]], {x, -Infinity,Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity} ] (* Out[]:= 0 *) 

It gives this error:

NIntegrate::izero: Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option.

Increasing MinRecursion doesn't help. I suspect that because this is a planar polygon, it has trouble figuring out exactly where that infinitesimally-thin plane is that satisfies the inequality actually is.

So, how can I integrate a function over an arbitrarily-oriented planar polygon in 3D? For what it's worth, at the very least it would be an acceptable answer for my current problem if it just works with a triangular region (in 3D), but I figured I'd leave the question more general if there's a way to do it.

I am trying to integrate a function over a planar polygon in 3D. In 2D, this is fairly straightforward, using either answer from this question (I use the second answer). If we use an equilateral triangle centered at the origin as our polygon:

basetri={{1/2,- (1/6) Sqrt[3],0},{0,1/3 Sqrt[3],0},{-(1/2),- (1/6) Sqrt[3],0}} inPolyQ[poly_,pt_]:=2.π==Total[VectorAngle@@@Transpose@{#,RotateRight[#]}]&@(#-pt&/@poly) 

we can integrate:

NIntegrate[ Boole[inPolyQ[basetri,{x,y,0}]], {x,Min@basetri[[;;,1]],Max@basetri[[;;,1]]}, {y,Min@basetri[[;;,2]],Max@basetri[[;;,2]]} ] (* Out[]:= 0.43265 *) 

which is pretty close to the exact value of Sqrt[3]/4 (~0.433013). (Yes, the are a bunch of errors thrown.) This can also be done over infinite bounds (see this answer):

NIntegrate[Boole[inPolyQ[basetri,{x,y,0}]],{x,-Infinity,Infinity},{y,-Infinity,Infinity}] (* Out[]:= 0.433321 *) 

which is also pretty close to the exact value. (I'll leave alone for now the question of which bounds should give better results...)

The problem arises when doing this in 3D:

NIntegrate[ Boole[inPolyQ[basetri, {x, y, z}]], {x, -Infinity,Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity} ] (* Out[]:= 0 *) 

It gives this error:

NIntegrate::izero: Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option.

Increasing MinRecursion doesn't help. I suspect that because this is a planar polygon, it has trouble figuring out exactly where that infinitesimally-thin plane is that satisfies the inequality actually is.

So, how can I integrate a function over an arbitrarily-oriented planar polygon in 3D? For what it's worth, at the very least it would be an acceptable answer for my current problem if it just works with a triangular region (in 3D), but I figured I'd leave the question more general if there's a way to do it.

I am trying to integrate a function over a planar polygon in 3D. In 2D, this is fairly straightforward, using either answer from this question (I use the second answer). If we use an equilateral triangle centered at the origin as our polygon:

f[pos_List] := 1 basetri={{1/2,- (1/6) Sqrt[3],0},{0,1/3 Sqrt[3],0},{-(1/2),- (1/6) Sqrt[3],0}} inPolyQ[poly_,pt_]:=2.π==Total[VectorAngle@@@Transpose@{#,RotateRight[#]}]&@(#-pt&/@poly) 

we can integrate our function f (in this case, this function will return the area of the triangle):

NIntegrate[  f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,Min@basetri[[;;,1]],Max@basetri[[;;,1]]}, {y,Min@basetri[[;;,2]],Max@basetri[[;;,2]]} ] (* Out[]:= 0.43265 *) 

which is pretty close to the exact value of Sqrt[3]/4 (~0.433013). (Yes, the are a bunch of errors thrown.) This can also be done over infinite bounds (see this answer):

NIntegrate[f[{x,y,0}] Boole[inPolyQ[basetri,{x,y,0}]], {x,-Infinity,Infinity},{y,-Infinity,Infinity}  ] (* Out[]:= 0.433321 *) 

which is also pretty close to the exact value. (I'll leave alone for now the question of which bounds should give better results...)

The problem arises when doing this in 3D:

NIntegrate[  f[{x,y,z}] Boole[inPolyQ[basetri, {x, y, z}]], {x, -Infinity,Infinity}, {y, -Infinity, Infinity}, {z, -Infinity, Infinity} ] (* Out[]:= 0 *) 

It gives this error:

NIntegrate::izero: Integral and error estimates are 0 on all integration subregions. Try increasing the value of the MinRecursion option.

Increasing MinRecursion doesn't help. I suspect that because this is a planar polygon, it has trouble figuring out exactly where that infinitesimally-thin plane is that satisfies the inequality actually is.

So, how can I integrate a function over an arbitrarily-oriented planar polygon in 3D? For what it's worth, at the very least it would be an acceptable answer for my current problem if it just works with a triangular region (in 3D), but I figured I'd leave the question more general if there's a way to do it.

edited tags
Link
Loading
Source Link
Eli Lansey
  • 7.6k
  • 3
  • 39
  • 73
Loading