LEXECORP

Welcome!

January 22, 2009 · Leave a Comment

Worldwide

Welcome to Lexecorp! Need assistance with a Software Project or with an ICT  Japanese translation (日本翻訳) ? Or simply reading our blog? Please have a look around!

Email Software Services
電子メール (Email) Translation Services
Email Customer Service

lexecorplogo

© Lexecorp Pty Ltd. 2006-2009. All rights reserved.

→ Leave a CommentCategories: Announcements
Tagged: , , , , , , , , , , , , , , , , , , , , , , , , ,

Groovy’s projectile motion

July 10, 2009 · Leave a Comment

projectileToday I needed more than a decent crossword. So, I had a think about subjects that I had been fascinated by, way back when I was a student.

So what might I try to renegotiate in Groovy – the latest enhancement to Java / JVM programming and my preferred tool for Perl’ifing the JVM ;-) . Well, in general OOP or Object Orientated Programming, does not beautify formulas (and thinking of Java specifically, no operator overloading was a disaster), but Groovy does give the JVM something of what has been sorely missing.

Now before you get carried away, the Achilles heal of Groovy is speed. If I had to do something seriously numerically intensive, like FEA (Finite Element Analysis) on a supercomputer platform, then I might look elsewhere. But for a quick dip into calculating a projectile’s trajectory, I think we will be fine.

Well whilst I was doing my Masters (Comp Sci) some 20+ years ago, I landed a placement with the British Ministry of Defence. Not just any site,  but the Proof and Experimental establishment.

What did they do? Well they studied projectiles. And a noisy firing range they had too. There were some very bright mathematicians there whose job it was to simulate and later analyse projectile performance. Sadly you have me. However, due to my lower calibre within this department, you will at least have a chance of understanding the code ;-)

Ok, here we go. A quick play with Mathematica and then some coding in Groovy is the result I offer you here. So, don’t shy away from Groovy. I know Python is the in thing for Numerical experimentation these days, but why follow the herd.


// PROJECTILES
//
// formulas - Thank you Mathematica
//
// h = (v^2 sin^2(alpha))/(2 g)    // maximum height
// x = (v^2 sin(2 alpha))/g        // distance traveled
// T = (2 v sin(alpha))/g          // travel time

// v | initial speed
// alpha | release angle
// g | acceleration due to gravity (~~ 9.807 m/s^2)

class Cannon {
  def final g = 9.807F    // acceleration due to gravity (9.81 m/(s^2)
  def deg                 // angle projectile is launched (deg)
  def v                   // initial velocity of projectile (m/s)
  def y0                  // initial height of projectile (m)
  def d                   // total "horizontal" distance traveled by projectile (m)
  def h                   // max height achieved
  def T                   // travel time
                         // radians = deg*(Math.PI/180)
  def distance() {  
    // x = (v^2 sin(2 alpha))/g   
    d = (v**2 * Math.sin(2 * Math.toRadians(deg)))/g
  }

  def height() {
    // h = (v^2 sin^2(alpha))/(2 g)    
    h = (v**2 * (Math.sin(Math.toRadians(deg))**2)) / (2 * g)        
  }

  def time() {
    // T = (2 v sin(alpha))/g
    T = (2 * v * Math.sin(Math.toRadians(deg))) / g
  }

  @Override  
   public String toString() {  
   """Cannon angle($deg degrees) Launch Velocity($v m/s) Initial height($y0 metres)  
      Distance: ${String.format("%.1f", distance())} metres
      Height:${String.format("%.2f", height())} metres
      Time:${String.format("%.3f", time())} seconds"""  
   }  
} // Cannon

// go
println new Cannon(deg: -90.0F, v:45.0F, y0:1.0F) // into ground

println new Cannon(deg: 0.0F, v:45.0F, y0:1.0F) // level

                                                // at an angle
println new Cannon(deg: 25.0F, v:45.0F, y0:1.0F)
println new Cannon(deg: 30.0F, v:45.0F, y0:1.0F)
println new Cannon(deg: 35.0F, v:45.0F, y0:1.0F)
println new Cannon(deg: 40.0F, v:45.0F, y0:1.0F)
println new Cannon(deg: 45.0F, v:45.0F, y0:1.0F)

println new Cannon(deg: 90.0F, v:45.0F, y0:1.0F) // straight up

which gives some results which Mathematica confirms to be correct

Cannon angle(-90.0 degrees) Launch Velocity(45.0 m/s) Initial height(1.0 metres)
           Distance: -0.0 metres
           Height:103.24 metres
           Time:-9.177 seconds
Cannon angle(0.0 degrees) Launch Velocity(45.0 m/s) Initial height(1.0 metres)
           Distance: 0.0 metres
           Height:0.00 metres
           Time:0.000 seconds
