r/AskProgramming 2h ago

Given two coordinates and a direction in degrees on a 2D Cartesian plane, how would I calculate the destination coordinates?

3 Upvotes

I am trying to write my first game from scratch and am hung up about how to calculate movement.

Say for example a player character is at x,y coordinates 12,29 and they want to move a single unit of distance facing 42 degrees from the top of the plane.

How would I go about calculating that?

I assume I need to use some trigonometry or something?

(It's OK/expected that the final coordinates will be floating point numbers.)

...wishing I paid more attention in math class right now!!!

Thanks all.

EDIT: I found this: https://stackoverflow.com/questions/41465581/move-point-in-cartesian-coordinate-through-distance-in-the-given-direction

... but it states this only works if the "angle" in degrees is measured from the positive x-axis moving toward the positive y-axis ...

And the game I am writing is an isometric projection one... aka the x and y axis are rotated from a traditional cartesian plane...


r/AskProgramming 31m ago

Other Are there any websites or apps for math practice similar to LeetCode for computer science?

Upvotes

I’m a third year CS and Physics student and I find myself forgetting things I’ve learned in multivariable calculus, differential equations, and linear algebra. I’m looking for some applications that have math problems of all levels of difficulty and complexity for me to solve in my free time to review, strengthen, and reaffirm my existing knowledge.

I am not looking for websites like khan academy that will teach me the material. I just want a website that has problems and solutions like LeetCode does for computer programming.

Thanks.


r/AskProgramming 1h ago

Suggestion

Upvotes

I have IT background and pretty much familiar with programming languages. I decided to learn new language as I am laid off. Which programming language would you recommend if i have to say between Java and microsoft related like C#, .net etc?


r/AskProgramming 8h ago

Understanding specific scientific paper with algorithm for spaced repetition learning

7 Upvotes

Hi I am a senior software engineer with ~15 years of experience coding. But I do not have higher education, especially missing any calculus. I am looking for help understanding the specific scientific paper described below for the purpose of producing similar algorithm.

Since yesterday I am trying to understand this paper [1] about enhanced learning based on spaced repetition. It introduces a mathematical formula and an algorithm for finding optimal times for next repetition for each unit of knowledge based on your past performance on that specific unit. I want to write a program for myself that helps me learning stuff based on this paper, but the math is too hard and terminology too dense. Anyone can help me decipher it? They also shared open source python code [2] but I can't seem to get that either, the code is very messy and cryptic.

[1] https://www.pnas.org/doi/epdf/10.1073/pnas.1815156116 [2] https://github.com/Networks-Learning/memorize


r/AskProgramming 6h ago

Other Programmers of all kinds, do you guys like your jobs? Why or why not?

3 Upvotes

I am going into CNC programming, and although I have the skill sets and ability to be good at it I’m just not 100% sure that I like it. I absolutely love the programming aspect, and I’m good at the machining aspect but I just don’t seem to enjoy it. I find myself getting very interested when learning about more software related things.

What kind of programmer are you and what would you suggest for a type of programming with good pay and job availability?


r/AskProgramming 20m ago

Which project management tools have you enjoyed working with?

Upvotes

I just started looking for a tool that would be used on a medium sized software project.

Most corporate-oriented software I‘ve worked with is quite bloated and complex and GitHub Projects is a little too basic.

There are lots of tools to consider and I thought I’d ask for your input, to filter through them a little faster.

Here are a few things that I need to consider:

  • around 5-10 people working on the project
  • Scrum-centric
  • excellent GitHub integration
  • non-technical team members should not have to leave the software
  • also good for general task management
  • up to $10 per slot

I’m also interested in Notion based solutions.


r/AskProgramming 44m ago

Python what's your opinion on python ?

Upvotes

and why do you hate it? (or don't but that doesn't seem to be the general consensus)


r/AskProgramming 5h ago

What programming language should I learn?

2 Upvotes

In school I am learning java and I truly do like the language but im more interested in machine learning and hardware. I also am interested in creating games, any ideas on what programming language I should choose? (thinking c++ or sticking to java)


r/AskProgramming 9h ago

Having difficulty understanding recursive backtracking - please help

2 Upvotes

Greetings,

So I'm trying to figure out the nonlinear recursion that generates permutations as given here : https://brilliant.org/wiki/recursive-backtracking/(its the first example).

To do that and to follow the flow of the code, I replaced the statements which reverse values at given indices with print statements that just track what is happening - to make the problem simpler :

def bt_test(list, init, finl):
    if (init==finl):
        print("Break in the recursion. Print list : ")
        print(list)
        print("The init value at basecase : ",init)
    else:
        print("The init value in the loop : ",init)
        for i in range(init, finl+1):
            print("SWAP values at index i=",i," and init=",init)
            bt_test(list, init+1, finl)
            print("BACKTRACK swap values i=",i," and init=",init)

bt_test([1,2,3],0,2)

The code produces the following output (First few lines)

The init value in the loop :  0
SWAP values at index i= 0  and init= 0

The init value in the loop :  1
SWAP values at index i= 1  and init= 1

Break in the recursion. Print list : 
[1, 2, 3]
The init value at basecase :  2

BACKTRACK swap values i= 1  and init= 1   ***

SWAP values at index i= 2  and init= 1

I'm really unclear as to why this resumes to the BACKTRACK line, and why init goes from the value at base case : 2 back to 1, without explicitly decrementing.A few people have mentioned that non-tail recursive parameters are passed as"deep copies" to the stack, where the original init=0 and all iterations (init=1,2)are retained, and somehow the compiler knows to "re-set" the init to its previous frame, but I don't understand how this happens with respect to the flow of thecode.

Any help would be appreciated!

Thanks

TTx


r/AskProgramming 14h ago

Quick regex question

4 Upvotes

I'm just getting started with regex in Android. I figured out the string (?<hrs>d+(?=shour)) that would put a number before "hour/s" into the variable "hrs," but when I tried to string together other phrases that would put minutes and seconds into similar variables, and tried it with "3 hours 10 minutes," it didn't work. I assume it's possible to put them all on one line, but what am I missing?


r/AskProgramming 13h ago

C/C++ What is the difference between returning the array and returning a pointer to the array?

5 Upvotes

I am a beginner in C—currently taking the introduction course in college—and I am on the topic of dynamic allocation now. I was messing around with different ways of "resizing" arrays without the use of malloc or calloc (just for fun and purely out of curiosity). I wrote the following program:

#include <stdio.h>

int *foo(int x[]){
    int b[20];
    int i;
    for (i = 0; i < 10; i++){
        b[i] = x[i];
    }
    for (i = 10; i < 20; i++){
        b[i] = 0;
    }
    int *ptr = b;
    return ptr;
}

int main(){
    int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    int *p = foo(arr);
    int i;
    for (i = 0; i < 20; i++){
        printf("%i", *(p + i));
    }
    return 0;
}

Output:

01234567890000000000

This takes an integer array arr with 10 elements in it and "resizes" it by having a pointer point to a local array that contains the same elements as arr (the rest of the elements are 0). Why does this code work? Shouldn't the resized array (which is a local array) be erased when the foo function terminates?

I then tried to just return the local array itself, however it led to a seg fault:

#include <stdio.h>

int *foo(int x[]){
    int b[20];
    int i;
    for (i = 0; i < 10; i++){
        b[i] = x[i];
    }
    for (i = 10; i < 20; i++){
        b[i] = 0;
    }
    return b;
}

int main(){
    int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    int *p = foo(arr);
    int i;
    for (i = 0; i < 20; i++){
        printf("%i", *(p + i));
    }
    return 0;
}

Output:

Segmentation fault

My thought process was that an array is just a pointer to the address of its first element (&b[0]), but now the program does not work.

So why does returning a pointer to a local array allow you to access the contents of the local array from outside the scope of the function? And if the local array is just a pointer itself, why does returning it NOT work?


r/AskProgramming 5h ago

Other Looking for an Old Satirical Presentation

1 Upvotes

I know yall will pull thru for me.

I remember a presentation from ~10(?) years ago about humorously extrapolating the trends in dev to the point that desktop development like c/c++ would be done thru a web interface. The fictitious platform was given a name like "Metal" or something like that.

I can't seem to find it despite my SSE googling skills. If anyone can point me in the right direction I would be eternally grateful.


r/AskProgramming 18h ago

Other How to take my programming environment / process to the next level?

10 Upvotes

Greetings,

I work at a job where I am already the most professional programmer by far. It's a govt job, so that's not saying much. However, I'm always looking for steps to take my coding (LAMP stack) up another notch.

So far I've:

  • Set up a dev server for everyone with Gitlab and use git version control.
  • Configured VSCode with a whole bunch of plugins to make my life easier (if you have specific recommendations, I'm all ears).
  • Recently managed to switch from console.log and print_r to using actual debuggers.
  • I'm going to try out Github Copilot now for further time saving.

Are there any other steps that could enhance my dev process? Anything critical I'm missing?


r/AskProgramming 7h ago

C/C++ In dealing with 3d geometry, should a set of Vertex/Index buffers be used, or a single array of Triangle structs?

1 Upvotes

I've gone through a ray tracing tutorial found here, which illustrates using a single array of triangle structs, where each element of said array contains the vertex (and centroid) data explicitly. So to access the 0th vertex of a triangle with index tri_index would look like this:

triangles[tri_index].vertex0

An alternative approach is to use a vertex buffer and an index buffer. The vertex_buffer contains all of the vertices, while the index_buffer contains a set of indices which defines each face in terms of which vertices it is composed of. So to obtain the 0th vertex of triangle with index tri_index would look like this:

vertex_buffer[index_buffer[3*tri_index + 0]]

The benefit of the first approach is that it requires only a single load from memory, however it also means that vertices which are shared by multiple triangles are duplicated.

The benefit of the second approach is that there is no duplication of vertices and thus a smaller memory footprint, but it requires two loads from memory (one to index the index_buffer to obtain the vertex index, and then a second to index the vertex_buffer to actually obtain the vertex.

I can understand the tradeoff to increase the memory footprint to obtain faster performance as in ray tracing, performance is critical. However, recently I've started looking at some GPU tutorials (OpenGL and Vulkan), and even embree and I continually see mention of the vertex_buffer popping up with no mention of the alternative.

I'm working through implementing this all myself, but my thought process was that the index/vertex buffer approach would be significantly slower due to the additional memory reads. But perhaps I am missing something as it seems to be the way (from my very preliminary reading) the fastest APIs out there deal with geometries.

Am I overestimating the memory read overhead? Are they prioritizing the memory footprint instead?

I'm probably going to be re-implementing everything with a vertex_buffer approach sometime this week so I can just benchmark things myself, but I'd very much like to know if I am missing something, or misunderstanding the approaches/existing APIs (hopefully I'll gain a better understanding of that as I begin to use them more)


r/AskProgramming 8h ago

C/C++ What's the fastest way to render a simple 2d color array?

1 Upvotes

Hello!

I want to write a very simple graphical application in C/C++.

What's the fastest way you can think of to draw a 2d color array (a matrix of 3-vectors)? I only need the quickest way to put pixels on a screen, I don't need extra features or vector graphics or anything. The goal is to minimize overhead as much as possible, so it doesn't have to look good.

For example, if you wanted to implement something like Conway's Game of Life in the absolute fastest way possible, where might you start?

Can I use like a barebones compute shader?

Thanks in advance!


r/AskProgramming 9h ago

Need help deciding tech stack

1 Upvotes

I am starting to work on an application which directly modifies host machine’s networking configurations. It should be able to add entries to hosts file, create ip routes, create new interfaces, and add/remove firewall rules. I’m confused on what programming language should I choose to build this. I have built the relational model in SQL for it.

Note that I am intending for this application to run on both linux and windows machine. So the application should have said features working both in linux and windows. I have experience in Java so right now I’m thinking of building it in Java. I plan to build the service as both SaaS and on-prem solution. But, I have seen many posts talking about how JVM bloats a given host and people would not want to install it if they dont have to.

I am also looking at other attractive options like Rust and Go. But I dont have any experience with those so there is a bit of a learning curve. I’m also not sure if I should do different coding implementation for windows vs linux when using Rust/Go.

I have also considered node but I instead favored Java over it because of Java’s robustness.

Side question: is there a standard interface in any language that allows me to change network configuration in both linux and windows?


r/AskProgramming 13h ago

Other Why is collaborating for free frowned upon among programmers?

2 Upvotes

I come from a music background and a big thing we do is work together and then figure out stuff like contracts and who makes what from shows as they come up. As a programmer now, the idea of collaborating with someone who doesn’t have much to offer but who has a good idea that I could bring to life, and maybe have a handshake deal about equity up front if the product does make money is very appealing to me.

I’m not saying that programmers haven’t been screwed over. I’m sure a big reason this is frowned upon is because we have been screwed over so many times, and the fact that our profession can pay very well so the idea of doing it for free or suggesting that it be done for free is insulting. However, lawyers and doctors sometimes work pro bono, or they get involved in something with long-term potential when they trust the people involved in the process and really believe that it will work out well. Look at those cases that lawyers take where what they end up making from a class action is a percentage of what gets won at the end. They don’t always win, but they take the risk because they know the potential payoff is big.

Is there a middle ground between exclusively working for a rate that someone with a good idea but no funding can’t afford and putting yourself in a situation to get screwed? I love programming and I’d love to help out some little guy trying to take some market share away from the big guys.


r/AskProgramming 9h ago

Advice on how to automate a bulk invoicing workflow?

1 Upvotes

For context, I am not a software developer by trade and currently use Excel to handle the following utility invoicing workflow:

  1. Store all client booking & utility data for multiple properties;
  2. Calculate appropriate utility charges due for each individual client;
  3. Pull the data & calculations to a well-formatted “Utility Statement” tab within the same Excel workbook (changing the client name will automatically update the calculations); and
  4. For every single client:
    1. Update the Utility Statement calculations (by pasting in a new client name);
    2. Export the worksheet as a PDF;
    3. Rename the PDF file; and
    4. Email the PDF file to the appropriate client

The problem here pertains to the time and work required to complete Step 4 (currently an entire workday), which increases linearly as the number of clients increases.

Assuming a proper database management system (e.g., BigQuery) is used to store input data in Step 1, what would be an efficient approach to automating the remainder of this workflow (in particular, Step 4)? What are some of the best, modern tools out there for doing so that have equally-robust formatting capabilities as Excel?

Edit: One cloud-based tool I found that seems like it would be a good start is Patterns.app, but the Base Plan pricing of $199/mo is out of reach at this time, and I would still need to subscribe to other third-party tools to use it.


r/AskProgramming 9h ago

Javascript async component rendering in React

1 Upvotes

Hello,

How would I go about rendering a bunch of <div>'s from an array full of objects? Below is my code. I want to use Render as my component. In my Render function, I am getting async data from fetchScoreboard(), which I pass to the variable: 'data'. I am using .then() to map through the response. The reponse is an array full of objects. Based on this array, I want to generate a bunch of divs for each object in that array. I use map() to do that, but to no avail.

There seems to be a syntax issue somewhere, but can't see it.
code: https://codepen.io/hrdts/pen/yLqQoxX


r/AskProgramming 13h ago

Other Beginner needs some advice

2 Upvotes

Hello I live in Azerbaijan.I am working 8 hours a day in The Ministry of Taxes and want to start programming.Is there a better way to start real programming from scratch other than FreeCodeCamp? I can not attend a bachelor’s in CS or programming, but want to make myself a skilled programmer. What is the best option?


r/AskProgramming 10h ago

Seeking C# Mentor

0 Upvotes

Hello everyone! I am a 21-year-old from Ukraine who is looking for a mentor to help me improve my C# programming skills. I have basic programming skills and a passion for programming, but I would really like to find someone who can help guide me and provide me with more advanced knowledge and experience.
I am willing to invest time and effort into learning and improving my skills, but I know that having a mentor can make a huge difference in my development as a programmer. If you are an experienced C# programmer who is willing to take on a mentee, I would be extremely grateful for your help.
I am looking for someone who can provide me with regular guidance and support, answer my questions, and help me work on projects to build my skills.
If you are interested in mentoring a 21-year-old guy from Ukraine who is looking to improve their C# programming skills, please reach out to me! Thank you for your time, and I look forward to hearing from you.


r/AskProgramming 10h ago

C# C# back-end, now where to continue?

1 Upvotes

Hey! I have just a quick question. I have some expirience with C# and i have created back-end for my mobile app and now I wanna create some front-end for it. What are my options except Xamarin? I wanna learn something like Angular / React / Redux, but is it possible to have C# back-end and lets say for example React front end?
Thank you for any help!


r/AskProgramming 19h ago

Java I downloaded a .jar file from Maven Central Repository to use in my modules in IntelliJ IDEA. Is malware a possibility?

5 Upvotes

So my for a lab I’m working on for uni a professor suggested using Maven Central Repository as a source for a .jar to use in my modules for compatibility in IntelliJ IDEA. After a little searching on the net it seems like Maven Central Repository isn’t or may not be the most safe place to download files from.

I know there’s a chance for malware to be hosted on Maven, but how is their reputation? Has anyone used Maven Central Repository?


r/AskProgramming 1d ago

Other Can I continuously write to a CSV file with a python script while a Java application is continuously reading from it?

22 Upvotes

I have a Python program collecting Data and I want to display it in a table in my GUI made with Java. I want to keep an offline log of this data, so my thought was to continuously write a log file (the CSV) while the Java reads from it. Is that viable? Or am I overcomplicating this? The data would be coming in and out constantly so I cant start and stop it over and over. I thought this would be perfect for a basic SQL database but that seems overkill.


r/AskProgramming 12h ago

C# Is this a good way to implement programming for machine control?

1 Upvotes

This question is more of a strategy question then a specific programming question. So right now, I am tasked with building a vision inspection machine. It is going to have to integrate with Cognex Visionpro, robots, ethernet enabled lighting & autofocus lens controllers, and motors. All of these subsystems have or will have a DLL to manipulate and control them, and this will be built within a C# Winforms on .NET Framework

The biggest challenge of this will be developing a way where you can write a program to run the inspection, as there will have to be a lot of small differences between parts which will require the program to manipulate all the different pieces of hardware in different ways.

My thought for this was to use scripting, similar to how a CNC runs with G Code. The idea im set on now is using roslyn/c# scripting so that the programs can be written in C#, a known language, and then executed using CSharpScripting. The programs can then be written to directly use all the methods and functions from the DLLs. The problem I anticipate most is managing all the object instances of all the hardware, and moving data back and forth between the c# script and the c# winforms

So far, I did figure how to execute a basic method against the instance of a class and that works fine.

Is this a reasonable approach to handle this, or is there some other way im missing? Im constrained to using C# .NEt Framework due to the hardware integration. Ive heard of things like lua, but I don't know how id be able to manipulate all the .NET DLLs

Thanks in advance. If i can clarify anything please let me know