How to write equilateral function ?
3 次查看(过去 30 天)
显示 更早的评论
Write the function in Matlab equilateral, which takes two different points x,y ∈ R N, N > 1, and returns one point z ∈ R N such that (x,y,z) are the vertices of an equilateral triangle, that is, the point z must satisfy ||x−z|| = ||y−z|| = ||x−y||
thanks in advance
11 个评论
Torsten
2023-2-12
编辑:Torsten
2023-2-12
Hint:
Given x and y, can you construct a vector that is normal to the line connecting x and y ?
If you let this normal vector start in the midpoint of the line connecting x and y, where do you have to place z in the direction of this normal vector such that the distance between z and x as well as z and y is equal to the distance between x and y ?
Remember that the height of an equilateral is sqrt(3)/2 if its side length is 1.
John D'Errico
2023-2-12
Is that an equilateral triangle? (NO.)
Suppose the length of a side of an equilateral triangle were known? What property would the height of the triangle have? Thus, the height of the perpendicular to that side?
Walter Roberson
2023-2-13
Your midpoint is a good start.
Your distance is not correct though. You are being given input points in 2 or more dimensions, so you need to calculate the length of the line segment, which will be a scalar quantity. abs(y-x) for vector x and y does not calculate the length of the vector. sqrt(sum((y-x).^2) which only reduces to abs when N=1
You need to find the perpendicular to the line x y
To emphasize: the question is for 2 or more dimensions, so just handling 2d is not enough.
John D'Errico
2023-2-13
@ghania gigi If we give you the code when you are perfectly capable of doing it yourself, then we are doing what is clearly a homework assignment for you.
@Walter Roberson - Given only two points, it is not possible to find a UNIQUE equliateral triangle in more than 2 dimensions, so your comment is not correct here. Said differently, there would be infinitely many such equilateral triangles. And that is clearly not the question at hand, so you can assume the 2-d case.
But again for @ghania gigi, What is the height of the triangle? You are almost there. I'll recap what you have done so far. Given two points, x and y, the midpoint is:
midpoint = (x + y) / 2;
That formula works for vectors too.
The length of one of the sides is the distance between those points. abs(x-y) does not quite work, since x and y are vectors that live in a 2-dimensional space. But this does work:
edgelength = norm(x-y);
I'll give you that much.
But now I'll repeat my question. If the edge has length 1, then what would the height be? This is basic geometry. The Pythagorean theorem would suffice. Or basic trig will do it too. But you need to make some effort!
Torsten
2023-2-13
编辑:Torsten
2023-2-13
Said differently, there would be infinitely many such equilateral triangles. And that is clearly not the question at hand, so you can assume the 2-d case.
I don't think so. The assignment says to determine one point z ∈ R^N such that (x,y,z) are the vertices of an equilateral triangle. But of course, the solution is not that much different.
ghania gigi
2023-2-13
编辑:Walter Roberson
2023-2-13
N=2.
x = randn(N, 1);
y = randn(N, 1);
xy = y-x;
heta = deg2rad(60);
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
z =x + xy .* R';
This is my code when N=2 ,but I would when N=5
Torsten
2023-2-13
编辑:Torsten
2023-2-13
Doesn't work even in case N = 2. Didn't you test your code ?
Must read
z =x + R*xy;
instead of
z =x + xy .* R';
and
theta = deg2rad(60);
instead of
heta = deg2rad(60);
A generalization of this method is more difficult in N dimensions than the simple method John and I suggested.
N=2;
x = randn(N, 1);
y = randn(N, 1);
xy = y-x;
theta = deg2rad(60);
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
z =x + xy .* R';
norm(z-x)
ans = 2.2489
norm(z-y)
ans = 1.5942
norm(y-x)
ans = 2.3185
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polar Plots 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)