Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to find the orientation and position of a polygon resting on a curved surface under gravity.The polygon MUST not be penetrated by any part of the surface below. Here is an example for a square shape.enter image description here

The curved surface is defined by a 2D Matrix: Tdata. The problem can be formulated to a constrained Optimization problem. The initial square can be approximated by five points(four vertices and one center point):

ConVer = {{l/2, w/2, 0}, {l/2, -w/2,0}, {-l/2, -w/2, 0}, {-l/2, w/2,0}, {0, 0, 0}};

Where l is the length and w is the width of the Square.

The square's orientation is parameterized by three angles:

Rθ = RotationMatrix[θ, {0, 0, 1}];
Rψ = RotationMatrix[ψ, {0, 1, 0}];
Rϕ = RotationMatrix[ϕ, {1, 0, 0}];

Then the parameterized square is

For[i = 1, i < 6, i++, ConVer[[i]] =Rθ.Rψ.Rϕ.ConVer[[i]] + {x, y,z}];

Where {x ,y ,z} is the coordinates of the center point of the square.

The optimization uses NMinimize function:

x = 1; y = 1; θ = 0;
NMinimize[{z,
             Tdata[(ConVer[[1]])[[1 ;; 2]]] <= (ConVer[[1]])[[3]] &&
             Tdata[(ConVer[[2]])[[1 ;; 2]]] <= (ConVer[[2]])[[3]] &&        
             Tdata[(ConVer[[3]])[[1 ;; 2]]] <= (ConVer[[3]])[[3]] &&
             Tdata[(ConVer[[4]])[[1 ;; 2]]] <= (ConVer[[4]])[[3]] &&
             Tdata[(ConVer[[5]])[[1 ;; 2]]] <= (ConVer[[5]])[[3]]}, 
            {{ψ, -Pi/4, Pi/4}, {ϕ, -Pi/4, Pi/4}, {z, 0, 1}}];

When Tdata is a 2d function this works well, but as to 2d Matrix error occurs! Why is that? I also tried to solve this problem in Matlab using 'fmincon', and Matlab can return desired result.

share|improve this question
    
You need to leave a blank line before code snippets, otherwise they are treated as part of the text of the previous paragraph. –  Rahul Nov 11 '13 at 8:26
    
What type of error? –  cormullion Nov 11 '13 at 8:33
    
NMinimize::bcons, which means my constraints are invalid –  novice Nov 11 '13 at 8:36
    
Please give an example on how do you want to define Tdata[] as a "2D matrix" –  belisarius Nov 11 '13 at 13:40
    
The curved surface is defined by Tdata as follows:f[{x_, y_}] := ( Cos[x] + Sin[y])/3; Tdata = Flatten[ Table[Flatten[{i, j, N[f /@ {{i, j}}]}], {i, 0, 6.5, 0.5}, {j, 0, 6.5, 0.5}], 1] –  novice Nov 12 '13 at 0:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.