Can someone suggest the best way to plot a directional 2D equilateral triangle?

2 views (last 30 days)
I'm trying to write some simple code that will plot a 2D equilateral triangle, with the triangle center specified at a distance from an existing equilateral triangle, which is pointing at it? Any help offered would be greatly appreciated.
example triangle arrangement

Answers (2)

DGM
DGM on 14 Apr 2021
This is incomplete, but it should be a start.
r=10; % triangle radius
p0=[0 0]; % prior point [x,y]
p=[50 50]; % current point [x,y]
% offset angle based on distance vector
% this may already be known from prior triangle orientation
th=atan2d(p(2)-p0(2),p(1)-p0(1))+180;
% calculate vertex locations
xv=r*cosd(th+[0 120 240 0]) + p(1);
yv=r*sind(th+[0 120 240 0]) + p(2);
% plot this triangle
plot(xv,yv)
xlim([0 100])
ylim([0 100])
axis equal

Steve
Steve on 14 Apr 2021
Edited: Steve on 14 Apr 2021
Thank you DGM. Can this code be modified to generate a connected series of equilateral triangles? I am ultimately looking to have many triangles (generated at specific centerpoint locations), where their vertices are all pointing at neighboring triangles' vertices (as depictred below). Thanks again for your help!
Example of equilateral triangle arrangement
_____________________________________________________________________________________
Dottet lines for directional reference only
  2 Comments
DGM
DGM on 14 Apr 2021
I suppose it could. Mind you, it would be using plot tools to do so. If your goal is to generate a raster image directly, the drawing part might get a bit more complicated.
Steve
Steve on 14 Apr 2021
Edited: Steve on 14 Apr 2021
Raster images are definitely not needed; the triangle your code generates is actually perfect. I just provided the sketches to show sample triangle arrangements.
Also, ideally, if all the triangle center locations are given, I would like to be able to assign a single, initial triangle on one of the centers, with the orientation specified (always toward another triangle's center). Then, I would like to code to generate the rest of the oriented triangles from there on. Would this be possible with a modified version of your code? Attached is another sketch to show the idea. Thanks again!

Sign in to comment.

Categories

Find more on Triangulation Representation in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!