changeset 16:5ac8c7980aaf

Normalize vectors
author Josef "Jeff" Sipek <jeffpc@optonline.net>
date Fri, 02 Dec 2005 23:48:40 -0500
parents 20615d891b8c
children b1a93dc1601d
files normalize.c
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/normalize.c	Fri Dec 02 23:48:40 2005 -0500
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+void normalize(float pt[3])
+{
+	float mag = sqrt(pt[0]*pt[0] + pt[1]*pt[1] + pt[2]*pt[2]);
+	if (mag == 0) {
+		printf("0 0 0\n");
+		return;
+	}
+	printf("%f %f %f\n", pt[0] / mag, pt[1] / mag, pt[2] / mag);
+}
+
+int main(int argc, char **argv) 
+{
+	float pt[3];
+	
+	while(scanf("%*f %*f %*f %f %f %f", &pt[0], &pt[1], &pt[2])==3)
+		normalize(pt);
+	
+	return 0;
+}
+