Trouble with finding appropriate conditions for logic
4 次查看(过去 30 天)
显示 更早的评论
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).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150504/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150505/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150506/image.jpeg)
1 个评论
Fredrick_jong
2013-3-17
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.
采纳的回答
Cedric
2013-1-17
编辑:Cedric
2013-1-17
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
更多回答(2 个)
Cedric
2013-1-17
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 个评论
Harold
2013-1-29
3 个评论
Cedric
2013-1-29
编辑:Cedric
2013-1-29
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!