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:
Coordinate on sphere(vector calculus)

Subject: Coordinate on sphere(vector calculus)

From: Els

Date: 25 Mar, 2010 14:14:05

Message: 1 of 18

I have a sphere, with center x0,y0,z0 and a radius r.
Furthermore I have a point 1 outside the sphere x1,y1,z1.
But now I want to calculate the coordinates of Point 2, which is on the surface of the sphere, and the CenterP2P1 is 90 degrees there.

With these two points, I made a 3d triangle.
Sides:
- Center - P1 (length calculated by Euclidean distance)
- Center - P2 (length = radius of the sphere)
- P1 - P2 (length = Pythagoras formula)

With Euclidean distances it is easy to calculate all the lengths of all the sides.

But can someone point me towards the possible very simple solution of this problem, the coordinate of point 2?

Subject: Coordinate on sphere(vector calculus)

From: Jan Simon

Date: 25 Mar, 2010 15:10:20

Message: 2 of 18

Dear Els!

> I have a sphere, with center x0,y0,z0 and a radius r.
> Furthermore I have a point 1 outside the sphere x1,y1,z1.
> But now I want to calculate the coordinates of Point 2, which is on the surface of the sphere, and the CenterP2P1 is 90 degrees there.

The problem is not well defined: There are an infinite number of points matching this condition.

Your teacher is payed for helping you. I do not expect, that she is very glad about reading their questions in a Matlab related newsgroup. BTW: Is there any connection to Matlab?!

Kind regards, Jan

Subject: Coordinate on sphere(vector calculus)

From: Els

Date: 25 Mar, 2010 15:31:04

Message: 3 of 18

Dear Jan,

Your answer is absolutely direct, my definition of the problem is maybe a bit vague.
This is not homework, but just a really small aspect of my graduation thesis.
A module which I am making in MatLab.
But you are correct, this is more a mathematical question than a MatLab question.

I will try to find my answer another way.

Thanks.

Subject: Coordinate on sphere(vector calculus)

From: Jan Simon

Date: 25 Mar, 2010 16:37:04

Message: 4 of 18

Dear Els!

> A module which I am making in MatLab.
That is related to Matlab.

> But you are correct, this is more a mathematical question than a MatLab question.
Perhaps you want to compute it efficiently, because you do it millions of times ;-)

The main problem remains: You are looking for a point, but the definition you gave defines a circle with the radius of the sphere.

Kind regards, Jan

Subject: Coordinate on sphere(vector calculus)

From: Matt J

Date: 25 Mar, 2010 16:47:04

Message: 5 of 18

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hog3fg$308$1@fred.mathworks.com>...

> The main problem remains: You are looking for a point, but the definition you gave defines a circle with the radius of the sphere.
============

I don't think it's the radius of the sphere. It defines a circle on the surface of the sphere, but not necessarily a great circle.

Subject: Coordinate on sphere(vector calculus)

From: Jan Simon

Date: 25 Mar, 2010 16:54:04

Message: 6 of 18

Dear Matt J!

> > The main problem remains: You are looking for a point, but the definition you gave defines a circle with the radius of the sphere.
>
> I don't think it's the radius of the sphere. It defines a circle on the surface of the sphere, but not necessarily a great circle.

You are right, Matt - most likely. It depends on what "and the CenterP2P1 is 90 degrees there" exactly means. I thought the 90 deg angle is in the center. But it could be "angle when going from center over P2 to P1" also.

Thanks, Jan

Subject: Coordinate on sphere(vector calculus)

From: Roger Stafford

Date: 25 Mar, 2010 17:00:23

Message: 7 of 18

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hog428$cek$1@fred.mathworks.com>...
> "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hog3fg$308$1@fred.mathworks.com>...
>
> > The main problem remains: You are looking for a point, but the definition you gave defines a circle with the radius of the sphere.
> ============
>
> I don't think it's the radius of the sphere. It defines a circle on the surface of the sphere, but not necessarily a great circle.

  That depends on which angle is 90 degrees, the angle between OP's "Center-P1" and "Center-P2" or between "P1-P2" and "Center-P2". That was not made clear by the OP.

Roger Stafford

Subject: Coordinate on sphere(vector calculus)

From: Matt J

Date: 25 Mar, 2010 18:12:06

Message: 8 of 18

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

>
> That depends on which angle is 90 degrees, the angle between OP's "Center-P1" and "Center-P2" or between "P1-P2" and "Center-P2". That was not made clear by the OP.
============

Perhaps. When the OP said the angle CenterP2P1 must be 90, I definitely took that to mean the angle at the vertex P2. That's a convention I've seen before.

Subject: Coordinate on sphere(vector calculus)

From: Els

Date: 25 Mar, 2010 18:49:04

Message: 9 of 18



What I meant was that the angle between "P1-P2" and "Center-P2" should be 90 degrees. So, indeed, at the vertex P2.

Subject: Coordinate on sphere(vector calculus)

From: Matt J

Date: 25 Mar, 2010 18:56:02

Message: 10 of 18

