POV-Ray : Newsgroups : povray.general : Plane passing through 3 points Server Time
31 Oct 2024 10:22:33 EDT (-0400)
  Plane passing through 3 points (Message 1 to 6 of 6)  
From: kurtz le pirate
Subject: Plane passing through 3 points
Date: 1 May 2022 10:15:53
Message: <626e9619$1@news.povray.org>
Hello,

I have 3 points A, B and C
I would like the "plane" object to pass through these three points.

It is easy to determine the equation of a plane that passes through
these three points. We obtain this equation : ax + by + cz + d = 0

I try to do : plane { <a, b, c>, d }

but the plane does not pass through the points.


Documentation at <http://www.povray.org/documentation/view/3.7.1/297/>
indicates that the object "plane { <A, B, C>, D }" represent the plane
defined by : A*x + B*y + C*z - D*sqrt(A^2 + B^2 + C^2) = 0

... I must be dumb but I can't make the link with my plan equation.


A little help ?





-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Plane passing through 3 points
Date: 1 May 2022 13:00:00
Message: <web.626ebb76e0a3ca27afe6ae3e89db30a9@news.povray.org>
kurtz le pirate <kur### [at] gmailcom> wrote:
> Hello,
>
> I have 3 points A, B and C
> I would like the "plane" object to pass through these three points.
>
> It is easy to determine the equation of a plane that passes through
> these three points. We obtain this equation : ax + by + cz + d = 0
>
> I try to do : plane { <a, b, c>, d }
>
> but the plane does not pass through the points.
>
>
> Documentation at <http://www.povray.org/documentation/view/3.7.1/297/>
> indicates that the object "plane { <A, B, C>, D }" represent the plane
> defined by : A*x + B*y + C*z - D*sqrt(A^2 + B^2 + C^2) = 0
>
> ... I must be dumb but I can't make the link with my plan equation.
>
>
> A little help ?

I would prefer to rewrite this equation:

A*x + B*y + C*z - D*sqrt(A^2 + B^2 + C^2) = 0

- like this:

A*X + B*Y + C*Z = D*sqrt(A^2 + B^2 + C^2)

If we let L = sqrt(A^2 + B^2 + C^2)

- and we then divide by L on both sides, we get this equation:

A/L*X + B/L*Y + C/L*Z = D

The left side of the equation equals the dot product between
two vectors; vN and vP, where vN = <A/L, B/L, C/L> and
vP = <X, Y, Z>. I.e.:

vdot(vN, vP) = D

Since L = vlength(<A, B, C>), vN is a normalized vector;

vN = <A, B, C>/L = vnormalize(<A, B, C>)

Now if vN is the normalized normal vector to a plane - and if
vP is the position vector to any point in that plane, then the
plane is defined by all points in 3D space, where the dot
product between these two vectors equals the distance; D from
the origin to the plane in the direction of the plane's normal
vector.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Plane passing through 3 points
Date: 1 May 2022 16:25:00
Message: <web.626eeb35e0a3ca27892957989db30a9@news.povray.org>
kurtz le pirate <kur### [at] gmailcom> wrote:
> Hello,
>
> I have 3 points A, B and C
> I would like the "plane" object to pass through these three points.
>
> It is easy to determine the equation of a plane that passes through
> these three points. We obtain this equation : ax + by + cz + d = 0
>
> I try to do : plane { <a, b, c>, d }
>
> but the plane does not pass through the points.
>
>
> Documentation at <http://www.povray.org/documentation/view/3.7.1/297/>
> indicates that the object "plane { <A, B, C>, D }" represent the plane
> defined by : A*x + B*y + C*z - D*sqrt(A^2 + B^2 + C^2) = 0
>
> ... I must be dumb but I can't make the link with my plan equation.
>
>
> A little help ?

Here's some code for you to experiment with:
NB:
I changed the names of your 3 points from A, B and C to pE, pF and pG,
so that those are not confused with the parameters A, B and C in the
plane equation that you quote from the documentation.

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.7;

global_settings { assumed_gamma 1.0 }

#include "colors.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare pE = <+3, -1, +7>;
#declare pF = <-2,  0, +5>;
#declare pG = <+1,  0, +9>;

sphere {
    pE, 0.1
    pigment { color Red }
}

sphere {
    pF, 0.1
    pigment { color Green }
}

sphere {
    pG, 0.1
    pigment { color Blue }
}


// Two vectors parallel to the plane
#declare vEF = pF - pE;
#declare vEG = pG - pE;


// Normalized normal vector to the plane
#declare vN = vnormalize(vcross(vEF, vEG));

// Distance from origin to the plane along the normal vector
#declare D = vdot(pE, vN);  // or vdot(pF, vN) or vdot(pG, vN)


/*
// This will also work

// Normal vector to the plane
#declare vN = vcross(vEF, vEG);

// Distance from origin to the plane along the normal vector
#declare D = vdot(pE, vnormalize(vN));
*/


