Created
January 30, 2013 03:15
-
-
Save jontonsoup/4670303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
/* | |
Author: Cynthia Stamelos | |
Date: 1/28/13 | |
*/ | |
double distance(double x1, double y1, double x2, double y2); | |
double triperimeter (double x1, double y1, double x2, double y2, double x3, double y3); | |
double arrayX1 [14] = {0, 0, 0, 2.5, 2.5, 1, 4, 2, 0, 0, 0, 0, -1.5, 0}; | |
double arrayX2 [14] = {5, 5, 0, -1.8, 2.5, 3, 2, 6, 4, 5, 0, 0, 2.4, 5}; | |
double arrayX3 [14] = {4, 2.5, 2.5, -2.5, 0.5, 2.5, 0, 0, 0, 0, 0, 0, 0, 0}; | |
double arrayY1 [14] = {0, 0, 0, -3.2, 2.5, 2, 3, 4, 0, 0, 0, 0, -2.3, 0}; | |
double arrayY2 [14] = {5, 0, 5, 6.9, 2.5, 4, 1, 8, 0, 0, 5, 5, -0.5, 0}; | |
double arrayY3 [14] = {3, 2.5, 2.5, 2.5, 2.5, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | |
int main() | |
{ | |
int i; | |
printf("Point One \t\t Point Two \t Distance\n"); | |
for(i = 0; i < 8; i++) | |
{ | |
double x1 = arrayX1[i]; | |
double x2 = arrayX2[i]; | |
double y1 = arrayY1[i]; | |
double y2 = arrayY2[i]; | |
double result = distance(x1, y1, x2, y2); | |
printf("(%.1f,%.1f) \t (%.1f, %.1f) \t %.2f\n", x1, y1, x2, y2); | |
} | |
return 0; | |
} | |
double distance(double x1, double y1, double x2, double y2) | |
{ | |
double differenceX = (x1 - x2); //calculate the x distance | |
double differenceY = (y1 - y2); //calculate the y distance | |
double SQdifferenceX = (differenceX)*(differenceX); | |
double SQdifferenceY = (differenceY)*(differenceY); | |
return sqrt((SQdifferenceX) + (SQdifferenceY)); //return the answer as the overall distance | |
} | |
int function() { | |
int j; | |
printf("Point One \t\t Point Two \t Point Three \t Distance\n"); | |
for(j = 8; j < 14; j++) | |
{ | |
double x1 = arrayX1[j]; | |
double x2 = arrayX2[j]; | |
double x3 = arrayX3[j]; | |
double y1 = arrayY1[j]; | |
double y2 = arrayY2[j]; | |
double y3 = arrayY3[j]; | |
double result = triperimeter(x1, y1, x2, y2, x3, y3); | |
printf("(%.1f,%.1f) \t (%.1f, %.1f) \t (%.1f, %.1f) \t %.2f\n", x1, y1, x2, y2, x3, y3); | |
} | |
return 0; | |
} | |
double triperimeter (double x1, double y1, double x2, double y2, double x3, double y3) | |
{ | |
double distance_x1 = (x1 - x2); | |
double distance_x2 = (x2 - x3); | |
double distance_x3 = (x3 - x1); | |
double distance_y1 = (y1 - y2); | |
double distance_y2 = (y2 - y3); | |
double distance_y3 = (y3 - y1); | |
double tri_perimeter = sqrt((distance_x1)*(distance_x1) + (distance_y1)*(distance_y1)) + sqrt((distance_x2)*(distance_x2) + (distance_y2)*(distance_y2)) +sqrt((distance_x3)*(distance_x3) +(distance_y3)*(distance_y3)); | |
return tri_perimeter; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment