Swardson Studios

Production and Training


Posts Tagged ‘ Programming ’

latlongxyzWith the help of some initial work from a friend of mine and some research online I have implemented a way to accurately place objects on a sphere using latitude and longitude coordinates. However, we are not simply rotating the object with its pivot point at the center of the
sphere. We are actually converting the longitude and latitude coordinates to XYZ coordinates on the fly.

First, let me explain what Latitude and Longitude actually are. To explain this I will use the most logical subject, the Earth. We all know what the equator is… or at least I hope so. The equator is the line that divides the Earth’s northern hemisphere from its southern hemisphere. Remember this term. The second term needed to discuss Latitude/Longitude is the Prime Meridian. The Prime Meridian is the line that divides the Earth’s Eastern hemisphere from it’s Western hemisphere. While the equator is a natural defining division of the
Earth based on its rotation, the Prime Meridian is an arbitrary line that passes through Greenwhich, England and each of the Earth’s poles. The complimentary line to the Prime Meridian is the International Date Line which is on the opposite side of the Earth.

To start the description, Latitude describes the angle along the equator from the Prime Meridian. In fact the Prime Meridian defines 0
degrees Latitude. Longitude describes the angle along the Prime Meridian from the Equator. In fact, the Equator defines 0 degrees
Longitude. So, a Longitude and Latitude of 35, 106 describes 35 degrees off the Equator and 106 degrees off the Prime Meridian.

In computer graphics we often define objects in space by X, Y and Z coordinates based on the origin of 0, 0, 0. It makes sense then to want to get different coordinate systems into X, Y and Z rather than trying to define X, Y and Z into other systems. So how do we do that? Well, it’s all about trigonometry in this situation.

Here is the equation.

1
2
3
tx = radiusOfSphere * cos(latitude) * cos(longitude);
ty = radiusOfSphere * -sin(latitude);
tz = radiusOfSphere * cos(latitude) * sin(longitude);

I won’t go into why this works because it is kind of drawn out. If you want to know, Google it and you should find many mathematical papers describing this.

The only thing about this equation that is tricky is that it returns values in radians rather than degrees. Again, if you want to know the
difference, Google it.

So lets set it up in Maya.

Create the Earth geometry as a nurbs or poly sphere in Maya with a specific radius (say 25, and yes, I know the Earth isn’t a true sphere, but the difference is so small, we simply omit it for purposes of art and simplicity).

After applying the earth color texture map to the sphere you will need to rotate the sphere by 90 degrees in Y to get the texture lined
up with where it needs to be (don’t worry to much about this, just do it).

Create the object you want to place at a specific lat/long on the Earth. Add 3 custom float attributes to it.

latitude (controls the latitude of the object)
longitude (controls the longitude of the object)
altitude (controls the distance from the object’s center to the sphere’s surface, think of a radius offset)

Then create the following expression and apply it (notice the deg_to_rad function that converts the latitude and longitude degrees into radians before being calculated).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
float $radius = 25; //radius of the sphere or Earths surface in Maya</code>
 
float $altitude = $radius + pSphere1.alt; // distance from center of earth to center of object.
 
float $long = deg_to_rad(pSphere1.long)*-1; //longitude value in radians
 
float $lat = deg_to_rad(pSphere1.lat)*-1; //latitude value in radians
 
// the equation to do the conversion and placement.
 
pSphere1.translateX = $altitude * cos($lat) * cos($long);
 
pSphere1.translateY = $altitude * sin($lat) * -1;
 
pSphere1.translateZ = $altitude * cos($lat) * sin($long)

Once applied to your object (a poly sphere in my case) will be placed on the Earth in the correct position at your given altitude.

**Special thanks to Adam Kugler for pointing out a discrepancy with the code. Thanks for the tip!

Try setting some keys on the attributes and see the object travel along the surface of the Earth.

New Life City

By Brad Swardson on May 29, 2009

nlc

http://www.newlifecity.org

This project is the largest and most ambitious of my web design and development projects.  I joined with New Life City as their web developer and designer in 2005.  Since then the site has evolved through 3 different iterations starting with a static site moving to the completely dynamic and customizable drupal CMS site.

I have found drupal to be an extremely adept and versatile solution to web based CMS needs.  With its fully customizable interface and add on selection, quick changes and additions are much faster than coding them manually.  However, even with its ease of use the site still presented some major challenges such as multiple node based audio setups including itunes validated RSS feeds, and a semi-fluid design structure that maximized the screen real-estate and optimized the image and text fluidity.

This is an evolving project that is changing as the needs and desires of the NLC staff require.  I expect new and more awesome things to come from the site, but definitely am confident and happy with it now.

-Brad

Life in the City

By Brad Swardson on March 29, 2009

litc

http://www.newlifecity.org/lifeinthecity/

In addition to the New Life City website, Pastor Alan Hawkins wished to create a seperate portal for his recorded radio broadcasts.  The material for this show tends to be more down to Earth and gets into the nitty gritty of life in the city from hot topics to sensitive issues.

I wanted this site to be a bit darker and a bit grungier but still allow for the shining light in the city.

Another change I made was that it utilizes a Wordpress blogging system as the back end rather than drupal or another CMS.  I was highly impressed with the newest versions of Wordpress and decided it would be a good fit for this project.  The theme utilizes some fancy layouts to display the 4 receent submissions on the front page as well as some archiving and comment listing on the bottom.

All in all I think it turned out really well and Pastor Alan really likes it too.

-Brad

Swardson.com

By Brad Swardson on January 29, 2009

swardsonSitehttp://www.swardson.com

This site was a personal project completed for my final portfolio class in my masters degree program at the Savannah College of Art and Design.  I was tasked to create a site that reflected other portfolio and business design elements.  The overall concept was the idea of authenticity and longevity.  The logo with the signature represents a pact between me and my clients that what they ask for they will get.  The earthy tones reflect the level of authenticity I portray in all areas of business.

The site was initially designed to be expandable to add tutorials, blogs, content and products for my various projects but was sercumvented by this site as it fit my business models better.

This project turned out fairly well in my opinion and may utilize it’s look in the future.

-Brad

Best Rental Ever.com

By Brad Swardson on July 29, 2008

bestRentalEverhttp://www.bestrentalever.com

I created this site as a host for my rental property.  I wanted to create a site that was both stylish and informative that would increase the interest in the home while allowing possible tenants the ability to tour the room photos and gather information easily.

This site featured the lightbox image gallery system which is really awesome and easy to use.

I also explored some more non-traditional design to make it feel somewhat like a flyer, but enough like a website so as to not make it confusing.

I had a lot of fun with this site and it ended up paying off.

-Brad