Get line side for vector

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Get line side for vector

Post by Apeirogon »

Is there are some native function which take line and some vector and returns is vector behind,on or in front of the line?
User avatar
KeksDose
 
 
Posts: 595
Joined: Thu Jul 05, 2007 6:13 pm
Contact:

Re: Get line side for vector

Post by KeksDose »

Not sure if a function exists, but you can write one. If you know the two vertices of your line, check the sign of this special product:

Code: Select all

let line_diff = line_point2 - line_point1;
let actor_diff = actor.pos.xy - line_point1; // maybe you'd like vec2diff here

if(line_diff.x * actor_diff.y - line_diff.y * actor_diff.x < 0) {
    // It's on the one side.
}

else {
    // it's on the other.
} 
If your line_diff is (0, 1), then "on the one side" means "to its right" in gzd coords.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Get line side for vector

Post by Apeirogon »

Problem is I want to know what "right" side is, front or back line side.
User avatar
KeksDose
 
 
Posts: 595
Joined: Thu Jul 05, 2007 6:13 pm
Contact:

Re: Get line side for vector

Post by KeksDose »

It depends on how the line is oriented. You could have a thing at (1 0) and the first vertex (0 0), second (0 1), and find my function output "right" / "the one side", but if you were to swap the two vertices, it will say "left" / "the other side"... and the quotation marks cuz it's all based on the idea that you're looking at it top down in the automap.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Get line side for vector

Post by Apeirogon »

KeksDose wrote:It depends on how the line is oriented
And thats the main problem, because I want to know line orientation relative to the point/vice versa.
User avatar
KeksDose
 
 
Posts: 595
Joined: Thu Jul 05, 2007 6:13 pm
Contact:

Re: Get line side for vector

Post by KeksDose »

No, that part is solved. My script will tell you whether a point is on "one side" or "the other". The consistency with your problem's context is entirely your job, something you pick.

For example, are you storing closed polygons? Then you get consistent results if all vertices are either stored clockwise or counter clockwise, but not mixed. This context allows you to say "inside" or "outside".

Or are you talking about a (double sided) map line? Then it might work totally different. Maybe map editors follow a convention, who knows.
Post Reply

Return to “Scripting”