Skip to content

Commit 13729b4

Browse files
author
francoisgrondin
committed
Circle arc added
1 parent 8c2859b commit 13729b4

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

manyears-C/dsplib/Localisation/sphere.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,62 @@ void sphereInit(struct objSphere *mySphere, unsigned int numberLevels)
670670

671671
}
672672

673+
void sphereArcInit(struct objSphere *mySphere, float angleInDegreeStart, float angleInDegreeStop, unsigned int nPoints) {
674+
675+
unsigned int indexPoint;
676+
677+
float angleInDegreeStartMod;
678+
float angleInDegreeStopMod;
679+
float theta;
680+
float x,y,z;
681+
682+
// *************************************************************************
683+
// * STEP 1: Initialize context *
684+
// *************************************************************************
685+
686+
// Number of recursive levels to generate the points on the sphere
687+
// We set it to zero here because it is a special case
688+
mySphere->SPHERE_NUMBERLEVELS = 0;
689+
690+
// Number of triangles according to the number of levels
691+
// No triangle in this specific case
692+
mySphere->SPHERE_NUMBERTRIANGLES = 0;
693+
694+
// Number of points on the arc
695+
mySphere->SPHERE_NUMBERPOINTS = nPoints;
696+
697+
// Sphere
698+
mySphere->spherePoints = (float **) newTable2D(mySphere->SPHERE_NUMBERPOINTS,3,sizeof(float));
699+
700+
// *************************************************************************
701+
// * STEP 2: Generate points *
702+
// *************************************************************************
703+
704+
angleInDegreeStartMod = angleInDegreeStart - floorf(angleInDegreeStart / 360.0f) * 360.0f;
705+
angleInDegreeStopMod = angleInDegreeStop - floorf(angleInDegreeStop / 360.0f) * 360.0f;
706+
707+
if (angleInDegreeStopMod <= angleInDegreeStartMod) {
708+
angleInDegreeStopMod = angleInDegreeStop + 360.0f;
709+
}
710+
711+
for (indexPoint = 0; indexPoint < mySphere->SPHERE_NUMBERPOINTS; indexPoint++) {
712+
713+
theta = angleInDegreeStartMod + indexPoint * (angleInDegreeStopMod - angleInDegreeStartMod) / (mySphere->SPHERE_NUMBERPOINTS - 1);
714+
715+
x = cosf(2*M_PI*theta/360.0f);
716+
y = sinf(2*M_PI*theta/360.0f);
717+
z = 0;
718+
719+
mySphere->spherePoints[indexPoint][0] = x;
720+
mySphere->spherePoints[indexPoint][1] = y;
721+
mySphere->spherePoints[indexPoint][2] = z;
722+
723+
printf("%u: %f %f %f\n",indexPoint,x,y,z);
724+
725+
}
726+
727+
}
728+
673729
/*******************************************************************************
674730
* sphereClone *
675731
* --------------------------------------------------------------------------- *

manyears-C/dsplib/Localisation/sphere.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@
131131
******************************************************************************/
132132

133133
void sphereInit(struct objSphere *mySphere, unsigned int numberLevels);
134+
135+
void sphereArcInit(struct objSphere *mySphere, float angleInDegreeStart, float angleInDegreeStop, unsigned int nPoints);
134136

135137
void sphereClone(struct objSphere *sourceSphere, struct objSphere *destSphere);
136138

0 commit comments

Comments
 (0)