Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kevlur

a math question about vectors/points 3d

This topic is 5279 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, could somebody help me with this problem? it''s about the displacement of points in 3D(and i think it can be solved with 3d vector operations): If there is a point/vector P in a 3d space, for example at coordinates (x = 20 units, z = 20 units, y = 20 units), how can i determine nine other points describing a circle around P, each of them being distant 50 units from P and each of them being placed on the same x/z plane(orizontal plane) as P ?

          
           .   
       .       .
     .     .P    .
      .         .
         .   .

(the worst design of the story of Gamedev.net i think, but dont hate me for this ) Thank you for any help.

Share this post


Link to post
Share on other sites
Advertisement
You would find the equation of the sphere surrounding that point at the desired radius. The general formula is (x-xOffset)^2 + (y-yOffset)^2 + (z-zOffset)^2 = radius^2. I believe in this case, that would be (x-20)^2 + (y-20)^2 + (z-20)^2 = 2500. If my math is wrong here, sorry in advance.

Then, since you want the circle on the xz plane at y=20, you can subsitute y=20 into the equation to get the equation of the circle lying on that plane: (x-20)^2 + (z-20)^2 = 2500.

Now if the nine points can be arbitrary, just pick 9 values from the range [centerX-radius, centerX+radius], plug them in and solve the equation.

For each x value you will get two z values. Depending on what x you pick (for instance if x were -30 or 70 in this case), the two solutions would be the same. In other cases, when taking the square root you have to account for both positive and negative roots and so you''d get two different z values.

If you don''t want the arbitrary points (for example, they''re evenly spaced at 40 degree intervals around the circle), then you''d need to throw some trig and arc formulae in there.

Hope that helps.

-Auron

Share this post


Link to post
Share on other sites
Or you could just use a simple loop to set the points like this :

(Pseudo/C Code)

: assuming P = point about which to generate the 9 points

int i=0
float ang = 0.0f
float step = (2PI/9)
Vec v, temp
Vec points[9]

v.x = 0.0f
v.y = 0.0f
v.z = 1.0f

for(ang=0.0; ang<2PI; ang+=step, i++)
{
RotateVecAroundY(&temp, &v, ang)
points = temp
points[i].x += P.x
points[i].y += P.y
points[i].z += P.z
}

...just a thought, obviously thats not tested or anything! and in no way optimal. Hope it''s an idea for you.

GCoder

Share this post


Link to post
Share on other sites
Thank you for your help Auron and GCoder, im trying your two ways to solve the problem

Share this post


Link to post
Share on other sites
p(x,y,z) is your center.

your points are given by

y = p.y

since you want to stay in the same XZ plane

x = p.x + r * cos(a)
z = p.z + r * sin(a)

where
r is the desired radius;
a is the angle at which you want your point...
most probably something like
a -> 0°, 40°, 80°, 120°, 160°, 200°, 240°, 280°, 320°
if you want 9 points.

I strongly advise you to strengten your geometry skills, since only really basic geometry was involved here.

Share this post


Link to post
Share on other sites
Now why didn''t I think of that... better yet, why do I always come up with the harder way to solve simple problems...

-Auron

Share this post


Link to post
Share on other sites
Jods is this correct?:


//P is the center(x=20,y=20,z=20)


int rad = 50;
D3DXVECTOR3 p[9];

for(i = 0, a = 0; a < 360; i++, a += 40)
{
p[i].y = P.y;
p[i].x = P.x + rad * cos(a);
p[i].z = P.z + rad * sin(a);
}

it''s really so simple?

Thank you very much Jods, your way to solve the problem is immediate and simple.

Thank you very much to all the other helps too.


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
sin() and cos() take arguments in radians, not degrees - multiply the angles by pi/180

Share this post


Link to post
Share on other sites
It looks ok to me, expect - as already mentionned - that sin and cos take their argument expressed in radians.

180[°] = Pi [rad]

So you have to multiply "a" by Pi/180, or even better change your loop for something like

for(i = 0, a = 0; i < 9; i++, a += 2*Pi/9)

(the successive additions could lead to some numeric instability, but since you''re only doing it 8 times, it will be ok).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!