Implement a primitive volume function ... for hyperboloids of one sheet (HYP)BRL-CAD
Status: ClosedTime to complete: 72 hrs Mentors: Sean, Matt S.Tags: C, C++, math, geometry, volume

 

BRL-CAD provides more than two dozen types of geometry "primitives" such as ellipsoids, boxes, and cones. Every primitive is described by a collection of callback functions, for example rt_ell_bbox() returns the bounding box dimensions for an ellipsoid. Wikipedia, Wolfram Mathworld, and various other math sites (and research papers) around the web include the equations for most of our basic primitives while others are a little more difficult to compute.

This task involves writing a new callback function that takes an rt_db_internal object and calculates the volume (units are mm^3). There are numerous examples in our code where we compute volume for other primitives. The primitives that do not already have a volume callback are itemized in following.

References:

Code:

  • src/librt/primitives/hyp/hyp.c
Uploaded Work
File name/URLFile sizeDate submitted
hyp.c38.9 KBNovember 30 2012 22:16 UTC
hyp.c38.9 KBNovember 30 2012 22:16 UTC
hyp.c39.0 KBDecember 01 2012 02:13 UTC
hypvolume.patch1.8 KBDecember 14 2012 04:54 UTC
Comments
Ben Brayon November 27 2012 23:41 UTCTask Claimed

I would like to work on this task.

Matt S. on November 27 2012 23:57 UTCI'll mentor this task!

I'm not sure if I have the ability to assign this task to you or not, but I will be happy to mentor it when it is assigned.


 


-Matt

Sean on November 28 2012 00:01 UTCTask Assigned

This task has been assigned to Ben Bray. You have 72 hours to complete this task, good luck!

Sean on November 28 2012 00:03 UTCyou do

Matt, not only do you have the ability to assign the task (select the assign task button), you have the ability to assign yourself as a mentor too (select the edit task button).  That goes for ANY task that interests you. ;)


Cheers!

Matt S. on November 28 2012 00:08 UTCgot it

Ah, I see.  OK, I'll stick my name on a few things shortly.  Thanks!


 


-Matt

Ben Brayon November 30 2012 22:18 UTCReady for review

The work on this task is ready to be reviewed.

Matt S. on November 30 2012 22:35 UTCLooks correct

This looks good, but I don't have time to actually properly check this for at least a few hours.  I'm extending the deadline in order to give myself fime to go over this a little later.  Of course, somebody else may get around to it  first...


-Matt

Matt S. on November 30 2012 22:36 UTCDeadline extended

The deadline of the task has been extended with 0 days and 12 hours.

Ben Brayon December 1 2012 02:16 UTCMinor Adjustment

I updated the file with code that I believe is more preferrable.  Instead of calling hyp_internal_to_specific() in each call to rt_volume(), I replaced the method call with just the code that I needed.  No more unnecessary calculations.


- Ben

Melange on December 1 2012 14:51 UTCNo more Work can be submitted

Melange has detected that the deadline has passed and no more work can be submitted. The submitted work should be reviewed.

Matt S. on December 1 2012 22:36 UTCCouple things...

First, I cannot figure out how to actually call this function, so I cannot test it.  How have you managed to do it?


Second, the most recent version (Dec. 01) does not compile, whereas the older one (Nov. 30) compiles without any issues.  Hooray!


Finally, I think there is a computational error in your code.  Using your notation, the volume should be:


*vol = M_PI * h * r1 * r1 * (1 + ( (h * h) / (12 * c * c)));


should it not?  So, if you want to fix this, and tell me how you have called it, I'll re-open the task for you.


Cheers!

Matt S. on December 1 2012 22:49 UTCActually, looking a little more...

This approach will not be totally compatible with the hyp primitive anyway, as the parameter "B" used in defining a hyp primitave allows for an elliptical cross section, not just circular ones.  I didn't actually notice this at first--my bad!


Thus, your function is actually going to require quite a bit more effort I'm afraid, this version will only ever work when B = 1.

Matt S. on December 1 2012 22:49 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Ben Brayon December 2 2012 00:24 UTCCalling rt_volume

I wasn't able to figure out how to call the method, either.  There isn't much documentation, I'm afraid.  Have you figured out how to call it yet?


The rtweight command is supposed to return the volume of shapes, but I can't figure out how to get rtweight to work either; when I pass it a *.r file it gives me errors.


I'll modify my code to work with cases where B 1.  

Ben Brayon December 9 2012 21:29 UTCClaim Removed

The claim on this task has been removed, someone else can claim it now.

Aaron Keesingon December 10 2012 10:12 UTCTask Claimed

I would like to work on this task.

Aaron Keesingon December 10 2012 10:14 UTCIdentical Task

I noticed there was another identically named and described task as well, so what is the difference between this one and that one?


Aaron K

