plot a 3-d figure (rhombus inside a cricle)
显示 更早的评论
Hello everybody.
I have an assignment to plot shape inside other shape. The assignment is related to electromagnetic fields, I need to describe the potential behavior from low potential to high potential. anyway all of this doesn't matter. because if someone will help with the code of the plot, I'll handle the rest.
The figure I need is a rhombus inside a circle a 3-d plot of course. I added an example of square inside a circle to illustrate my meaning.
THANK YOU VERY MUCH!

采纳的回答
更多回答(3 个)
Sean de Wolski
2011-4-25
Pseudocode (I don't want to do your whole assignment for you):
- Use the formula for a circle to create a logical circle the size you want (both circle size and matrix size) http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F . (M in the code below)
- Create a new variable that is the double precision equivalent of the circle. (C in the code below)
- Set the square in the middle of the circle (the logical circle) to false (M)
- Find the row/col coordinates of both sets of points in the map (true and false) ([rhave chave] and [rwant cwant])
- Use griddata and some fun logical indexing expressions to overwrite those values. I'll provide the code for that.
- Use mesh() to visualize
C(M) = griddata(rhave,chave,C(~M),rwant,cwant,'linear');
And to prove that I'm not talking out of my ass:

You can scale it as you wish at this point because the minimum value is zero and the square is 1; any multiplication will be a linear scale.
Good Luck!
3 个评论
Matt Fig
2011-4-25
I like your graphic, Sean de. It is basically what I did when I saw this post. However I think there is more to the story, as the image posted by the OP looks like it was derived from more elaborate constraints. If you will notice, the OP image looks like a square plate punched through an elastic circular membrane. Thus it almost looks to me like the solution to some sort of an Elastic Lagrange minimization problem.
Sean de Wolski
2011-4-25
Matt you're absolutely right! His obviously non-convex while mine is. There was nothing in the problem statement about that though; he said he'd take care of it. (This was a fun Monday morning wake-up challenge)
Andrew Newell
2011-4-25
Actually, the problem statement did say that it is a potential, as in Teja's answer.
Andrew Newell
2011-4-25
Suppose your potential function is z = V(x,y). Define V so that it can input matrices for x and y, e.g.,
V = @(x,y) 1./(x.^2+y.^2+1);
then create the matrices for your problem area, e.g.,
x = -40:1:40; y = -40:1:40;
[x,y] = meshgrid(x,y);
z = V(x,y);
Now you can plot it:
surf(x,y,z)
1 个评论
Sean de Wolski
2011-4-25
or do that inside bsxfun, i.e.:
z = bsxfun(@V,-40:40,(-40:40).');
Which means in theory (a detailed enough V function), this entire plot could be one-lined!
eli
2011-4-25
0 个投票
1 个评论
Andrew Newell
2011-4-25
For the benefit of other people reading this question, I recommend you accept Teja's response.
类别
在 帮助中心 和 File Exchange 中查找有关 General PDEs 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!