Revision: 54145
http://brlcad.svn.sourceforge.net/brlcad/?rev=54145&view=rev
Author: brlcad
Date: 2013-01-08 19:47:57 +0000 (Tue, 08 Jan 2013)
Log Message:
-----------
apply another patch from aaron keesing
(http://www.google-melange.com/gci/task/view/google/gci2012/7982218) that
implements a surface area function for rhc
Modified Paths:
--------------
brlcad/trunk/src/librt/primitives/rhc/rhc.c
brlcad/trunk/src/librt/primitives/table.c
Modified: brlcad/trunk/src/librt/primitives/rhc/rhc.c
===================================================================
--- brlcad/trunk/src/librt/primitives/rhc/rhc.c 2013-01-08 18:48:50 UTC (rev
54144)
+++ brlcad/trunk/src/librt/primitives/rhc/rhc.c 2013-01-08 19:47:57 UTC (rev
54145)
@@ -1791,6 +1791,62 @@
return 1;
}
+void
+rt_rhc_surf_area(fastf_t *area, const struct rt_db_internal *ip)
+{
+ if (area != NULL && ip != NULL) {
+ struct rt_rhc_internal *rip;
+ fastf_t A, arclen, integralArea, a, b, magB, sqrt_ra, height;
+
+ fastf_t h;
+ fastf_t sumodds = 0, sumevens = 0, x = 0;
+ int i, j;
+
+ /**
+ * n is the number of divisions to use when using Simpson's
+ * composite rule below to approximate the integral.
+ *
+ * A value of n = 1000000 should be enough to ensure that the
+ * approximation is accurate to at least 10 decimal places.
+ * The accuracy of the approximation increases by about 2 d.p with
+ * each added 0 onto the end of the number (i.e. multiply by 10),
+ * so there is a compromise between accuracy and performance,
+ * although performance might only be an issue on old slow
+ * hardware.
+ *
+ * I wouldn't recommend setting this less than about
+ * 10000, because this might cause accuracy to be unsuitable for
+ * professional or mission critical use.
+ */
+ int n = 1000000;
+
+ RT_CK_DB_INTERNAL(ip);
+ rip = (struct rt_rhc_internal *)ip->idb_ptr;
+ RT_RHC_CK_MAGIC(rip);
+
+ b = rip->rhc_c;
+ magB = MAGNITUDE(rip->rhc_B);
+ height = MAGNITUDE(rip->rhc_H);
+ a = (rip->rhc_r * b) / sqrt(magB * (2 * rip->rhc_c + magB));
+ sqrt_ra = sqrt(rip->rhc_r * rip->rhc_r + b * b);
+ integralArea = (b / a) * ((2 * rip->rhc_r * sqrt_ra) / 2 + ((a * a) /
2) * (log(sqrt_ra + rip->rhc_r) - log(sqrt_ra - rip->rhc_r)));
+ A = 2 * rip->rhc_r * (rip->rhc_c + magB) - integralArea;
+
+ h = (2 * rip->rhc_r) / n;
+ for (i = 1; i <= (n / 2) - 1; i++) {
+ x = -rip->rhc_r + 2 * i * h;
+ sumodds += sqrt((b * b * x * x) / (a * a * x * x + pow(a, 4)) + 1);
+ }
+ for (j = 1; j <= (n / 2); j++) {
+ x = -rip->rhc_r + (2 * j - 1) * h;
+ sumevens += sqrt((b * b * x * x) / (a * a * x * x + pow(a, 4)) + 1);
+ }
+ arclen = (h / 3) * (sqrt((b * b * rip->rhc_r * rip->rhc_r) / (a * a *
rip->rhc_r * rip->rhc_r + pow(a, 4)) + 1) + 2 * sumodds + 4 * sumevens +
sqrt((b * b * rip->rhc_r * rip->rhc_r) / (a * a * rip->rhc_r * rip->rhc_r +
pow(a, 4)) + 1));
+
+ *area = 2 * A + 2 * rip->rhc_r * height + arclen * height;
+ }
+}
+
/*
* Local Variables:
* mode: C
Modified: brlcad/trunk/src/librt/primitives/table.c
===================================================================
--- brlcad/trunk/src/librt/primitives/table.c 2013-01-08 18:48:50 UTC (rev
54144)
+++ brlcad/trunk/src/librt/primitives/table.c 2013-01-08 19:47:57 UTC (rev
54145)
@@ -927,8 +927,8 @@
rt_rhc_params,
rt_rhc_bbox,
NULL,
+ rt_rhc_surf_area,
NULL,
- NULL,
},
{
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS
and more. Get SQL Server skills now (including 2012) with LearnDevNow -
200+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only - learn more at:
http://p.sf.net/sfu/learnmore_122512
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits