How to write equilateral function ?

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
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.
Hamza
Hamza 2023년 2월 12일
midpoint = (x + y) / 2;
distance = abs(y - x);
z = midpoint + distance;
like that?
John D'Errico
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?
ghania gigi
ghania gigi 2023년 2월 13일
please can you give me a code
Walter Roberson
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
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
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
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
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
ghania gigi
ghania gigi 2023년 2월 14일
yes , can you helpme when N=5?
ghania gigi
ghania gigi 2023년 2월 14일
how I can generate R

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

질문:

2023년 2월 12일

댓글:

2023년 2월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by