Cannon angle(25.0 degrees) Launch Velocity(45.0 m/s) Initial height(1.0 metres)
           Distance: 158.2 metres
           Height:18.44 metres
           Time:3.878 seconds
Cannon angle(30.0 degrees) Launch Velocity(45.0 m/s) Initial height(1.0 metres)
           Distance: 178.8 metres
           Height:25.81 metres
           Time:4.589 seconds
Cannon angle(35.0 degrees) Launch Velocity(45.0 m/s) Initial height(1.0 metres)
           Distance: 194.0 metres
           Height:33.97 metres
           Time:5.264 seconds
Cannon angle(40.0 degrees) Launch Velocity(45.0 m/s) Initial height(1.0 metres)
           Distance: 203.3 metres
           Height:42.66 metres
           Time:5.899 seconds
Cannon angle(45.0 degrees) Launch Velocity(45.0 m/s) Initial height(1.0 metres)
           Distance: 206.5 metres
           Height:51.62 metres
           Time:6.489 seconds
Cannon angle(90.0 degrees) Launch Velocity(45.0 m/s) Initial height(1.0 metres)
           Distance: 0.0 metres
           Height:103.24 metres
           Time:9.177 seconds

→ Leave a CommentCategories: Software Design, Development & Programming
Tagged: , , , ,

Mine is bigger than yours

July 8, 2009 · Leave a Comment

Well not really mine. I do wish that we had bigger ones though. Whilst in the UK I saw a very big one. Yes, at work, I took a peek.

I am not surprised that the “Super size me” nation has the biggest and the most. Yes, the US is well endowed. My two sad little cores make for adequate performance but I’m not trying to visualize anything these days.

Yes, the big guns, supercomputing and where is it all happening? To find out, take a look at Top 500 and try the countries page. We (Australia) are somewhere in the others section. I am always surprised that the UK is so high up.

Scanning the top sites (installations)  and seeing mostly the U.S. and Japan,  it was interesting to see that the site I was working at is currently 24 on the list (Weather forecasting at the Meteorological Office takes some serious grunt).

Now isn’t Scandinavia a peculiar place. Tiny populations and yet countries like Sweden compete (in so many ways) on a world stage. Cars, mobile phones,… I think we Australians should pay heed!

→ Leave a CommentCategories: General · Graphics, Visualisation, Image Processing
Tagged: , ,

Groovy gave me piles

July 6, 2009 · 1 Comment

If you haven’t already, make sure to read Bob’s (@Transentia) massive improvement on the code from my last post. He made a lightly veiled piece of Java code really swing to a Groovy tune! He may also have gotten a little soiled playing with my piles!

Well, using Bob’s improvements with a little touch up (for densities and angles of repose), here’s a way to find out just how hard it would be to shift the mound of building material dropped on the end of your drive! Or, at least you can say how heavy it is and get someone else to shift it :-) .


enum Material {
  CEMENT(131.0F, 45.0F),
  DRYSAND(90.0F, 41.0F),
  WETSAND(118.0F, 26.0F),
  LOOSEGRAVEL(93.0F, 50.0F),
  PACKEDGRAVEL(100.0F, 45.0F),
  CLAY(120.0F, 43.0F)

  Material(D, theta) {
    this.D = D
    this.theta = theta
  }

  def D
  def theta
}

class ConicalPile {
  def m
  def h

  def getWeightPounds() {
    def cT = Math.cos(Math.toRadians(m.theta))
    (Math.PI * h ** 3 * m.D) / (3 * (cT ** 2))
  }

  def getWeightTons() {
    getWeightPounds() / 2000.0F
  }

  @Override
  public String toString() {
    """$m
  Weight(pounds): ${String.format("%.0f", getWeightPounds())}
  Weight(tons): ${String.format("%.3f", getWeightTons())}"""
  }
}

def testHt = 10.0F
println "At pile height of "+testHt+" foot"
for (Material m : Material.values())
  println new ConicalPile(m: m, h: testHt)

which when run gives us something that looks quite reasonable

At pile height of 10.0 foot
CEMENT
  Weight(pounds): 274366
  Weight(tons): 137.183
DRYSAND
  Weight(pounds): 165467
  Weight(tons): 82.734
WETSAND
  Weight(pounds): 152964
  Weight(tons): 76.482
LOOSEGRAVEL
  Weight(pounds): 235709
  Weight(tons): 117.855
PACKEDGRAVEL
  Weight(pounds): 209440
  Weight(tons): 104.720
CLAY
  Weight(pounds): 234939
  Weight(tons): 117.469

→ 1 CommentCategories: Software Design, Development & Programming
Tagged: ,