Calculation method of pipeline volume rate based on ape physics engine

Source: Internet
Author: User

The volumetric rate is generally used in real estate development, which refers to the ratio of total floor area and total land area in the land, and this parameter is a very important index to measure the use intensity of construction land. In other industries, the calculation of volumetric rate is also very important, such as product utilization, pipeline utilization and so on. So in the monitoring system, how can vivid image of the expression volume rate calculation, is the monitoring system with accuracy, security, but also has a diversity, good interactivity and so on. The recent development of the game industry is also very rapid, in the handheld terminal 3D game is also more and more, then if we integrate the game engine into the monitoring system, what effect will be achieved, this article focuses on the use of ape physics engine combined with twaver 2D products to achieve the volume rate calculation of pipelines. First look at the effect:

Many physics engines, we use the more easy to start the ape engine, the first to understand the ape physics engine, you can download the classic Apedemo for research, download link: Ape Physics engine Demo (extract password: EYJM). Simple introduction of the Ape:

Abstractcollection Abstract classes for all groups

Abstractconstraint Abstract classes of all physical interactions

Abstractitem All interactions (collisions), particles of the base class

Abstractparticle about the base class of particles

Apengine main engine, Force class

Circleparticle Round particles

Rectangleparticle Rectangular particles

Composite can contain particles and collisions of complex classes

Group A class of groups that can contain particles, collisions, complexes

Springconstraint Two-particle class (spring) with a similar elastic collision

Vector Force

Wheelparticle a particle to simulate wheel behavior

Next start with the Twaver 2D product:

1. Create a network element with physical parameters Circleparticle: Class Circleparticle inherits from node network element which abstractparticle,abstractparticle inherits from Twaver;

Importjava.awt.geom.*;ImportTwaver.    Twaverconst;  Public classCircleparticleextendsabstractparticle {Private Double_radius; @Override PublicString Getuiclassid () {returnCircleparticleui.class. GetName (); }                 PublicCircleparticle (Doublex,Doubley,Doubleradius,Booleanfixed,DoubleMass,Doubleelasticity,Doublefriction) {            Super(x, y, fixed, mass, elasticity, friction); _radius=radius; if((double.valueof (x)! =NULL) && (Double.valueof (y)! =NULL)){                 This. setlocation (x, y); }                         This. Putcustomdraw (true);  This. Putcustomdrawshapefactory (twaverconst.shape_circle); } @Override Public intgetwidth () {//TODO auto-generated Method Stub            if(Double.valueof (_radius)! =NULL){                return(int) _radius*2; }            return Super. getwidth (); } @Override Public intgetheight () {//TODO auto-generated Method Stub            if(Double.valueof (_radius)! =NULL){                return(int) _radius*2; }            return Super. GetHeight (); }                 Public DoubleGetradius () {return_radius; }                         Public voidSetradius (Doubler) {_radius=R; }                 Public voidpaint () {if(CURR.Y > 500)return; if(Math.pow (curr.x+_radius-330,2) + Math.pow (curr.y+_radius-240, 2) > 150*150){                return; }             This. setlocation (int) (Curr.x-getradius ()), (int) (Curr.y-Getradius ())); }             PublicInterval getprojection (Vector axis) {Doublec =curr.dot (axis); Interval.min= C-_radius; Interval.max= C +_radius; returninterval; }                 PublicInterval Getintervalx () {interval.min= Curr.x-_radius; Interval.max= Curr.x +_radius; returninterval; }                         PublicInterval getintervaly () {interval.min= Curr.y-_radius; Interval.max= Curr.y +_radius; returninterval; }    }

2. Also create a view class Circleparticleui class, inheriting Nodeui, to draw the mesh element.

Import Twaver. Node; Import twaver.network.TNetwork;  Public class extends abstractparticeui{    public  Circleparticleui (tnetwork Network, node node) {         Super (Network, node);}    }

In this way, the network element under the physics engine is created, and then the load network element can be created as twaver.

//Initialize the scene, load the mesh element into the box and the physics enginePrivate voidInitworld () {Apengine.init (Double) 1/5);        Apengine.setcollisionresponsemode (Apengine.standard); Apengine.addmasslessforce (NewVector (0, 10)); Swingutilities.invokelater (NewRunnable () { Public voidrun () {intCount = 500;  for(inti = 0; I < Count; i++) {                    floatCenterX = 330; floatCenterY = 240; floatRADIUS = 150; floatx = (float) (CenterX +radius* Math.Cos (MATH.PI * 2/count *i)); floaty = (float) (CenterY +radius* Math.sin (MATH.PI * 2/count *i)); Circleparticle Circle=NewCircleparticle (x, Y, 1,true, 1, 0, 1);                    Apengine.addparticle (circle);                    Box.addelement (circle); I++;                }                            }        }); Paintqueue=Apengine.getall (); }
//update volume rate and alarm display rules Public voidUpdateworld () {apengine.step (); Alarm.setname (Count+ "pipe" + "/remaining area:" +remains/totals*100+ "%"); if(Remains/totals*100 <15) {alarmstate alarmstate=alarm.getalarmstate (); Alarmstate.increasenewalarm (Alarmseverity.minor,1); Alarm.putclientproperty ("Alarm", "alarm"); Flag=false; }    }//Draw Mesh Elements     Public voidPaintworld () { for(inti = 0; I < Paintqueue.size (); i++) {        if(Paintqueue.get (i)instanceofcircleparticle)                {((circleparticle) paintqueue.get (i)). Paint (); }    }    }
//finally set the scene update RulePrivate voidgame () {Usedtime= 1000; T= 0;    Initworld ();  while(flag) {T++; LongStartTime =System.currenttimemillis ();    Updateworld ();    Paintworld (); Usedtime= System.currenttimemillis ()-StartTime; Try{Thread.Sleep (30); } Catch(Interruptedexception e) {} }}

Such a monitoring volume rate calculation platform is completed, of course, based on a variety of physics engine can be completed more rich expression, if you have this aspect of the needs and ideas, welcome to discuss with us!

Calculation method of pipeline volume rate based on ape physics engine

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.