Archived

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

getting arbitary circle circumference coordinates

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

Recommended Posts

Hi I''m trying to write a camera behaviour where the camera rotates around the target and stays the same distance from the target at all times. I''m having trouble working out the mathematics of it. Let''s say I want the camera to be able to view the target from 100 different points, all equal amounts of space apart. Since the distance between the camera will always be the same this will in effect be the radius of a circle and the camera will always be at one of the arbitary points on said circle''s circumference. From this, how do I work out where the 100 points will be? I''m using java3d but really I just need some help getting the maths right... Thanks

Share on other sites
can someone verify this is correct???

cameraX = objectX + sin( angle ) * distanceToObject
cameraZ = objectZ + cos( angle ) * distanceToObject

you just wanted the x and z from the sounds of it

Share on other sites
Isn''t X suppose to use cos and the Z use sin?

Share on other sites
The sin and cos can be any way round. This way round is best I think, as zero degrees means along the positive z-axis.

Share on other sites
Hello and thank you for your time,

I have tried this code:

quote:

package com.codeinthewhole.trajectoryGame;

public class RotateTargetCamera {

private double cameraX, cameraZ = 0d;
private double objectDistance = 10d;
private double angle = 0d;
private double objectX, objectZ = 0d;
private double degreesInc = 90;

public RotateTargetCamera() {
for( double counter = 0d; counter < 360; counter += degreesInc ) {
angle = counter;
calculateCamPos();
System.out.println( "angle: " + angle );
System.out.println( "CamX: " + cameraX + ", " + "CamZ: " + cameraZ );
}
}

private void calculateCamPos() {
cameraX = objectX + Math.sin( Globals.getDegreesToRadians( angle ) ) * objectDistance;
cameraZ = objectZ + Math.cos( Globals.getDegreesToRadians( angle ) ) * objectDistance;
}

public static void main( String[] args ) {
new RotateTargetCamera();
}

} // EOF

Basically the distance from the object is 10 units and I have set it to output the positions for 0, 90, 180 and 270 degrees so the readings should all be either 0 or -10, or 10 yet I get this as the output:

angle: 0.0
CamX: 0.0, CamZ: 10.0
angle: 90.0
CamX: 10.0, CamZ: 6.123233995736766E-16
angle: 180.0
CamX: 1.2246467991473533E-15, CamZ: -10.0
angle: 270.0
CamX: -10.0, CamZ: -1.8369701987210296E-15

Can anyone help me get the code right I have been staring at this for ages and can''t quite get it???

Thanks - Kanamit

Share on other sites
quote:
Original post by Anonymous Poster
Basically the distance from the object is 10 units and I have set it to output the positions for 0, 90, 180 and 270 degrees so the readings should all be either 0 or -10, or 10 yet I get this as the output:

angle: 0.0
CamX: 0.0, CamZ: 10.0
angle: 90.0
CamX: 10.0, CamZ: 6.123233995736766E-16
angle: 180.0
CamX: 1.2246467991473533E-15, CamZ: -10.0
angle: 270.0
CamX: -10.0, CamZ: -1.8369701987210296E-15

Can anyone help me get the code right I have been staring at this for ages and can''t quite get it???

Thanks - Kanamit

looks correct to me, except you''re suffering from some rounding errors, not surprising really given the nature of the functions.

6.123233995736766E-16 is really this :
.000000000000006123233995736766

pretty damn close 0, if you ask me.

Share on other sites
As you can guess my maths are not very good, thank you for confirming these details are correct

Thanks - Kanamit

Share on other sites
quote:
Original post by Anonymous Poster
As you can guess my maths are not very good, thank you for confirming these details are correct
Thanks - Kanamit

yep, just incase you''re dont know yet ...

6.123233995736766E-16 = 6.123233995736766 * 10^-16 =
6.123233995736766/10^16

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• Forum Statistics

• Total Topics
632950
• Total Posts
3009382
• Who's Online (See full list)

There are no registered users currently online

×