473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Looking for an algorithm/example for plotting functions to pixel arrays

archonmagnus
113 100+
Hello all,

I've been experimenting with developing an orbital analysis program. Being a visually oriented person, I'd like to translate my (x, y) coordinate pairs to an pixel image array so I can plot the satellite ground tracks on a bitmap, JPEG, PNG, etc. If I simply truncate the values to integers, I'll only have discrete (an most likely) overlapping points rather than line segments that join pixels.

Basically, what I'd like to find out about is how to go about plotting values to pixels using a better method (and having much better plotting results/fidelity) than simply truncating.

Below is the relevant section of code:
Expand|Select|Wrap|Line Numbers
  1.     do
  2.     {
  3.         for (i = 0; i < width; i++)
  4.         {
  5.             // Shifted so that longitude = 0 is on the prime meridian
  6.             longitude = ((((double)i / (double)width) * 360.0) - 180.0);  // [units: deg]
  7.             longitude *= (pi / 180.0);    // Convert to radians
  8.             longitude -= m;
  9.  
  10.             latitude = (amplitude
  11.                           * sin((scale * longitude) + (raan * pi / 180.0)))
  12.                           + (0.5 * (double)height);
  13.  
  14.             if (track == 0)
  15.                 outPix.green[i][(int)latitude] = outPix.blue[i][(int)latitude] = 0;
  16.             else if (track == 1)
  17.                 outPix.red[i][(int)latitude] = outPix.green[i][(int)latitude] = 0;
  18.             else if (track == 2)
  19.                 outPix.red[i][(int)latitude] = outPix.blue[i][(int)latitude] = 0;
  20.         }
  21.  
  22.         if (++track > 3)
  23.             done = true;
  24.  
  25.         m -= longitudinalDifference;
  26.     } while (!done);
  27.  
The code sample should generate a periodic function, the first sweep across the image should be colored red, the second sweep blue, and the third sweep green. When the amplitude of the periodic function is sufficiently low, the plot looks ok; however, when the amplitude is larger, the plot only shows the discreet truncated integer points (i.e. the plot looks better when the distance
Expand|Select|Wrap|Line Numbers
  1. D = sqrt( (x[i] - x[i - 1])^2 + (y[i] - y[i - 1])^2 )
  2.  
approaches unity.)

I'd certainly appreciate any help, particularly if it's just a nudge in the right direction. Thanks!
Oct 20 '08 #1
2 2332
newb16
687 512MB
Plots don't work? Try line segments : Bresenham algorithm, e.g.
Oct 21 '08 #2
archonmagnus
113 100+
Brilliant! Thanks a lot. That's exactly what I needed. There are often days where I wish I had gone into computer science so I would know these kind of things. Thanks again for the reference.
Oct 22 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Erik Lechak | last post by:
Hello All, I am creating a visual programming environment for python (similar to Matlab's simulink, but for python). For several reasons I have decided not to go with OGL. I am writing a wxOGL...
28
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
29
by: Roy Gourgi | last post by:
Hi, I am new to C#. I have the same time scheduling program written in C++ and it is 5 times faster than my version in C#. Why is it so slow as I thought that C# was only a little slower than...
3
by: Jacky Luk | last post by:
Hi, I used to stick with VB6 and now changing to vb.net What about pixel plotting? there is no function like pset. So how to do simple pixels on screen? Thanks a lot Jack
5
by: Eric Fortier | last post by:
Hi all, Last year I posted a message regarding templates use in blitter functions, but the single answer I got didn't help. My problem is that I was writing blitter functions which takes a...
13
by: Grant Edwards | last post by:
I need to interpolate an irregularly spaced set of sampled points: Given a set of x,y,z points, I need to interpolate z values for a much finer x,y grid. I tried using the scipy sandbox delaunay...
5
by: jo5867472 | last post by:
hi to all I am just a beginner of python. I want to know how pixels are plotted in python. I am not intending to use PIL because I don't need to manipulate images. So is there a simple module for...
6
by: Peter | last post by:
Hi I have a number of arrays of longs, from which I need to find a single array which only contains the values which appear in all the original arrays. For example, I could have the three...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.