Calculate the distance squared of a point in 3d space

Asked by Devdolly Saini

Devdolly Saini (view profile)

on 10 Sep 2019
Latest activity Commented on by Rena Berman

Rena Berman (view profile)

on 19 Sep 2019
how do I calculate the squared distance between two points in 3d space where the 2 inputs say P and Q and 1d arrays say P=[P1,P2,P3] and Q=[Q1,Q2,Q3]
so far i have the following but i don't think thats correct but I think im on the right track.
function [distanceSquared] = PixelDistance(P,Q)
P=[P1,P2,P3]
Q=[Q1,Q2,Q3]
distanceSquared =(P1-Q1).^2 +(P2-Q2).^2 +(P3-Q3).^2
end
thanks

Stephen Cobeldick

Stephen Cobeldick (view profile)

on 13 Sep 2019
Original Question (from Google Cache):
how do I calculate the squared distance between two points in 3d space where the 2 inputs say P and Q and 1d arrays say P=[P1,P2,P3] and Q=[Q1,Q2,Q3]
so far i have the following but i don't think thats correct but I think im on the right track.
function [distanceSquared] = PixelDistance(P,Q)
P=[P1,P2,P3]
Q=[Q1,Q2,Q3]
distanceSquared =(P1-Q1).^2 +(P2-Q2).^2 +(P3-Q3).^2
end
thanks
Rik

Rik (view profile)

on 13 Sep 2019
It is considered extemely rude to edit away your question. Bruno has requested the site admins to revert the edit for this question. Please don't edit away your questions in the future. If you want private help you should hire a consultant.
Rena Berman

Rena Berman (view profile)

on 19 Sep 2019
(Answers Dev) Restored edit

Release

R2019a

Answer by Bruno Luong

Bruno Luong (view profile)

on 10 Sep 2019

function [distanceSquared] = PixelDistance(P,Q)
P1 = P(1); P2 = P(2); P3 = P(3);
Q1 = Q(1); Q2 = Q(2); Q3 = Q(3);
distanceSquared =(P1-Q1).^2 +(P2-Q2).^2 +(P3-Q3).^2
end