Harmanpreet Singh on December 10 2012 10:25 UTCTask Assigned

This task has been assigned to Aaron Keesing. You have 72 hours to complete this task, good luck!

Daniel Rossberg on December 10 2012 11:44 UTCDuplicate task

Aaron, I don't know whats the difference between these two tasks.  I think, the intention was to split this task in two or more parts becasuse of the mathematical difficulty.  You should know that a HYP is something similar to http://mathworld.wolfram.com/EllipticHyperboloid.html


Any progress in calculating the HYP primitive's volume would make this task count as completed.  However, the first steps is to develop the formula as there is no handy yet.

Matt S. on December 10 2012 23:33 UTCIt does indeed seem to be a duplicate

Also, for what it's worth, I've sketched up a possible solution strategy here:


http://brlcad.org/wiki/Image:Volume_computation.pdf


I'm not sure it's correct though--it was done in a rush and I have not worked all the way through it.  But it may be a start...

Aaron Keesingon December 11 2012 08:23 UTCToo complex?

Matt, I looked at your volume computation PDF, but surely there must be some easier way of calculating the volume. Are you not able to find the volume by integration of cross-sectional area. Using basic calculus, I integrated the function for cross-sectional area from 0 to h/2 (if hyp is oriented in z and has center at 0), then multiplied this by 2 to get the formula:


V = pi*a*b*h*(1 + (h^2)/(12*c^2)).


This was using the standard formula for a hyperboloid of x^2/a^2 + y^2/b^2 - z^2/c^2 = 1; the formula described in hyp.c has a slightly different formula. But the formula for the volume should still be somewhat similar.

Matt S. on December 11 2012 21:27 UTCThere probably is an easier way

But I don't think it's what you've suggested.  Maybe it is though.  Let's investigate, shall we?


You're saying that youor volume element is:


dV = A(z)dz


    =\pi * r1(z) * r2(z) * dz


where r1(z) and r2(z) are the major and minor axes of the ellipse, determined via


(x^2 / a^2) + (y^2 / b^2) - (z^2/c^2) = 1


and your'e saying this leads to your provided formula for V?  Please do show me how--I'm not saying you're incorrect, I'm saying I don't have time this minute to work through the computations right now.  And I won't have the time in the next while either...


Cheers!

Aaron Keesingon December 12 2012 11:16 UTCHyperboloid Volume

I have created a document which hopefully shows you how I came to my formula for the volume:


https://docs.google.com/open?id=0BydeQ6BPlVejRTFyRkFlbWNXNjQ


Regards


Aaron K

Melange on December 13 2012 10:25 UTCInitial Deadline passed

Melange has detected that the initial deadline has passed and it has set the task status to ActionNeeded. The student has 24 hours to submit the work before the task is reopened and sent back to the pool for other students to claim.

Sean on December 13 2012 14:55 UTCDeadline extended

The deadline of the task has been extended with 1 days and 0 hours.

Sean on December 13 2012 15:02 UTCif that can be verified

It'll take some time to digest that, but I added more time just to keep the clock rolling. Matt and Daniel are both better at reviewing the math tasks faster than I can (takes me forever to get everything into context).  :)


Of course, there's always the demonstrative approach.  Create a HYP with a known volume (e.g., where it equals an RCC), and show it works by comparison.  If we run out of review time, we can accept the task and create another for someone to test it (but at the risk of the code getting ranked wholesale if it doesn't work).

Daniel Rossberg on December 13 2012 18:49 UTCThe suggested solution sounds reasonable

I havn't checked every step but the approach with the integral shows how it should work.  Maybe Matt should have a look at it too and correct me if I'm wrong.


The next steps (in different tasks) would be to



  • implement the formula in BRL-CAD

  • make tests, e.g. compare the volume of HYPs equal to RCCs with the volumes of these RCCs

Daniel Rossberg on December 13 2012 19:19 UTCPlease mark the task as completed

Aaron, if it's not completed I can't close it ;)

Aaron Keesingon December 14 2012 04:54 UTCReady for review

The work on this task is ready to be reviewed.

Aaron Keesingon December 14 2012 05:38 UTCCode

I've tested the formula using a cylinder like Sean said, although I only tested it twice.


I've submitted the code (which includes the centroid function I did for a previous task) as hypvolume.patch


Aaron K

Daniel Rossberg on December 14 2012 08:18 UTCLet's leave it at that

The code has some shortfalls in my opinion but for a GCI task enough work was invested here.  Additional efforts need to be made in an additional task (e.g. in the twin of this one).

Daniel Rossberg on December 14 2012 08:18 UTCTask Closed

Congratulations, this task has been completed successfully.

Sean on December 14 2012 14:13 UTCfollow-on task

A follow-on task for this work has been created:


http://www.google-melange.com/gci/task/view/google/gci2012/8074203