element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
NexGen Flight Simuator Flight Simulator 101 or back to college - part 15: Radio Propagation and Slant Range Math. part 3 - The Software
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: phoenixcomm
  • Date Created: 25 Apr 2026 3:23 AM Date Created
  • Views 82 views
  • Likes 5 likes
  • Comments 4 comments
  • flight simulator
  • nexgen
  • Flight Simulator 101 or back to college
  • software_design
  • c progrmming
Related
Recommended

Flight Simulator 101 or back to college - part 15: Radio Propagation and Slant Range Math. part 3 - The Software

phoenixcomm
phoenixcomm
25 Apr 2026

imageOk, so after slogging through the math, and going to a local college to get my head straight, and to get some help, here finally I can see some light at the end of the road. So now I have to lay out the software, for you, and myself. So I drew a little planet with a VOR station and the Sonic Cruiser.
imageSo on the left, you see a diagram of our little problem, we have a VOR Station (which we know where it is (Lat, Lon, H), from an FAA Navaids DB that I have. This DB is mySQL accessed via JASON API.  We also have a Sonic Cruiser, and we know where it is (Lat, Lon, Alt) from the simulator. Given the six pieces of information that we have, we can now generate the distance between both objects on the ground by the use of the Great Circle Navigation Software.  Now we need to find the distance between the VOR Station and the center of the earth. This is done EarthCenterCalculator software. Next, we have to use the Station's H (height above sea level). Next, I can use the Pythagorean theorem, to generate the slant range.  where
Distance ::= Antenna height above sea level
Altitude ::= Aircraft Altitude above sea leve
So HEY C DOSE NOT HAVE A NOTATION or FUNCTION for A xe2
you could use a = a x a
but why don't you use a #define Sq (x) ((x)*(x))
so here's what you should do: Create program_name.h file and insert one line of code the #define
tells the C pre-processor that you have just created the function #define
So now we have the Sq() but now we have to tell the Compiler to use it
you now have to put one line of code in your program,


#include program_name.h
ok now on with the code.

TOP OF THE PAGE
#include program_name.h
float main(argv, argc){
// remember to specify the type of the Variables
return( Square Root( Sq(Distance) + Sq(Altitude))); //- but then you have to convert to miles.  Now My program(S) have a several .h files I use them for organization. REMEMBER YOU MUST WATCH YOUR CAPs  AS C in not c FIns

  • Sign in to reply
  • phoenixcomm
    phoenixcomm 8 days ago in reply to michaelkellett

    I have never used MISRA C I have seen it and disagree with its ideals, I use K&R rules and have disdain it I liked when It first came out and later grew to hate it. its like turning C into Pascal when i use "after -> before" I dont do this "after points to Before" This is why from Wirth's own hand said Pascal is for teaching programing not to write systems with (or words to that effect)

    While this spec was written to support C++, It has major problems with C That is why with common #defines you never have inches vs Cm. I remember a spacecraft crashing because two different teams used to different forms of measurements. 

    When I write one of my large functions I have multiple calls to SQR??? That why you use the #defines (if I remember I had about a dozen calls.. #defines are a wonderful thing, just dont abuse them I typicality my header would contains TRUE, FALSE, ERROR, PI(formula), SQR and not much else. 

    Some time I use  JOINT STRIKE FIGHTER AIR VEHICLE
    rule 29 shall not use Micros... It doesn't like because of var types // DISAGREE if you write functions and you have different type you will now have to write multiple forms of the same function!
    rule 30  dont define constants //DISAGREE this is one place constants belong 
    rule 31 will only be used to prevent multiple files?? of what. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelkellett
    michaelkellett 9 days ago in reply to phoenixcomm

    I think you may be a little "off message" here Slight smile

    This is an extract from the MISRA C 2025 Guidlines:

    image

    It says a lot more and gives examples but it's a paid for thing and I think the above is safely within the limit of fair use.

    Some of the examples are of when macro is a good (or even the only) way.

    It addresses your point that macros do not check types - which it considers to be a bad thing. 

    Certainly I would rather the compiler generated an error than that hidden function used  a type conversion that I had not anticipated.

    The Barr Group Embedded C coding standard takes a harder line:

    image

    It also give several examples. 

    The Barr Group coding standard is quite  a good document and a free download - any serious C programmer should at least read it. (And almost certainly disagree with at least some of it !)

    My main reason for bringing all this up is less to influence how you write your C and more to make sure that other readers see both sides of the coin and can make up their own minds.

    BTW Chris - have you considered Vibe Coding Relaxed

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • phoenixcomm
    phoenixcomm 9 days ago in reply to michaelkellett

    I hate to disagree with you but I have been using C for more than a few decades. I a professional environment  it is recommended to use #define, rather than functions. and those defines are very small things that you repeat over and over, again. But don't use LOWER CASE as then you may be Confused. Also If you use a macro, the compiler does the work in the pre-prossor not later so If you used a function to do the same each call to a function is a cost, where as Macro are free..... also never, ever try to define a Macro that is inside an other Macro, this should be AVOIDED.

    In small programs ok, but my simulator run in to more than a few thousand functions by them selves 

    I have function that  Convert Things to Other Things like D = Time * Speed I could put it in a Macro  but the Macro doesn't care about variable types, so doing the with a function  you might need 2 ::= float, fixed woh, forgot fixed point,......

    Michael the only time I might agree is if you don't understand C... You see (just for grins) to me for instance  Python is a joke, and a bad one at that. you have to indent instead  {..} This is a bad joke because its going backwards to FORTRAN, and how to you finish a statement which could be more than one line. So as the Wendy's commercial "Wheres the Beef?" Python should be "Where is the Period? ~~~~~End of Rant."

    ~~ Cris H.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelkellett
    michaelkellett 14 days ago

    If you use a reasonably modern optimising C compiler the resulting code will often be the same if you use a #define for Sq or a function.

    (Because they inline short functions when optimising for speed.)

    Macros can be useful but can also make it very hard for other people to read your code - and the error messages the compiler makes when they are involved are sometimes not very helpful.

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube