Skip to Main Content
Mastering Algorithms with C
book

Mastering Algorithms with C

by Kyle Loudon
August 1999
Intermediate to advanced content levelIntermediate to advanced
560 pages
18h 57m
English
O'Reilly Media, Inc.
Content preview from Mastering Algorithms with C

Implementation and Analysis of Arc Length on Spherical Surfaces

To compute the length of an arc on a spherical surface, we first must have a way to define the arc’s endpoints. For this, arclen accepts the two points p1 and p2. Each endpoint is an SPoint structure. This structure consists of three members, rho, theta, and phi, which are the spherical coordinates for a point expressed in radian measure.

The arclen operation (see Example 17.4) begins by converting spherical coordinates into rectilinear coordinates using the equations presented earlier. Recall that this allows us to calculate the angle between the lines extending from the center of the sphere to either point on its surface. Next, we simply multiply this angle by the radius of the sphere to obtain the length of the arc from p1 to p2.

The runtime complexity of arclen is O (1) because all of the steps in computing the length of an arc on a spherical surface run in a constant amount of time.

Example 17.4. Implementation for Computing Arc Length on Spherical Surfaces
/*****************************************************************************
*                                                                            *
*  ------------------------------- arclen.c -------------------------------  *
*                                                                            *
*****************************************************************************/

#include <math.h>

#include "geometry.h"

/*****************************************************************************
*                                                                            *
*  -------------------------------- arclen -------------------------------- * * * *****************************************************************************/ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Introducing Algorithms in C: A Step by Step Guide to Algorithms in C

Introducing Algorithms in C: A Step by Step Guide to Algorithms in C

Luciano Manelli
Head First C

Head First C

David Griffiths, Dawn Griffiths

Publisher Resources

ISBN: 1565924533Supplemental ContentErrata Page