COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Distance calculation in sphere

• Email
• Follow

```I have used the following code to generate a sphere of radius 8:
[x,y,z] = sphere(30);
x=x*8;
y=y*8;
z=z*8;

for now, I am trying to calculate the distance between two points on the sphere, Can you please help me? I am also looking for a method to get all neighrong points of a certain point (on sphere) within a circle of radius 0.5 ?

Thanks,
Kamal.
```
 0

See related articles to this posting

```"kamal abuhassan" <kamal.abuhassan@hotmail.com> wrote in message <hplfrr\$r8k\$1@fred.mathworks.com>...
> I have used the following code to generate a sphere of radius 8:
> [x,y,z] = sphere(30);
> x=x*8;
> y=y*8;
> z=z*8;
>
> for now, I am trying to calculate the distance between two points on the sphere, Can you please help me? I am also looking for a method to get all neighrong points of a certain point (on sphere) within a circle of radius 0.5 ?
>
> Thanks,
> Kamal.

I'll just answer your first question.  If P1 = [x1,y1,z1] and P2 = [x2,y2,z2] are two vectors pointing from the center of the sphere to the two given points (x1,y1,z1) and (x2,y2,z2) on the sphere, what is the shortest great circle distance d between them?

d = 8*atan2(norm(cross(P1,P2)),dot(P1,P2));

Roger Stafford
```
 0

```"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hplht6\$396\$1@fred.mathworks.com>...
> "kamal abuhassan" <kamal.abuhassan@hotmail.com> wrote in message <hplfrr\$r8k\$1@fred.mathworks.com>...
> > I have used the following code to generate a sphere of radius 8:
> > [x,y,z] = sphere(30);
> > x=x*8;
> > y=y*8;
> > z=z*8;
> >
> > for now, I am trying to calculate the distance between two points on the sphere, Can you please help me? I am also looking for a method to get all neighrong points of a certain point (on sphere) within a circle of radius 0.5 ?
> >
> > Thanks,
> > Kamal.
>
>   I'll just answer your first question.  If P1 = [x1,y1,z1] and P2 = [x2,y2,z2] are two vectors pointing from the center of the sphere to the two given points (x1,y1,z1) and (x2,y2,z2) on the sphere, what is the shortest great circle distance d between them?
>
>  d = 8*atan2(norm(cross(P1,P2)),dot(P1,P2));
>
> Roger Stafford

Thank you so much Roger
Kamal.
```
 0