You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to write equilateral function ?
4 views (last 30 days)
Show older comments
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 Comments
Torsten
on 12 Feb 2023
Edited: Torsten
on 12 Feb 2023
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
on 12 Feb 2023
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?
ghania gigi
on 13 Feb 2023
please can you give me a code
Walter Roberson
on 13 Feb 2023
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
on 13 Feb 2023
@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
on 13 Feb 2023
Edited: Torsten
on 13 Feb 2023
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
on 13 Feb 2023
Edited: Walter Roberson
on 13 Feb 2023
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
on 13 Feb 2023
Edited: Torsten
on 13 Feb 2023
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
ghania gigi
on 14 Feb 2023
yes , can you helpme when N=5?
ghania gigi
on 14 Feb 2023
how I can generate R
Answers (0)
See Also
Categories
Find more on Construction in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)