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 Comments

Torsten
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.
midpoint = (x + y) / 2;
distance = abs(y - x);
z = midpoint + distance;
like that?
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?
please can you give me a code
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.
@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 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.
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
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
yes , can you helpme when N=5?
how I can generate R

Sign in to comment.

Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 12 Feb 2023

Commented:

on 14 Feb 2023

Community Treasure Hunt

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

Start Hunting!