Trouble with finding appropriate conditions for logic
Show older comments
I have a blunt body (Apollo capsule) modeled. I wrote a function to read in the vertices and the normals from the STL of this model. Given a velocity vector, I want to be able to figure out which facets of the capsule are in the shadow region (region where there is relatively no flow) and also any facets not on the heat shield (the facets that are not part of the cone and the radius at the top). I tried writing conditions down using the angle between the velocity vector and the normal vector of each facet. Right now I'm coloring these facets red so I can see if the conditions are detecting the right facets. The problem that I'm having is that some of the facets of interest are getting detected and some areas are not.
Included are some images of what the capsule looks like from the side and in 3d space and also the problem I am running into. The red line indicates the velocity vector pointing up. The whole underside of the capsule should be selected as well as the lower half of the rounded edge (the edge between the large heat shield and the cone sides).



1 Comment
Fredrick_jong
on 17 Mar 2013
Hi,
I was wondering, how did you manage to plot the Apollo capsule on MATLAB? I am currently trying to do that but I am unable to. Your assistance will be greatly appreciated. Many thanks in advance.
Accepted Answer
More Answers (2)
Cedric
on 17 Jan 2013
0 votes
Which method did you chose finally to..
- Flag facets in the shadow.
- Flag facets from the shield.
- Define colors.
Could you paste the code? Here it seems that you have something like a union of the upper part and facets exposed to flow.
9 Comments
Harold
on 17 Jan 2013
Ok, so if you want to flag in red your region of study which is, up to what I understood, the region of the shield that is not in the "shadow region", then you want to define
flagsInRed = ~flags_Shadow & flags_Shield ;
and change your code in PlotFacets into
if flagsInRed((k+2)/3)
color = 'r';
else
color = 'w';
end
It seems irrelevant just to change a variable name, but actually defining flagsInWhite would mean taking the negation of (~flags_Shadow & flags_Shield) which is (flags_Shadow | ~flags_Shield) ;-)
Now this won't work unless you set the boundary back to 0.6. The reason is that 0.65 captures one or two vertices of these long triangles that constitute the cone, and take the cone as being part of the shield. You could also change the logic behind the detection of polygons from the shield, e.g. by using all() instead of any():
flags_Shield = all( reshape( vertices(:,3), 3, [] ) < hBoundary );
which would require all vertices to be below the boundary for a facet to be flagged as being part of the shield.
As a side note, I would also change some loops in your code so they use a facetID rather than a vertexID. This would avoid computing the facet ID using (k+2)/3 which is a positive integer because "MATLAB is nice enough to understand that it is likely to be one", but which would be a float in other languages. Starting from a facetID and computing the IDs of vertices by multiplication surely leads to positive integer IDs. But this is more a question of preference I guess..
Harold
on 18 Jan 2013
Ah ok, then be sure to have hBoundary=0.6 and not 0.65, and it is just about permuting r/w:
flagsInWhite = ~flags_Shadow & flags_Shield ;
and
if flagsInWhite((k+2)/3)
color = 'w';
else
color = 'r';
end
I made these modifications really fast on the code that you posted yesterday, and it's working.
Harold
on 18 Jan 2013
Cedric
on 18 Jan 2013
My pleasure, I'm glad it works!
Harold
on 29 Jan 2013
0 votes
3 Comments
The key is: if it is not obvious whether a variable/function applies to vertices or to facets, then you should name this variable/function so it explicitly gives this information. Here are a few hints..
- For loops: name a loop index fId if it applies to facets and vId if it applies to vertices, instead of using i, j, k, etc.
- Build functions for converting vectors of indices from vertices to facets and vice versa. You could even use short names, e.g. f2v() and v2f():
function vId = f2v(fId)
% Return a nx3 array of vertices IDs, where n is the number of elements
% of fId (vector of facet IDs).
vId = [3*fId(:),3*fId(:)+1, 3*fId(:)+2] ;
end
function fId = v2f(vId)
% ...
...
end
- Think about "vector" ways to process your data. For example, If you had to build a flag enabling/disabling all facets that contain vertices from a list of vertices IDs vId_list, it would be much more efficient/clear to perform the following (using functions defined above):
fId_list = v2f(vId_list) ;
fEnabled = true(nFacets, 1) ;
fEnabled(fId_list) = false ;
than to build a complicated for loop using i as index, rounding i/3, etc.
Harold
on 29 Jan 2013
In fact, you could have the transpose of what I built above for vId, so you can exploit linear indexing:
function vId = f2v(fId)
% Return a 3xn array of vertices IDs, where n is the number of elements
% of fId (vector of facet IDs).
vId = [3*fId(:),3*fId(:)+1, 3*fId(:)+2].' ;
end
I don't know if you are familiar with linear indexing.. if not, look at the following:
>> A = [1 2; 3 4] ;
>> A(:)
ans =
1
3
2
4
Arrays are saved in memory in "column". A(:) means get all elements of A following the linear order in memory, which means that you get the entire column 1 first and the the entire column 2. This means for example that is v is a vector, v(:) is always the column version of this vector, even if v is a row vector.
So having vId as a 3xn matrix means that if you access it linearly with vId(:) you get a column vector with the 3 vertices of facet 1 of fId first, then the 3 vertices of facet 2 of fId, etc .. which can be useful.
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




