이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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 (한국어)