How can I draw a plane between 2 points ?

11 Ansichten (letzte 30 Tage)
VIGNESH BALAJI
VIGNESH BALAJI am 15 Nov. 2023
Kommentiert: William Rose am 19 Feb. 2024
Hi, I am trying to draw a plane between 2 points. I am not sure what is a good way to do it. My idea is that I have 3 points out of which 2 points represent a robot (as a point) and there is a common point between these 2 points. I am considering a stationary case and the robots cannot move more than a certain distnace from the common point, hence the maximum distance the robot can move is a circle around the common point. Let's assume all 3 points are stationary.
Let's say I have P0(common point), P1 (1st robot point), P2 (2nd robot point). I always want to compute the angle between P1 (Robot 1) and P2 (Robot 2). Hence, I started drawing a plane for each robot with respect to the common point and I am trying to find the angle between these planes. I tried using affine fit to make the planes (I am not sure whether this is the right choice) and I am not sure what is a good way to visualise this plane.
I have attached my code below, this is just for plane visualisation. This is not working as surf function is unable to find a conection, from previous issues raised by others here example this one - how to use surf function? - MATLAB Answers - MATLAB Central (mathworks.com) . I understand that Surf function is not a good choice for doing this. I would like to know other ways of doing this in Matlab
p_0 = [1.25, 1.0, 1.0];
p_1 = [1.0, 1.0, 1.0];
plane_1_points = [p_1; p_0];
figure;
XYZ_1 = plane_1_points;
plot3(XYZ_1(:,1),XYZ_1(:,2),XYZ_1(:,3),'r.');
hold on
%compute the normal to the plane and a point that belongs to the plane
[n_1,~,p_1] = affine_fit(XYZ_1);
%plot the two points p_1 and p_2
plot3(p_1(1),p_1(2),p_1(3),'ro','markersize',15,'markerfacecolor','red');
%plot the normal vector
quiver3(p_1(1),p_1(2),p_1(3),n_1(1)/3,n_1(2)/3,n_1(3)/3,'r','linewidth',2)
%plot the two adjusted planes
%[X,Y] = meshgrid(linspace(0,1,N));
X = reshape(XYZ_1(:,1), [2,1]);
Y = reshape(XYZ_1(:,2), [2,1]);
%first plane
surf(X,Y, - (n_1(1)/n_1(3)*X+n_1(2)/n_1(3)*Y-dot(n_1,p_1)/n_1(3)),'facecolor','red','facealpha',0.5);

Akzeptierte Antwort

William Rose
William Rose am 16 Nov. 2023
You need to specify the third point (P2) in order to define a unique plane, and the third point must not be collinear with P0 and P1.
You say "I always want to compute the angle between P1 (Robot 1) and P2 (Robot 2)." I assume you mean you want to compute the angle P1-P0-P2 (robot 1 to common point to robot 2). Remember the formula
where θ is the angle between u and v. Let u=P1-P0 and let v=P2-P0.
p0 = [1.25, 1.0, 1.0]; % common point
p1 = [1.0, 1.0, 1.0]; % robot 1
p2 = [1.15, 1.2, 0.95]; % robot 2
u=p1-p0; v=p2-p0; % vectors from common point to each robot
a=acos(dot(u,v)/(norm(u)*norm(v)));
fprintf('Angle between robots, from common point, =%.1f degrees.\n',a*180/pi);
Angle between robots, from common point, =64.1 degrees.
% create a mesh for plotting
ny=9; nx=9; % number of x and y grid locations
X=zeros(ny,nx); Y=X; Z=X; % allocate arrays
for i=1:ny
X(i,:)=p0(1)+((1-nx)/2:(nx-1)/2)*u(1)/2+(i-(ny+1)/2)*v(1)/2;
Y(i,:)=p0(2)+((1-nx)/2:(nx-1)/2)*u(2)/2+(i-(ny+1)/2)*v(2)/2;
Z(i,:)=p0(3)+((1-nx)/2:(nx-1)/2)*u(3)/2+(i-(ny+1)/2)*v(3)/2;
end
% draw 3D arrows
as=[p0;p0]; % start points
ae=[p1;p2]; % end points
global ColorOrder; ColorOrder='RGBCMYK';
figure
arrow3(as,ae,'o2'); % arrows
grid on; axis equal;
hold on;
% draw mesh
mesh(X,Y,Z,'EdgeColor',[.2,.2,.2])
xlabel('X'); ylabel('Y'); zlabel('Z')
I chose p2 so that v=p2-p0 is not the same length as, and is not perpendicular to, u=p1-p0, and so that the plane would be tilted.
The script computes and displays the angle between the robots, from the common point.
The mesh is made of multiples of vectors u/2 and v/2.
This script uses arrow3() from the Matlab File Exchange to draw arrows u=p1-p0 (red) and v=p2-p0 (green).
When you run it on your own machine, you can use the 3D rotate tool to view the plot from different angles.
  4 Kommentare
VIGNESH BALAJI
VIGNESH BALAJI am 19 Feb. 2024
@William Rose can someone please answer me this question - Unable to install Gazebo Plugin for Simulink co-simulation - MATLAB Answers - MATLAB Central (mathworks.com). I have been waiting on this answer for a long time. Thanks in advance :)
William Rose
William Rose am 19 Feb. 2024
@VIGNESH BALAJI, I cannot help with that question.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Agriculture finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by