473,795 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

archonmagnus
113 New Member
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 2350
newb16
687 Contributor
Plots don't work? Try line segments : Bresenham algorithm, e.g.
Oct 21 '08 #2
archonmagnus
113 New Member
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
5060
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 replacement library for wxPython. My first thought was to create an exact drop in replacement for OGL, but the more I look at the OGL api the more I hesitate to do it.
28
3182
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 linear search the best here(for loop from beginning to end of array)? It seems like some other search algorithm like binary or whatever would be of no benefit on this data set.
113
12358
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 algorithm work with strings that may or may not be unicode 3) Number of bytes back must either be <= number of _TCHARs in * sizeof(_TCHAR), or the relation between output size and input size can be calculated simply. Has to take into account the...
29
2268
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 C++? What am I doing wrong? Here is my code: using System;
3
1546
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
2262
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 "Flag" argument which may radically change the behavior of a function. I have read that the best way to handle this particular issue was with meta-programming using templates, as can be read on this page:
13
2652
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 module, but the interpolators don't work: the natural neighbor interpolator produces a surface with "holes" in it: the interpolator returns NaNs for no reason for certain regions within the convex hull (the convex hull looks right, and the input...
5
4249
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 2D graphics and plot pixels
6
1743
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 arrays: 1, 3, 2, 8, 5 3, 6, 1
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.