DEFCON1 Posted January 9, 2010 Share Posted January 9, 2010 Hello, I need a function to calculate points on a 3D circle, which will have these parameters: param 1 : amount of points to calculate params 2, 3, 4 : an origin 3D point -> center of the circle param 5 : a radius -> distance from circle origin to points param 6 : a yaw angle -> rotation around world's z axis param 7 : a pitch angle -> rotation around circle's x axis return : a table with points coordinates and angles Actually, I've got everything but the Z and PITCH calculations. Adding another dimension is too hard, I'm stuck . Here is my code actually, which work for a 2D circle, mean the returned table contain X, Y coordinates and yaw angle for each points: local RAD2DEG = 57.295779513082320876798154814105 local DEG2RAD = 0.017453292519943295769236907685 local PI2 = 6.283185307179586476925286766559 local cos = math.cos local sin = math.sin function getPointsOnCircle2D(points, originX, originY, radius, yaw) yaw = ( yaw + 90 ) * DEG2RAD local t = {} local a = PI2 / points for i = 1, points do t[i] = { originX + ( cos( yaw ) * radius ), originY + ( sin( yaw ) * radius ), yaw * RAD2DEG } yaw = yaw + a end return t end Thanks for any help ! Link to comment
DEFCON1 Posted January 9, 2010 Author Share Posted January 9, 2010 Hello, I need a function to calculate points on a 3D circle, which will have these parameters: param 1 : amount of points to calculate params 2, 3, 4 : an origin 3D point -> center of the circle param 5 : a radius -> distance from circle origin to points param 6 : a yaw angle -> rotation around world's z axis param 7 : a pitch angle -> rotation around circle's x axis return : a table with points coordinates and angles Actually, I've got everything but the Z and PITCH calculations. Adding another dimension is too hard, I'm stuck . Here is my code actually, which work for a 2D circle, mean the returned table contain X, Y coordinates and yaw angle for each points: local RAD2DEG = 57.295779513082320876798154814105local DEG2RAD = 0.017453292519943295769236907685local PI2 = 6.283185307179586476925286766559 local cos = math.coslocal sin = math.sin function getPointsOnCircle2D(points, originX, originY, radius, yaw) yaw = ( yaw + 90 ) * DEG2RAD local t = {} local a = PI2 / points for i = 1, points do t[i] = { originX + ( cos( yaw ) * radius ), originY + ( sin( yaw ) * radius ), yaw * RAD2DEG } yaw = yaw + a end return t end Thanks for any help ! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now