Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Get a distant point on sphere

Subject: Get a distant point on sphere

From: kamal abuhassan

Date: 11 Oct, 2010 16:55:05

Message: 1 of 8

Hi,

I have created a sphere of large number of points as bellow:
points=1000;
[x,y,z]=sphere(points); % Create a sphere of 1001 x 1001 points
x=x*8; % raduis of the sphere = 8 mm
y=y*8;
z=z*8;

Given a certain point P1=[a , b , c]; Can I get all the points that are 12 distant (approximately) from P1 using the find command in MATLAB ?

I have used the command d = 8*atan2(norm(cross(P1,P2)),dot(P1,P2)); to compare the distance from each point to P1 but I need more effecient approach.

Thanks
Kamal.

Subject: Get a distant point on sphere

From: Roger Stafford

Date: 12 Oct, 2010 00:42:03

Message: 2 of 8

"kamal abuhassan" <kamal.abuhassan@hotmail.com> wrote in message <i8vfh9$2jo$1@fred.mathworks.com>...
> Hi,
>
> I have created a sphere of large number of points as bellow:
> points=1000;
> [x,y,z]=sphere(points); % Create a sphere of 1001 x 1001 points
> x=x*8; % raduis of the sphere = 8 mm
> y=y*8;
> z=z*8;
>
> Given a certain point P1=[a , b , c]; Can I get all the points that are 12 distant (approximately) from P1 using the find command in MATLAB ?
>
> I have used the command d = 8*atan2(norm(cross(P1,P2)),dot(P1,P2)); to compare the distance from each point to P1 but I need more effecient approach.
>
> Thanks
> Kamal.
- - - - - - - - -
  What about doing this:

 t = abs(sqrt((x-a).^2+(y-b).^2+(z-c).^2)-12)<tol; % The ring
 M = [reshape(x(t),[],1),reshape(y(t),[],1),reshape(z(t),[],1)];

where 'tol' should be set at the allowed variation (approximation) from 12 of the distance from P1 to points on the given sphere. It will constitute a ring of points on the sphere. The M array's three columns give the three coordinates of all the points in this ring.

  It should be pointed out that the expression "atan2(norm(cross(P1,P2)),dot(P1,P2))" which you mentioned is not a valid distance. It is the angle between the two vectors P1 and P2, which is quite a different concept from a distance metric. Multiplying it by eight makes no sense at all in your problem.

  It is true that in this problem the angle between your P1 = [a,b,c] and a vector P2 = [x,y,z] on this ring will be a certain (approximate) constant value depending on P1, but the above distance approach is a much easier way of determining the points in the ring. Also there is another ring on the sphere with the same angle but at a different distance.

Roger Stafford

Subject: Get a distant point on sphere

From: Bruno Luong

Date: 12 Oct, 2010 07:09:06

Message: 3 of 8

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i90asr$1m0$1@fred.mathworks.com>...

>
> It should be pointed out that the expression "atan2(norm(cross(P1,P2)),dot(P1,P2))" which you mentioned is not a valid distance. It is the angle between the two vectors P1 and P2, which is quite a different concept from a distance metric. Multiplying it by eight makes no sense at all in your problem.
>

Roger, I believe Kamal refers to the geodesic distance, where 8 - the radius of the sphere - must be multiplied.

Bruno

Subject: Get a distant point on sphere

From: kamal abuhassan

Date: 12 Oct, 2010 09:04:06

Message: 4 of 8


Roger and Bruno, Thanks for your replies.
Actually, my work is related to geodesic distance. Can any one help me ?
Kamal.

Subject: Get a distant point on sphere

From: Bruno Luong

Date: 12 Oct, 2010 11:56:04

Message: 5 of 8

"kamal abuhassan" <kamal.abuhassan@hotmail.com> wrote in message <i8vfh9$2jo$1@fred.mathworks.com>...
> Hi,
>
> I have created a sphere of large number of points as bellow:
> points=1000;
> [x,y,z]=sphere(points); % Create a sphere of 1001 x 1001 points
> x=x*8; % raduis of the sphere = 8 mm
> y=y*8;
> z=z*8;
>
> Given a certain point P1=[a , b , c]; Can I get all the points that are 12 distant (approximately) from P1 using the find command in MATLAB ?
>
> I have used the command d = 8*atan2(norm(cross(P1,P2)),dot(P1,P2)); to compare the distance from each point to P1 but I need more effecient approach.

Assuming P1 is in the sphere, you can just do

iscloserthan12 = [x(:) y(:) z(:)]*P1(:) > cos(12/8)*8^2

Bruno

Subject: Get a distant point on sphere

From: Bruno Luong

Date: 12 Oct, 2010 12:21:05

Message: 6 of 8

May be some graphics is better:

% 100 x 100 pnts on the sphere
[x,y,z] = sphere(100);
r = 8;
x=x*r; y=y*r; z=z*r;
% pick a random point on the sphere
P = rand(3,1);
P = P*r/norm(P);

d = 5;
% find points closer to P than geodesic distance d
b=[x(:) y(:) z(:)]*P(:)>cos(d/r)*r^2;

% Graphic
figure
plot3(x,y,z,'g.');
hold on; axis equal
plot3(x(b),y(b),z(b),'b.')
plot3(P(1),P(2),P(3),'ro')

% Bruno

Subject: Get a distant point on sphere

From: Roger Stafford

Date: 12 Oct, 2010 12:59:04

Message: 7 of 8

"kamal abuhassan" <kamal.abuhassan@hotmail.com> wrote in message <i918a6$ih7$1@fred.mathworks.com>...
>
> Roger and Bruno, Thanks for your replies.
> Actually, my work is related to geodesic distance. Can any one help me ?
> Kamal.
- - - - - - -
  Hello Kamal. I guess what threw me off was that you didn't say that P1 was itself on the sphere, which I think would be necessary for the concept of geodesic distance from P1 to P2 to make sense. With this interpretation of the word "distance", you are seeking all the points P2 = {x,y,z) on the sphere which make an angle of 12/8 = 1.5 radians with respect to the point P1 = (a,b,c).

  Using the 'atan2' formula is a robust method of solving this problem, but for the specific angle 1.5 radians, the simpler method Bruno gives is sufficiently accurate. Where the use of this easier formula would have accuracy difficulties would be where the geodesic distance were to be very small compared to 8 or else very close to 8*pi - that is, near the antipodes from P1. In those cases the 'atan2' approach would be more accurate, though requiring more computation.

  Whether you use '>', '<', or "within some 'tol' of equality", in Bruno's formula depends on whether you are asking for points closer to, farther away from, or approximate equal to, the given geodesic distance, respectively.

Roger Stafford

Subject: Get a distant point on sphere

From: kamal abuhassan

Date: 12 Oct, 2010 15:15:07

Message: 8 of 8

Roger and Bruno, Thank you very much for the useful discussions and the source code.
That was very helpful.
Kamal.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us