Click here to Skip to main content
15,888,182 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionc++ Pin
EvelynChristian7-Apr-23 5:01
EvelynChristian7-Apr-23 5:01 
AnswerRe: c++ Pin
Victor Nijegorodov7-Apr-23 6:45
Victor Nijegorodov7-Apr-23 6:45 
GeneralRe: c++ Pin
Richard MacCutchan7-Apr-23 7:20
mveRichard MacCutchan7-Apr-23 7:20 
GeneralRe: c++ Pin
Victor Nijegorodov7-Apr-23 7:30
Victor Nijegorodov7-Apr-23 7:30 
GeneralRe: c++ Pin
jschell7-Apr-23 9:13
jschell7-Apr-23 9:13 
GeneralRe: c++ Pin
Richard MacCutchan7-Apr-23 21:57
mveRichard MacCutchan7-Apr-23 21:57 
QuestionSnooker Game programing using c Programing. Pin
Francis Lagar3-Apr-23 7:37
Francis Lagar3-Apr-23 7:37 
AnswerRe: Snooker Game programing using c Programing. Pin
Richard MacCutchan3-Apr-23 9:57
mveRichard MacCutchan3-Apr-23 9:57 
AnswerRe: Snooker Game programing using c Programing. Pin
Gerry Schmitz3-Apr-23 10:19
mveGerry Schmitz3-Apr-23 10:19 
AnswerRe: Snooker Game programing using c Programing. Pin
jschell4-Apr-23 6:24
jschell4-Apr-23 6:24 
GeneralRe: Snooker Game programing using c Programing. Pin
Daniel Pfeffer4-Apr-23 7:40
professionalDaniel Pfeffer4-Apr-23 7:40 
SuggestionMessage Closed Pin
29-Mar-23 15:32
Member 1496877129-Mar-23 15:32 
GeneralRe: Socket or file descriptor ? Pin
k505429-Mar-23 17:18
mvek505429-Mar-23 17:18 
GeneralRe: Socket or file descriptor ? Pin
Richard MacCutchan29-Mar-23 21:38
mveRichard MacCutchan29-Mar-23 21:38 
GeneralRe: Socket or file descriptor ? Pin
jschell30-Mar-23 5:45
jschell30-Mar-23 5:45 
GeneralMessage Closed Pin
30-Mar-23 6:28
Member 1496877130-Mar-23 6:28 
GeneralRe: Socket or file descriptor - more questions ? Pin
k505430-Mar-23 9:31
mvek505430-Mar-23 9:31 
QuestionFind X,Y index into 2D array/matrix using an angle and number of cells Pin
imk12326-Mar-23 7:37
imk12326-Mar-23 7:37 
Hello,
I am working on a robots projects and part of this project is a local map space (2D array/matrix).
This map consists of 201 x 201 1cm squares, with the robot sitting in the middle.
From a robots point of view this local map has a index range of -100x -100y to +100x +100y
With the robot sitting at cell 0,0, obviously from a c/c++ point of view.
The array/matrix is addressed from 0x to 200x and 0y to 200y. (0x,0y being array/matrix bottom left)
I have successfully implement a robot rolling road and robot array/matrix rotations.
However, for some reason my brain has gone into gimble lock.
Trying to figure how to find the array/matrix x,y indices for a number of cells at a given angle from the middle of the map (robots position).
The code below produces perfect result for 100 cells at 0,45,90,135,180,225,270,315 degrees but at other angle is fails, can someone help please.
Many thanks in advance imk

#define LOCAL_MAP_NUM_X_CELLS 201
#define LOCAL_MAP_NUM_Y_CELLS 201
#define DEG_TO_RAD 0.0174533

struct LocalMap
{
unsigned char Cell[ LOCAL_MAP_NUM_Y_CELLS ][ LOCAL_MAP_NUM_X_CELLS ];
}; typedef struct LocalMap LocalMap;

int Cell_X;
int Cell_Y;

ComputeLocalMapCellIntexFromCentre( 315 , 100 , &Cell_X , &Cell_Y );

int ComputeLocalMapCellIntexFromCentre( double Angle , int NumberCells , int *pCell_X , int *pCell_Y )
{
double AngleAdjustMent;
double Sin = sin( Angle * DEG_TO_RAD);
double Cos = cos( Angle * DEG_TO_RAD);
double NumCells;

AngleAdjustMent = ( fabs( sin( Angle * DEG_TO_RAD)) + fabs( cos( Angle * DEG_TO_RAD )) );

NumCells = (double)NumberCells;
NumCells = round( (double)NumCells * AngleAdjustMent );

NumberCells = (int)NumCells;

*pCell_X = (int)round( Sin * NumberCells ) + ( LOCAL_MAP_NUM_X_CELLS - 1 ) / 2;
*pCell_Y = (int)round( Cos * NumberCells ) + ( LOCAL_MAP_NUM_Y_CELLS - 1 ) / 2;

return( TRUE );
}

modified 26-Mar-23 13:43pm.

AnswerRe: Find X,Y index into 2D array/matrix using an angle and number of cells Pin
Mircea Neacsu26-Mar-23 8:04
Mircea Neacsu26-Mar-23 8:04 
AnswerRe: Find X,Y index into 2D array/matrix using an angle and number of cells Pin
Gerry Schmitz26-Mar-23 8:50
mveGerry Schmitz26-Mar-23 8:50 
QuestionWhat is the difference in C and C++ in terms of memory management ? Pin
Gulshan Negi20-Mar-23 22:57
professionalGulshan Negi20-Mar-23 22:57 
GeneralRe: What is the difference in C and C++ in terms of memory management ? Pin
Richard MacCutchan21-Mar-23 2:11
mveRichard MacCutchan21-Mar-23 2:11 
AnswerRe: What is the difference in C and C++ in terms of memory management ? Pin
jschell21-Mar-23 5:41
jschell21-Mar-23 5:41 
QuestionC language Pin
Pavani M18-Mar-23 5:24
Pavani M18-Mar-23 5:24 
AnswerRe: C language Pin
Richard MacCutchan18-Mar-23 6:53
mveRichard MacCutchan18-Mar-23 6:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.