"Els " <y.e.t.reeuwijk@student.utwente.nl> wrote in message <hogb70$f9s$1@fred.mathworks.com>...
>
>
> What I meant was that the angle between "P1-P2" and "Center-P2" should be 90 degrees. So, indeed, at the vertex P2.
==============

Well, here are the equations that P2 must satisfy

dot(P1,P2)=r^2
dot(P2,P2)=r^2

As you can see, you have 2 equations in 3 unknowns, so as we've been saying, there will be no unique solution.
 

Subject: Coordinate on sphere(vector calculus)

From: Matt J

Date: 25 Mar, 2010 19:02:05

Message: 11 of 18

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hogbk2$mkc$1@fred.mathworks.com>...

> Well, here are the equations that P2 must satisfy
>
> dot(P1,P2)=r^2
> dot(P2,P2)=r^2
>
> As you can see, you have 2 equations in 3 unknowns, so as we've been saying, there will be no unique solution.
===============

Here I assumed that x0=y0=z0=0, but you can solve under this assumption and then make a coordinate shift later...


>

Subject: Coordinate on sphere(vector calculus)

From: Bruno Luong

Date: 25 Mar, 2010 20:19:03

Message: 12 of 18

% Data
P0=randn(3,1)
r=rand

P1=randn(3,1);
d=r+abs(randn);
P1 = P0 + P1*(d/norm(P1))

% Engine
d = norm(P1-P0);
r2 = r^2;
a = r2/d;
b = sqrt(r2-a^2);
V = P1-P0;
Q = null(V');
theta = linspace(0,2*pi) % any angle value to parametrize P2
B = b*Q*[cos(theta); sin(theta)];
A = (a/d)*(P1-P0);
P2 = bsxfun(@plus, A+P0, B)

% Check
for idx=1:size(P2,2)
    dot(P2(:,idx)-P1,P2(:,idx)-P0) % orthogonality
    norm(P2(:,idx)-P0)-r % on the sphere
end

% Bruno

Subject: Coordinate on sphere(vector calculus)

From: Els

Date: 25 Mar, 2010 21:24:04

Message: 13 of 18



Dear Bruno,

Thanks a lot for all your effort, but can you help me understand the final step?
P2 gives all the possible solutions, and where do you use the final check for?

> % Check
> for idx=1:size(P2,2)
> dot(P2(:,idx)-P1,P2(:,idx)-P0) % orthogonality
> norm(P2(:,idx)-P0)-r % on the sphere
> end
>

And in my data, the Q is an empty matrix, which makes it impossible to construct B, any tips?

Els

Subject: Coordinate on sphere(vector calculus)

From: Bruno Luong

Date: 25 Mar, 2010 21:34:05

Message: 14 of 18

"Els " <y.e.t.reeuwijk@student.utwente.nl> wrote in message <hogk9k$mpn$1@fred.mathworks.com>...
>
>
> Dear Bruno,
>
> Thanks a lot for all your effort, but can you help me understand the final step?
> P2 gives all the possible solutions, and where do you use the final check for?

I do not understand the question.

> And in my data, the Q is an empty matrix, which makes it impossible to construct B, any tips?
>

What is the size of V? V must be a (3x1) vector. P0 and P1 must be also (3x1) vectors.

Bruno

Subject: Coordinate on sphere(vector calculus)

From: James Tursa

Date: 25 Mar, 2010 22:15:04

Message: 15 of 18

"Els " <y.e.t.reeuwijk@student.utwente.nl> wrote in message <hogb70$f9s$1@fred.mathworks.com>...
>
>
> What I meant was that the angle between "P1-P2" and "Center-P2" should be 90 degrees. So, indeed, at the vertex P2.

So you are just trying to find the tangent point(s) on the sphere on a line that goes through P1?

James Tursa

Subject: Coordinate on sphere(vector calculus)

From: Bruno Luong

Date: 25 Mar, 2010 22:29:05

Message: 16 of 18

"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hogn98$8s8$1@fred.mathworks.com>...

>
> So you are just trying to find the tangent point(s) on the sphere on a line that goes through P1?
>

That's what I also understood.

Bruno

Subject: Coordinate on sphere(vector calculus)

From: Els

Date: 26 Mar, 2010 05:27:05

Message: 17 of 18

Yes, it should indeed be the tangent, which makes a 90 degrees angle with the radius of the sphere, in this case that is the Center-P2 line.

But I do not understand this code does, and what the output means. Which coordinate couples are correct, the ones who get a 0 value?

% Check
for idx=1:size(P2,2)
    dot(P2(:,idx)-P1,P2(:,idx)-P0) % orthogonality
    norm(P2(:,idx)-P0)-r % on the sphere
end

Subject: Coordinate on sphere(vector calculus)

From: Bruno Luong

Date: 26 Mar, 2010 05:37:03

Message: 18 of 18

"Els " <y.e.t.reeuwijk@student.utwente.nl> wrote in message <hohgj8$1vk$1@fred.mathworks.com>...

> But I do not understand this code does, and what the output means. Which coordinate couples are correct, the ones who get a 0 value?
>

All are correct. Because of floating point round-off errors, some of them are not exactly 0 (they must be all very small numbers), but you shouldn't discard them.

Bruno

Tags for this Thread

No tags are associated with 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