plane {
    vN, D
    pigment { color Cyan }
}

/*
// Alternative way
plane {
    vcross(vEF, vEG), 0
    translate pE  // or translate pF or translate pG
    pigment { color Magenta }
}
*/

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

background { color Gray20 }

light_source {
    <-3, 3, -4>*100
    color White
}

camera {
    location -z
    right x
    up y
    direction z
    sky y
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Plane passing through 3 points
Date: 1 May 2022 16:45:00
Message: <web.626ef069e0a3ca27892957989db30a9@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> kurtz le pirate <kur### [at] gmailcom> wrote:
> > Hello,
> >
> > I have 3 points A, B and C
> > I would like the "plane" object to pass through these three points.
> >
> > It is easy to determine the equation of a plane that passes through
> > these three points. We obtain this equation : ax + by + cz + d = 0
> >
> > I try to do : plane { <a, b, c>, d }
> >
> > but the plane does not pass through the points.
> >
> >
> > Documentation at <http://www.povray.org/documentation/view/3.7.1/297/>
> > indicates that the object "plane { <A, B, C>, D }" represent the plane
> > defined by : A*x + B*y + C*z - D*sqrt(A^2 + B^2 + C^2) = 0
> >
> > ... I must be dumb but I can't make the link with my plan equation.
> >
> >
> > A little help ?
>
> I would prefer to rewrite this equation:
>
> A*x + B*y + C*z - D*sqrt(A^2 + B^2 + C^2) = 0
>
> - like this:
>
> A*X + B*Y + C*Z = D*sqrt(A^2 + B^2 + C^2)

Since this has the same effect as normalizing the normal vector,
the statement "that is only true if the normal vector has unit length",
in the documentation page that you linked to, seems false to me.

I.e.: The normal vector in the plane statement does not need to be
normalized.


> If we let L = sqrt(A^2 + B^2 + C^2)
>
> - and we then divide by L on both sides, we get this equation:
>
> A/L*X + B/L*Y + C/L*Z = D
>
> The left side of the equation equals the dot product between
> two vectors; vN and vP, where vN = <A/L, B/L, C/L> and
> vP = <X, Y, Z>. I.e.:
>
> vdot(vN, vP) = D
>
> Since L = vlength(<A, B, C>), vN is a normalized vector;
>
> vN = <A, B, C>/L = vnormalize(<A, B, C>)
>
> Now if vN is the normalized normal vector to a plane - and if
> vP is the position vector to any point in that plane, then the
> plane is defined by all points in 3D space, where the dot
> product between these two vectors equals the distance; D from
> the origin to the plane in the direction of the plane's normal
> vector.

Hmmm.. not so precise. I try again:

Now if vN is the normalized normal vector to a plane - and if
vP is a position vector to any point in 3D space, then the
plane is defined by (or contains ?) all possible points vP
whose the dot product with vN equals D; the distance from the
origin to the plane in the direction of vN.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Alain Martel
Subject: Re: Plane passing through 3 points
Date: 2 May 2022 10:39:22
Message: <626fed1a$1@news.povray.org>
Le 2022-05-01 à 16:41, Tor Olav Kristensen a écrit :
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>> kurtz le pirate <kur### [at] gmailcom> wrote:
>>> Hello,
>>>
>>> I have 3 points A, B and C
>>> I would like the "plane" object to pass through these three points.
>>>
>>> It is easy to determine the equation of a plane that passes through
>>> these three points. We obtain this equation : ax + by + cz + d = 0
>>>
>>> I try to do : plane { <a, b, c>, d }
>>>
>>> but the plane does not pass through the points.
>>>
>>>
>>> Documentation at <http://www.povray.org/documentation/view/3.7.1/297/>
>>> indicates that the object "plane { <A, B, C>, D }" represent the plane
>>> defined by : A*x + B*y + C*z - D*sqrt(A^2 + B^2 + C^2) = 0
>>>
>>> ... I must be dumb but I can't make the link with my plan equation.
>>>
>>>
>>> A little help ?
>>
>> I would prefer to rewrite this equation:
>>
>> A*x + B*y + C*z - D*sqrt(A^2 + B^2 + C^2) = 0
>>
>> - like this:
>>
>> A*X + B*Y + C*Z = D*sqrt(A^2 + B^2 + C^2)
> 
> Since this has the same effect as normalizing the normal vector,
> the statement "that is only true if the normal vector has unit length",
> in the documentation page that you linked to, seems false to me.
> 
> I.e.: The normal vector in the plane statement does not need to be
> normalized.
> 
> 
>> If we let L = sqrt(A^2 + B^2 + C^2)
>>
>> - and we then divide by L on both sides, we get this equation:
>>
>> A/L*X + B/L*Y + C/L*Z = D
>>
>> The left side of the equation equals the dot product between
>> two vectors; vN and vP, where vN = <A/L, B/L, C/L> and
>> vP = <X, Y, Z>. I.e.:
>>
>> vdot(vN, vP) = D
>>
>> Since L = vlength(<A, B, C>), vN is a normalized vector;
>>
>> vN = <A, B, C>/L = vnormalize(<A, B, C>)
>>
>> Now if vN is the normalized normal vector to a plane - and if
>> vP is the position vector to any point in that plane, then the
>> plane is defined by all points in 3D space, where the dot
>> product between these two vectors equals the distance; D from
>> the origin to the plane in the direction of the plane's normal
>> vector.
> 
> Hmmm.. not so precise. I try again:
> 
> Now if vN is the normalized normal vector to a plane - and if
> vP is a position vector to any point in 3D space, then the
> plane is defined by (or contains ?) all possible points vP
> whose the dot product with vN equals D; the distance from the
> origin to the plane in the direction of vN.
> 
> --
> Tor Olav
> http://subcube.com
> https://github.com/t-o-k
> 
> 
Thus, using POV SDL, that plane is defined as :
plane{vN, D}


Post a reply to this message

From: kurtz le pirate
Subject: Re: Plane passing through 3 points
Date: 2 May 2022 11:49:05
Message: <626ffd71$1@news.povray.org>
On 01/05/2022 22:23, Tor Olav Kristensen wrote:

> 
> Here's some code for you to experiment with:
> ... 
> 

Thanks Tor.
*I will look at your code*


on my side, I made (not the easiest way) :

// ---------------------------------------------------------------------
// https://en.wikipedia.org/wiki/Plane_(geometry)
// ---------------------------------------------------------------------
#macro plane_equation(p1, p2, p3)
	#local a1 = p2.x - p1.x;
	#local b1 = p2.y - p1.y;
	#local c1 = p2.z - p1.z;

	#local a2 = p3.x - p1.x;
	#local b2 = p3.y - p1.y;
	#local c2 = p3.z - p1.z;
	
	#local a = b1 * c2 - b2 * c1;
	#local b = a2 * c1 - a1 * c2;
	#local c = a1 * b2 - b1 * a2;
	#local d = (-a*p1.x -b*p1.y - c*p1.z);
	
	#declare equation = concat(str(a,0,2),"x ");
	#if(b<0)
		#declare equation = concat(equation,"- ");
	#else
		#declare equation = concat(equation,"+ ");
	#end
	#declare equation = concat(equation, str(abs(b),0,2),"y ");
	#if(c<0)
		#declare equation = concat(equation,"- ");
	#else
		#declare equation = concat(equation,"+ ");
	#end
	#declare equation = concat(equation,str(abs(c),0,2),"z ");
	#if(d<0)
		#declare equation = concat(equation,"- ");
	#else
		#declare equation = concat(equation," +");
	#end
	#declare equation = concat(equation,str(abs(d),0,2)," = 0");
	#debug concat("Plane equation :\n  ",equation,"\n\n")
	
	#local result = array[4]{a,b,c,d};
	result
#end

// ---------------------------------------------------------------------
// --- 3 POINTS --------------------------------------------------------
// ---------------------------------------------------------------------
#declare ptA = <1,1,0>;
#declare ptB = <0,1,1>;
#declare ptC = <1,0,1>;

#declare POINTS =union {
	sphere { ptA, 0.10 pigment { color Red } }
	sphere { ptB, 0.10 pigment { color Green } }
	sphere { ptC, 0.10 pigment { color Blue } }

	union {
		cylinder { ptA, ptB, 0.025 }
		cylinder { ptB, ptC, 0.025 }
		cylinder { ptC, ptA, 0.025 }
		pigment { color White*0.80 }
		finish { brilliance 2 specular 0.20 }
		}
	}

object { POINTS }

#declare planCoef = plane_equation(ptA, ptB, ptC);
#declare a = planCoef[0];
#declare b = planCoef[1];
#declare c = planCoef[2];
#declare d = planCoef[3];

plane {
 <a, b, c>, ? <- several tests here :(
 pigment { color Magenta transmit 0.80 }
 }



// ---------------------------------------------------------------------
// Just to check the distance between the plane and the points...
// https://mathworld.wolfram.com/Point-PlaneDistance.html
// ---------------------------------------------------------------------
#declare D = sqrt(a*a+b*b+c*c);

#declare Dist = abs(a*ptA.x + b*ptA.y + c*ptA.z + d)/D;
#debug concat("A Point-Plane = ",str(Dist,0,4),"\n")

#declare Dist = abs(a*ptB.x + b*ptB.y + c*ptB.z + d)/D;
#debug concat("B Point-Plane = ",str(Dist,0,4),"\n")

#declare Dist = abs(a*ptC.x + b*ptC.y + c*ptC.z + d)/D;
#debug concat("C Point-Plane = ",str(Dist,0,4),"\n\n")

// all Dist values are egal to zero.



-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.