Trouble with finding appropriate conditions for logic

6 views (last 30 days)
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
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.

Sign in to comment.

Accepted Answer

Cedric
Cedric on 17 Jan 2013
Edited: Cedric on 17 Jan 2013
Could you have an issue with the orientation of your facets, e.g. by coding vertice IDs clockwise when they should be coded counterclockwise or vice versa? That would make part of your normals point in the wrong direction which would change the sign of the scalar product with the velocity vector (if it's what you use to detect facets in the shadow region).
Without seeing your code, there isn't much more that comes to my mind.
EDIT: here are a few hints after looking at your code.
  • The red line that you display vertically is different from the "free-stream vector" b that you define in facet_sort.m.
  • You rotate vertices in Apollo.m but you forget to rotate normals .
These two combined explain the angle. If you set b=[0 0 1] in facet_sort.m for example, you will see that the heat shield will be displayed in red.
Several for loops could be eliminated if you had efficiency requirements. E.g. in facet_sort.m, you could replace the computation of theta (the whole for loop) by:
flagsShadow = normals * b.' < 0 ; % Or > 0 depending the orientation
% your facets.
and propagate these flags back into PlotFacets.m to select the color, instead of performing tricky computations with angles.
Hope it helps!
Cedric
  7 Comments
Cedric
Cedric on 17 Jan 2013
Edited: Cedric on 17 Jan 2013
if you use vectors of logical for flagging facets, then you just want to apply logical operators
flagsInRed = ~flagsShadow & flagsShield ;
would be a vector flagging facets that are both in the shield and not in the shadow.
Harold
Harold on 17 Jan 2013
Edited: Harold on 17 Jan 2013
That worked to some degree. The cone on the top is getting selected for some reason even though the z coordinates are greater than 0.65 (the value that I'm testing against). Another problem is that for greater attack angles, the sides are getting picked up. This is odd since the intersection should of taken care of this.
0 attack angle
-30 attack angle
-60 attack angle

Sign in to comment.

More Answers (2)

Cedric
Cedric on 17 Jan 2013
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
Cedric
Cedric on 27 Jan 2013
Edited: Cedric on 27 Jan 2013
Well, without running your code, my first guess is that you are indexing your array of vertices whose size is 3*nFacets x 3 (= nVertices x 3 ) with a logical index for facets whose size is nFacets.
Harold
Harold on 28 Jan 2013
Edited: Harold on 29 Jan 2013
I checked the size of the logic indexes and the vertices and you were right. The size of the logic indexes is exactly 3 times smaller than that of the vertices. This is because Flow_flags is calculated using normals. The size of normals will always be 3 times smaller than the vertices since each row or normals describes the location of the normal. So what I did was output Flow_flags from face_sort and used the kron function to replicate every row of Flow_flags three times so that I get the same size as the vertices matrix. This worked to some extent. I have a few intersection points that appear on the small rounded cone part at the top of the capsule. This doesn't do this when alpha is set to 0 though. I'm not sure why this happens but I know that I am on the right track. By the way, the variable xsym is the x value of where the plane of symmetry is for the model. You can change this to change the x location of the yz cutting plane. Just run Apollo from the editor window.
I just realized that if the rounded cone comes past the heat shield, there are flags that get picked up. If you set view([-90 0]) and change the alpha angle you can see this happen.

Sign in to comment.


Harold
Harold on 29 Jan 2013
I believe I have just figured out what I was doing wrong. I should of been using the replicated ShieldFlow_flags for the row indexes of vertices. This works now. I now only get red dots on the heat shield facets that are exposed to the flow.
  3 Comments
Harold
Harold on 29 Jan 2013
Thanks for the tips. I will definitely have to incorporate these.
Cedric
Cedric on 29 Jan 2013
Edited: Cedric 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.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements 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!